[hg] galaxy 3699: Rename the tool_browser controller and add a l...
details: http://www.bx.psu.edu/hg/galaxy/rev/ba5b796311f3 changeset: 3699:ba5b796311f3 user: Greg Von Kuster <greg@bx.psu.edu> date: Tue Apr 27 09:32:38 2010 -0400 description: Rename the tool_browser controller and add a link to the masthead. diffstat: lib/galaxy/webapps/community/buildapp.py | 2 +- lib/galaxy/webapps/community/controllers/admin.py | 2 +- lib/galaxy/webapps/community/controllers/tool.py | 161 +++++++++++++++ lib/galaxy/webapps/community/controllers/tool_browser.py | 161 --------------- lib/galaxy/webapps/community/controllers/upload.py | 4 +- templates/webapps/community/base_panels.mako | 1 + templates/webapps/community/index.mako | 4 +- templates/webapps/community/tool/browse_tool.mako | 2 +- templates/webapps/community/tool/view_tool.mako | 6 +- 9 files changed, 172 insertions(+), 171 deletions(-) diffs (441 lines): diff -r 83102f27fd1d -r ba5b796311f3 lib/galaxy/webapps/community/buildapp.py --- a/lib/galaxy/webapps/community/buildapp.py Mon Apr 26 17:02:37 2010 -0400 +++ b/lib/galaxy/webapps/community/buildapp.py Tue Apr 27 09:32:38 2010 -0400 @@ -76,7 +76,7 @@ add_controllers( webapp, app ) # These two routes handle our simple needs at the moment webapp.add_route( '/:controller/:action', action='index' ) - webapp.add_route( '/:action', controller='tool_browser', action='index' ) + webapp.add_route( '/:action', controller='tool', action='index' ) webapp.finalize_config() # Wrap the webapp in some useful middleware if kwargs.get( 'middleware', True ): diff -r 83102f27fd1d -r ba5b796311f3 lib/galaxy/webapps/community/controllers/admin.py --- a/lib/galaxy/webapps/community/controllers/admin.py Mon Apr 26 17:02:37 2010 -0400 +++ b/lib/galaxy/webapps/community/controllers/admin.py Tue Apr 27 09:32:38 2010 -0400 @@ -461,7 +461,7 @@ if 'operation' in kwargs: operation = kwargs['operation'].lower() if operation == "browse": - return trans.response.send_redirect( web.url_for( controller='tool_browser', + return trans.response.send_redirect( web.url_for( controller='tool', action='browse_tool', **kwargs ) ) elif operation == "edit tool": diff -r 83102f27fd1d -r ba5b796311f3 lib/galaxy/webapps/community/controllers/tool.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/webapps/community/controllers/tool.py Tue Apr 27 09:32:38 2010 -0400 @@ -0,0 +1,161 @@ +import sys, os, operator, string, shutil, re, socket, urllib, time, logging, mimetypes + +from galaxy.web.base.controller import * +from galaxy.webapps.community import model +from galaxy.web.framework.helpers import time_ago, iff, grids +from galaxy.model.orm import * +from common import * + +log = logging.getLogger( __name__ ) + +# States for passing messages +SUCCESS, INFO, WARNING, ERROR = "done", "info", "warning", "error" + +class ToolListGrid( grids.Grid ): + class NameColumn( grids.TextColumn ): + def get_value( self, trans, grid, tool ): + return tool.name + class CategoryColumn( grids.TextColumn ): + def get_value( self, trans, grid, tool ): + if tool.categories: + return tool.categories + return 'not set' + class StateColumn( grids.GridColumn ): + def get_value( self, trans, grid, tool ): + state = tool.state() + if state == tool.states.NEW: + return '<div class="count-box state-color-queued">%s</div>' % state + if state == tool.states.WAITING: + return '<div class="count-box state-color-running">%s</div>' % state + if state == tool.states.APPROVED: + return '<div class="count-box state-color-ok">%s</div>' % state + if state == tool.states.REJECTED or state == tool.states.ERROR: + return '<div class="count-box state-color-error">%s</div>' % state + return state + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column.""" + accepted_filter_labels_and_vals = [ model.Tool.states.NEW, + model.Tool.states.WAITING, + model.Tool.states.APPROVED, + model.Tool.states.REJECTED, + model.Tool.states.DELETED, + "All" ] + accepted_filters = [] + for val in accepted_filter_labels_and_vals: + label = val.lower() + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args ) ) + return accepted_filters + class UserColumn( grids.TextColumn ): + def get_value( self, trans, grid, tool ): + return tool.user.email + # Grid definition + title = "Tools" + model_class = model.Tool + template='/webapps/community/tool/grid.mako' + default_sort_key = "name" + columns = [ + NameColumn( "Name", + key="name", + model_class=model.Tool, + link=( lambda item: dict( operation="Edit Tool", id=item.id, webapp="community" ) ), + attach_popup=True, + filterable="advanced" ), + CategoryColumn( "Category", + key="category", + model_class=model.Category, + link=( lambda item: dict( operation="View Tool", id=item.id, webapp="community" ) ), + attach_popup=False, + filterable="advanced" ), + # Columns that are valid for filtering but are not visible. + grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" ) + ] + columns.append( grids.MulticolFilterColumn( "Search", + cols_to_filter=[ columns[0], columns[1] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) + global_actions = [ + grids.GridAction( "Upload tool", dict( controller='upload', action='upload', type='tool' ) ) + ] + operations = [ + grids.GridOperation( "Add to category", + condition=( lambda item: not item.deleted ), + allow_multiple=False, + url_args=dict( controller="common", action="add_category", webapp="community" ) ), + grids.GridOperation( "Remove from category", + condition=( lambda item: not item.deleted ), + allow_multiple=False, + url_args=dict( controller="common", action="remove_category", webapp="community" ) ), + grids.GridOperation( "View versions", condition=( lambda item: not item.deleted ), allow_multiple=False ) + ] + standard_filters = [ + grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), + grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) + ] + default_filter = dict( name="All", deleted="False" ) + num_rows_per_page = 50 + preserve_state = False + use_paging = True + def build_initial_query( self, session ): + return session.query( self.model_class ) + def apply_default_filter( self, trans, query, **kwargs ): + return query.filter( self.model_class.deleted==False ) + +class ToolBrowserController( BaseController ): + + tool_list_grid = ToolListGrid() + + @web.expose + def index( self, trans, **kwd ): + params = util.Params( kwd ) + message = util.restore_text( params.get( 'message', '' ) ) + status = params.get( 'status', 'done' ) + return trans.fill_template( '/webapps/community/index.mako', message=message, status=status ) + @web.expose + def browse_tools( self, trans, **kwargs ): + if 'operation' in kwargs: + operation = kwargs['operation'].lower() + if operation == "browse": + return trans.response.send_redirect( web.url_for( controller='tool_browser', + action='browse_tool', + **kwargs ) ) + elif operation == "view tool": + return trans.response.send_redirect( web.url_for( controller='tool_browser', + action='view_tool', + **kwargs ) ) + elif operation == "edit tool": + return trans.response.send_redirect( web.url_for( controller='common', + action='edit_tool', + cntrller='tool_browser', + **kwargs ) ) + # Render the list view + return self.tool_list_grid( trans, **kwargs ) + @web.expose + def browse_tool( self, trans, **kwd ): + params = util.Params( kwd ) + message = util.restore_text( params.get( 'message', '' ) ) + status = params.get( 'status', 'done' ) + return trans.fill_template( '/webapps/community/tool/browse_tool.mako', + tools=tools, + message=message, + status=status ) + @web.expose + def download_tool( self, trans, id=None, **kwd ): + params = util.Params( kwd ) + tool = None + # Get the tool + tool = None + if id is not None: + id = trans.app.security.decode_id( id ) + tool = trans.sa_session.query( trans.model.Tool ).get( id ) + if tool is None: + return trans.response.send_redirect( web.url_for( controller='tool_browser', + action='browse_tools', + message='Please select a Tool to edit (the tool ID provided was invalid)', + status='error' ) ) + + trans.response.set_content_type(tool.mimetype) + trans.response.headers['Content-Length'] = int( os.stat( tool.file_name ).st_size ) + trans.response.headers['Content-Disposition'] = 'attachment; filename=%s' % tool.download_file_name + return open( tool.file_name ) diff -r 83102f27fd1d -r ba5b796311f3 lib/galaxy/webapps/community/controllers/tool_browser.py --- a/lib/galaxy/webapps/community/controllers/tool_browser.py Mon Apr 26 17:02:37 2010 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -import sys, os, operator, string, shutil, re, socket, urllib, time, logging, mimetypes - -from galaxy.web.base.controller import * -from galaxy.webapps.community import model -from galaxy.web.framework.helpers import time_ago, iff, grids -from galaxy.model.orm import * -from common import * - -log = logging.getLogger( __name__ ) - -# States for passing messages -SUCCESS, INFO, WARNING, ERROR = "done", "info", "warning", "error" - -class ToolListGrid( grids.Grid ): - class NameColumn( grids.TextColumn ): - def get_value( self, trans, grid, tool ): - return tool.name - class CategoryColumn( grids.TextColumn ): - def get_value( self, trans, grid, tool ): - if tool.categories: - return tool.categories - return 'not set' - class StateColumn( grids.GridColumn ): - def get_value( self, trans, grid, tool ): - state = tool.state() - if state == tool.states.NEW: - return '<div class="count-box state-color-queued">%s</div>' % state - if state == tool.states.WAITING: - return '<div class="count-box state-color-running">%s</div>' % state - if state == tool.states.APPROVED: - return '<div class="count-box state-color-ok">%s</div>' % state - if state == tool.states.REJECTED or state == tool.states.ERROR: - return '<div class="count-box state-color-error">%s</div>' % state - return state - def get_accepted_filters( self ): - """ Returns a list of accepted filters for this column.""" - accepted_filter_labels_and_vals = [ model.Tool.states.NEW, - model.Tool.states.WAITING, - model.Tool.states.APPROVED, - model.Tool.states.REJECTED, - model.Tool.states.DELETED, - "All" ] - accepted_filters = [] - for val in accepted_filter_labels_and_vals: - label = val.lower() - args = { self.key: val } - accepted_filters.append( grids.GridColumnFilter( label, args ) ) - return accepted_filters - class UserColumn( grids.TextColumn ): - def get_value( self, trans, grid, tool ): - return tool.user.email - # Grid definition - title = "Tools" - model_class = model.Tool - template='/webapps/community/tool/grid.mako' - default_sort_key = "name" - columns = [ - NameColumn( "Name", - key="name", - model_class=model.Tool, - link=( lambda item: dict( operation="Edit Tool", id=item.id, webapp="community" ) ), - attach_popup=True, - filterable="advanced" ), - CategoryColumn( "Category", - key="category", - model_class=model.Category, - link=( lambda item: dict( operation="View Tool", id=item.id, webapp="community" ) ), - attach_popup=False, - filterable="advanced" ), - # Columns that are valid for filtering but are not visible. - grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" ) - ] - columns.append( grids.MulticolFilterColumn( "Search", - cols_to_filter=[ columns[0], columns[1] ], - key="free-text-search", - visible=False, - filterable="standard" ) ) - global_actions = [ - grids.GridAction( "Upload tool", dict( controller='upload', action='upload', type='tool' ) ) - ] - operations = [ - grids.GridOperation( "Add to category", - condition=( lambda item: not item.deleted ), - allow_multiple=False, - url_args=dict( controller="common", action="add_category", webapp="community" ) ), - grids.GridOperation( "Remove from category", - condition=( lambda item: not item.deleted ), - allow_multiple=False, - url_args=dict( controller="common", action="remove_category", webapp="community" ) ), - grids.GridOperation( "View versions", condition=( lambda item: not item.deleted ), allow_multiple=False ) - ] - standard_filters = [ - grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), - grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) - ] - default_filter = dict( name="All", deleted="False" ) - num_rows_per_page = 50 - preserve_state = False - use_paging = True - def build_initial_query( self, session ): - return session.query( self.model_class ) - def apply_default_filter( self, trans, query, **kwargs ): - return query.filter( self.model_class.deleted==False ) - -class ToolBrowserController( BaseController ): - - tool_list_grid = ToolListGrid() - - @web.expose - def index( self, trans, **kwd ): - params = util.Params( kwd ) - message = util.restore_text( params.get( 'message', '' ) ) - status = params.get( 'status', 'done' ) - return trans.fill_template( '/webapps/community/index.mako', message=message, status=status ) - @web.expose - def browse_tools( self, trans, **kwargs ): - if 'operation' in kwargs: - operation = kwargs['operation'].lower() - if operation == "browse": - return trans.response.send_redirect( web.url_for( controller='tool_browser', - action='browse_tool', - **kwargs ) ) - elif operation == "view tool": - return trans.response.send_redirect( web.url_for( controller='tool_browser', - action='view_tool', - **kwargs ) ) - elif operation == "edit tool": - return trans.response.send_redirect( web.url_for( controller='common', - action='edit_tool', - cntrller='tool_browser', - **kwargs ) ) - # Render the list view - return self.tool_list_grid( trans, **kwargs ) - @web.expose - def browse_tool( self, trans, **kwd ): - params = util.Params( kwd ) - message = util.restore_text( params.get( 'message', '' ) ) - status = params.get( 'status', 'done' ) - return trans.fill_template( '/webapps/community/tool/browse_tool.mako', - tools=tools, - message=message, - status=status ) - @web.expose - def download_tool( self, trans, id=None, **kwd ): - params = util.Params( kwd ) - tool = None - # Get the tool - tool = None - if id is not None: - id = trans.app.security.decode_id( id ) - tool = trans.sa_session.query( trans.model.Tool ).get( id ) - if tool is None: - return trans.response.send_redirect( web.url_for( controller='tool_browser', - action='browse_tools', - message='Please select a Tool to edit (the tool ID provided was invalid)', - status='error' ) ) - - trans.response.set_content_type(tool.mimetype) - trans.response.headers['Content-Length'] = int( os.stat( tool.file_name ).st_size ) - trans.response.headers['Content-Disposition'] = 'attachment; filename=%s' % tool.download_file_name - return open( tool.file_name ) diff -r 83102f27fd1d -r ba5b796311f3 lib/galaxy/webapps/community/controllers/upload.py --- a/lib/galaxy/webapps/community/controllers/upload.py Mon Apr 26 17:02:37 2010 -0400 +++ b/lib/galaxy/webapps/community/controllers/upload.py Tue Apr 27 09:32:38 2010 -0400 @@ -62,10 +62,10 @@ os.link( uploaded_file.name, obj.file_name ) except OSError: shutil.copy( uploaded_file.name, obj.file_name ) - # We're setting cntrller to 'tool_browser' since that is the only controller from which we can upload + # We're setting cntrller to 'tool' since that is the only controller from which we can upload return trans.response.send_redirect( web.url_for( controller='common', action='edit_tool', - cntrller='tool_browser', + cntrller='tool', id=trans.app.security.encode_id( obj.id ), message='Uploaded %s' % meta.message, status='done' ) ) diff -r 83102f27fd1d -r ba5b796311f3 templates/webapps/community/base_panels.mako --- a/templates/webapps/community/base_panels.mako Mon Apr 26 17:02:37 2010 -0400 +++ b/templates/webapps/community/base_panels.mako Tue Apr 27 09:32:38 2010 -0400 @@ -26,6 +26,7 @@ <td class="${cls}" style="${style}"><a target="${target}" href="${href}">${display}</a></td> </%def> + ${tab( "tools", "Tools", h.url_for( controller='/tool', action='index', webapp='community' ) )} ${tab( "admin", "Admin", h.url_for( controller='/admin', action='index', webapp='community' ), extra_class="admin-only", visible=( trans.user and app.config.is_admin_user( trans.user ) ) )} <td class="tab"> diff -r 83102f27fd1d -r ba5b796311f3 templates/webapps/community/index.mako --- a/templates/webapps/community/index.mako Mon Apr 26 17:02:37 2010 -0400 +++ b/templates/webapps/community/index.mako Tue Apr 27 09:32:38 2010 -0400 @@ -29,7 +29,7 @@ </div> <div class="toolSectionBody"> <div class="toolSectionBg"> - <div class="toolTitle"><a href="${h.url_for( controller='tool_browser', action='browse_tools' )}" target="galaxy_main">Browse tools</a></div> + <div class="toolTitle"><a href="${h.url_for( controller='tool', action='browse_tools' )}" target="galaxy_main">Browse tools</a></div> </div> </div> <div class="toolSectionPad"></div> @@ -51,7 +51,7 @@ if trans.app.config.require_login and not trans.user: center_url = h.url_for( controller='user', action='login', message=message, status=status ) else: - center_url = h.url_for( controller='tool_browser', action='browse_tools', message=message, status=status ) + center_url = h.url_for( controller='tool', action='browse_tools', message=message, status=status ) %> <iframe name="galaxy_main" id="galaxy_main" frameborder="0" style="position: absolute; width: 100%; height: 100%;" src="${center_url}"> </iframe> </%def> diff -r 83102f27fd1d -r ba5b796311f3 templates/webapps/community/tool/browse_tool.mako --- a/templates/webapps/community/tool/browse_tool.mako Mon Apr 26 17:02:37 2010 -0400 +++ b/templates/webapps/community/tool/browse_tool.mako Tue Apr 27 09:32:38 2010 -0400 @@ -29,7 +29,7 @@ </thead> <tbody> <tr class="formRow id="toolRow"> - <td><a href="${h.url_for( controller='tool_browser', action='browse', id=trans.security.encode_id( tool.id ) )}">${tool.name}</a></td> + <td><a href="${h.url_for( controller='tool', action='browse', id=trans.security.encode_id( tool.id ) )}">${tool.name}</a></td> <td>${tool.description}</td> </tr> </tbody> diff -r 83102f27fd1d -r ba5b796311f3 templates/webapps/community/tool/view_tool.mako --- a/templates/webapps/community/tool/view_tool.mako Mon Apr 26 17:02:37 2010 -0400 +++ b/templates/webapps/community/tool/view_tool.mako Tue Apr 27 09:32:38 2010 -0400 @@ -19,7 +19,7 @@ <div class="toolFormTitle">${tool.name} <em>${tool.description}</em> ${tool.version} (ID: ${tool.tool_id})</div> <div class="toolFormBody"> <div class="form-row"> - Uploaded by <a href="${h.url_for(controller='tool_browser', action='user_tools')}">${tool.user.username}</a> on ${tool.create_time.strftime('%B %d, %Y')} + Uploaded by <a href="${h.url_for(controller='tool', action='user_tools')}">${tool.user.username}</a> on ${tool.create_time.strftime('%B %d, %Y')} <div style="clear: both"></div> </div> <div class="form-row"> @@ -36,12 +36,12 @@ </div> <div class="form-row"> <label>Download:</label> - <a href="${h.url_for(controller='tool_browser', action='download_tool', id=trans.app.security.encode_id( tool.id ))}"><img src="${h.url_for('/static/images/silk/page_white_compressed.png')}"> ${tool.tool_id}_${tool.version}</a> + <a href="${h.url_for(controller='tool', action='download_tool', id=trans.app.security.encode_id( tool.id ))}"><img src="${h.url_for('/static/images/silk/page_white_compressed.png')}"> ${tool.tool_id}_${tool.version}</a> <div style="clear: both"></div> </div> %if trans.user.id == tool.user_id: <div class="form-row"> - <em>This is your tool. You may <a href="${h.url_for(controller='tool_browser', action='edit_tool', id=trans.app.security.encode_id( tool.id ) )}">edit it</a>.</em> + <em>This is your tool. You may <a href="${h.url_for(controller='tool', action='edit_tool', id=trans.app.security.encode_id( tool.id ) )}">edit it</a>.</em> <div style="clear: both"></div> </div> %endif
participants (1)
-
Nate Coraor