mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
More grid-page integation work. Cleaned up clause generation in grid columns and finalized search for pages grid.
This commit is contained in:
@@ -12,30 +12,31 @@ def format_bool( b ):
|
||||
else:
|
||||
return ""
|
||||
|
||||
class PublicURLColumn( grids.GridColumn ):
|
||||
class PublicURLColumn( grids.TextColumn ):
|
||||
def get_value( self, trans, grid, item ):
|
||||
username = trans.user.username or "???"
|
||||
username = item.user.username or "???"
|
||||
return username + "/" + item.slug
|
||||
def get_link( self, trans, grid, item ):
|
||||
if trans.user.username:
|
||||
if item.user.username:
|
||||
return dict( action='display_by_username_and_slug', username=item.user.username, slug=item.slug )
|
||||
else:
|
||||
return None
|
||||
|
||||
class OwnerColumn( grids.GridColumn ):
|
||||
class OwnerColumn( grids.TextColumn ):
|
||||
def get_value( self, trans, grid, item ):
|
||||
return item.user.username
|
||||
|
||||
class PageListGrid( grids.Grid ):
|
||||
# Grid definition
|
||||
use_panels = True
|
||||
title = "Your pages"
|
||||
title = "Pages"
|
||||
model_class = model.Page
|
||||
default_filter = { "published" : "All"}
|
||||
default_sort_key = "-create_time"
|
||||
columns = [
|
||||
grids.TextColumn( "Title", key="title", model_class=model.Page, attach_popup=True, filterable="standard" ),
|
||||
PublicURLColumn( "Public URL" ),
|
||||
grids.GridColumn( "Published", key="published", format=format_bool, filterable="advanced" ),
|
||||
grids.GridColumn( "Published", key="published", format=format_bool, filterable="standard" ),
|
||||
grids.GridColumn( "Created", key="create_time", format=time_ago ),
|
||||
grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
|
||||
]
|
||||
@@ -56,13 +57,13 @@ class PageListGrid( grids.Grid ):
|
||||
class PageAllPublishedGrid( grids.Grid ):
|
||||
# Grid definition
|
||||
use_panels = True
|
||||
title = "Published pages from all users"
|
||||
title = "Published Pages From All Users"
|
||||
model_class = model.Page
|
||||
default_sort_key = "-create_time"
|
||||
columns = [
|
||||
grids.GridColumn( "Title", key="title" ),
|
||||
grids.TextColumn( "Title", model_class=model.Page, key="title", filterable="standard" ),
|
||||
PublicURLColumn( "Public URL" ),
|
||||
OwnerColumn( "Published by" ),
|
||||
OwnerColumn( "Published by", model_class=model.User, key="username" ),
|
||||
grids.GridColumn( "Created", key="create_time", format=time_ago ),
|
||||
grids.GridColumn( "Last Updated", key="update_time", format=time_ago ),
|
||||
]
|
||||
|
||||
@@ -21,6 +21,7 @@ class Grid( object ):
|
||||
columns = []
|
||||
operations = []
|
||||
standard_filters = []
|
||||
# Any columns that are filterable (either standard or advanced) should have a default value set in the default filter.
|
||||
default_filter = {}
|
||||
default_sort_key = None
|
||||
preserve_state = False
|
||||
@@ -320,10 +321,10 @@ class TextColumn( GridColumn ):
|
||||
if isinstance( column_filter, basestring ):
|
||||
return func.lower( model_class_key_field ).like( "%" + column_filter.lower() + "%" )
|
||||
elif isinstance( column_filter, list ):
|
||||
composite_filter = True
|
||||
clause_list = []
|
||||
for filter in column_filter:
|
||||
composite_filter = and_( composite_filter, func.lower( model_class_key_field ).like( "%" + filter.lower() + "%" ) )
|
||||
return composite_filter
|
||||
clause_list.append( func.lower( model_class_key_field ).like( "%" + filter.lower() + "%" ) )
|
||||
return and_( *clause_list )
|
||||
|
||||
# Generic column that supports tagging.
|
||||
class TagsColumn( TextColumn ):
|
||||
@@ -353,15 +354,15 @@ class TagsColumn( TextColumn ):
|
||||
# Collapse list of tags into a single string; this is redundant but effective. TODO: fix this by iterating over tags.
|
||||
column_filter = ",".join( column_filter )
|
||||
raw_tags = tag_handler.parse_tags( column_filter.encode("utf-8") )
|
||||
filter = True
|
||||
clause_list = []
|
||||
for name, value in raw_tags.items():
|
||||
if name:
|
||||
# Search for tag names.
|
||||
filter = and_( filter, self.model_class.tags.any( func.lower( self.model_tag_association_class.user_tname ).like( "%" + name.lower() + "%" ) ) )
|
||||
clause_list.append( self.model_class.tags.any( func.lower( self.model_tag_association_class.user_tname ).like( "%" + name.lower() + "%" ) ) )
|
||||
if value:
|
||||
# Search for tag values.
|
||||
filter = and_( filter, self.model_class.tags.any( func.lower( self.model_tag_association_class.user_value ).like( "%" + value.lower() + "%" ) ) )
|
||||
return filter
|
||||
clause_list.append( self.model_class.tags.any( func.lower( self.model_tag_association_class.user_value ).like( "%" + value.lower() + "%" ) ) )
|
||||
return and_( *clause_list )
|
||||
|
||||
# Column that performs multicolumn filtering.
|
||||
class MulticolFilterColumn( TextColumn ):
|
||||
@@ -373,17 +374,20 @@ class MulticolFilterColumn( TextColumn ):
|
||||
if column_filter == "All":
|
||||
return query
|
||||
if isinstance( column_filter, list):
|
||||
composite_filter = True
|
||||
clause_list = []
|
||||
for filter in column_filter:
|
||||
part_composite_filter = False
|
||||
part_clause_list = []
|
||||
for column in self.cols_to_filter:
|
||||
part_composite_filter = or_( part_composite_filter, column.get_filter( filter ) )
|
||||
composite_filter = and_( composite_filter, part_composite_filter )
|
||||
part_clause_list.append( column.get_filter( filter ) )
|
||||
clause_list.append( or_( *part_clause_list ) )
|
||||
complete_filter = and_( *clause_list )
|
||||
else:
|
||||
composite_filter = False
|
||||
clause_list = []
|
||||
for column in self.cols_to_filter:
|
||||
composite_filter = or_( composite_filter, column.get_filter( column_filter ) )
|
||||
return query.filter( composite_filter )
|
||||
clause_list.append( column.get_filter( column_filter ) )
|
||||
complete_filter = or_( *clause_list )
|
||||
|
||||
return query.filter( complete_filter )
|
||||
|
||||
class GridOperation( object ):
|
||||
def __init__( self, label, key=None, condition=None, allow_multiple=True, allow_popup=True, target=None, url_args=None ):
|
||||
|
||||
@@ -86,10 +86,23 @@
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
## Clear the standard search.
|
||||
##|
|
||||
##<% filter_all = GridColumnFilter( "", { column.key : "All" } ) %>
|
||||
##<a href="${url( filter_all.get_url_args() )}">Clear All</a>
|
||||
| <a href="" onclick="javascript:$('#more-search-options').slideToggle('fast');return false;">Advanced Search</a>
|
||||
##<a href="${url( filter_all.get_url_args() )}">Clear All</a>
|
||||
|
||||
## Only show advanced search if there are filterable columns.
|
||||
<%
|
||||
show_advanced_search = False
|
||||
for column in grid.columns:
|
||||
if column.filterable == "advanced":
|
||||
show_advanced_search = True
|
||||
break
|
||||
endif
|
||||
%>
|
||||
%if show_advanced_search:
|
||||
| <a href="" onclick="javascript:$('#more-search-options').slideToggle('fast');return false;">Advanced Search</a>
|
||||
%endif
|
||||
</td>
|
||||
</tr></table>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user