[hg] galaxy 3000: More grid-page integation work. Cleaned up cla...
details: http://www.bx.psu.edu/hg/galaxy/rev/facf315d9e0e changeset: 3000:facf315d9e0e user: jeremy goecks <jeremy.goecks at emory.edu> date: Tue Nov 10 13:46:53 2009 -0500 description: More grid-page integation work. Cleaned up clause generation in grid columns and finalized search for pages grid. diffstat: lib/galaxy/web/controllers/page.py | 19 ++++++++++--------- lib/galaxy/web/framework/helpers/grids.py | 32 ++++++++++++++++++-------------- templates/grid_common.mako | 17 +++++++++++++++-- 3 files changed, 43 insertions(+), 25 deletions(-) diffs (160 lines): diff -r 7698e2ecca3e -r facf315d9e0e lib/galaxy/web/controllers/page.py --- a/lib/galaxy/web/controllers/page.py Tue Nov 10 13:06:20 2009 -0500 +++ b/lib/galaxy/web/controllers/page.py Tue Nov 10 13:46:53 2009 -0500 @@ -12,30 +12,31 @@ 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 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 ), ] diff -r 7698e2ecca3e -r facf315d9e0e lib/galaxy/web/framework/helpers/grids.py --- a/lib/galaxy/web/framework/helpers/grids.py Tue Nov 10 13:06:20 2009 -0500 +++ b/lib/galaxy/web/framework/helpers/grids.py Tue Nov 10 13:46:53 2009 -0500 @@ -21,6 +21,7 @@ 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 @@ 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 @@ # 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 @@ 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 ): diff -r 7698e2ecca3e -r facf315d9e0e templates/grid_common.mako --- a/templates/grid_common.mako Tue Nov 10 13:06:20 2009 -0500 +++ b/templates/grid_common.mako Tue Nov 10 13:46:53 2009 -0500 @@ -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>
participants (1)
-
Greg Von Kuster