[hg] galaxy 2757: Cleaned up new/edit request code.
details: http://www.bx.psu.edu/hg/galaxy/rev/dcdbb13b0c76 changeset: 2757:dcdbb13b0c76 user: rc date: Wed Sep 23 17:16:13 2009 -0400 description: Cleaned up new/edit request code. 2 file(s) affected in this change: lib/galaxy/web/controllers/requests.py lib/galaxy/web/controllers/requests_admin.py diffs (211 lines): diff -r fbd7d0a0f596 -r dcdbb13b0c76 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Wed Sep 23 17:01:04 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Wed Sep 23 17:16:13 2009 -0400 @@ -462,31 +462,16 @@ helptext='(Optional)')) # libraries selectbox - all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \ - .order_by( trans.app.model.Library.name ).all() - user, roles = trans.get_user_and_roles() - actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ] - # The libraries dictionary looks like: { library : '1,2' }, library : '3' } - # Its keys are the libraries that should be displayed for the current user and whose values are a - # string of comma-separated folder ids, of the associated folders the should NOT be displayed. - # The folders that should not be displayed may not be a complete list, but it is ultimately passed - # to the calling method to keep from re-checking the same folders when the library / folder - # select lists are rendered. - libraries = odict() - for library in all_libraries: - can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check ) - if can_show: - libraries[ library ] = hidden_folder_ids - libui = self.__library_ui(trans, libraries, **kwd) + libui = self.__library_ui(trans, request=None, **kwd) widgets = widgets + libui - widgets = widgets + request_type.request_form.get_widgets( user, **kwd ) + widgets = widgets + request_type.request_form.get_widgets( trans.user, **kwd ) return trans.fill_template( '/requests/new_request.mako', select_request_type=select_request_type, request_type=request_type, widgets=widgets, msg=msg, messagetype=messagetype) - def __library_ui(self, trans, libraries, request=None, **kwd): + def __library_ui(self, trans, request=None, **kwd): params = util.Params( kwd ) lib_id = params.get( 'library_id', 'none' ) # if editing a request @@ -497,6 +482,16 @@ else: # new request selected_lib = None + # get all permitted libraries for this user + all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \ + .order_by( trans.app.model.Library.name ).all() + user, roles = trans.get_user_and_roles() + actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ] + libraries = odict() + for library in all_libraries: + can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check ) + if can_show: + libraries[ library ] = hidden_folder_ids lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()] lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list ) # fill up the options in the Library selectfield @@ -513,7 +508,7 @@ else: lib_list.add_option(lib.name, lib.id) lib_list.refresh_on_change_values.append(lib.id) - # new library + # new library option if lib_id == 'new': lib_list.add_option('Create a new data library', 'new', selected=True) else: @@ -539,8 +534,6 @@ else: folder_list.add_option('Select one', 'none') # get all show-able folders for the selected library - user, roles = trans.get_user_and_roles() - actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ] showable_folders = trans.app.security_agent.get_showable_folders( user, roles, selected_lib, actions_to_check, @@ -724,25 +717,9 @@ widget=TextField('desc', 40, desc), helptext='(Optional)')) # libraries selectbox - all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \ - .order_by( trans.app.model.Library.name ).all() - user, roles = trans.get_user_and_roles() - actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ] - # The libraries dictionary looks like: - # { library : '1,2' }, library : '3' } - # Its keys are the libraries that should be displayed for the current user and whose values are a - # string of comma-separated folder ids, of the associated folders the should NOT be displayed. - # The folders that should not be displayed may not be a complete list, but it is ultimately passed - # to the calling method to keep from re-checking the same folders when the library / folder - # select lists are rendered. - libraries = {} - for library in all_libraries: - can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check ) - if can_show: - libraries[ library ] = hidden_folder_ids - libui = self.__library_ui(trans, libraries, request, **kwd) + libui = self.__library_ui(trans, request, **kwd) widgets = widgets + libui - widgets = widgets + request.type.request_form.get_widgets( user, request.values.content, **kwd ) + widgets = widgets + request.type.request_form.get_widgets( trans.user, request.values.content, **kwd ) return trans.fill_template( '/requests/edit_request.mako', select_request_type=select_request_type, request_type=request.type, diff -r fbd7d0a0f596 -r dcdbb13b0c76 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Wed Sep 23 17:01:04 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Wed Sep 23 17:16:13 2009 -0400 @@ -720,9 +720,20 @@ """ params = util.Params( kwd ) lib_id = params.get( 'library_id', 'none' ) + # if editing a request + if request and lib_id == 'none': + if request.library: + lib_id = str(request.library.id) + selected_lib = request.library + else: + # new request + selected_lib = None + # if new request no user is selected initially, none of the libraries are + # listed in the selectfield if not user: libraries = {} else: + # get all permitted libraries for this user all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \ .order_by( trans.app.model.Library.name ).all() roles = user.all_roles() @@ -733,43 +744,38 @@ # The folders that should not be displayed may not be a complete list, but it is ultimately passed # to the calling method to keep from re-checking the same folders when the library / folder # select lists are rendered. - # - # TODO: RC, when you add the folders select list to your request form, take advantage of the hidden_folder_ids - # so that you do not need to check those same folders yet again when populating the select list. - # libraries = {} for library in all_libraries: can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check ) if can_show: libraries[ library ] = hidden_folder_ids + # create the selectfield lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()] lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list ) - folders = [] - if request and lib_id == 'none': - if request.library: - lib_id = str(request.library.id) + # first option if lib_id == 'none': lib_list.add_option('Select one', 'none', selected=True) else: lib_list.add_option('Select one', 'none') + # all the libraries available to the selected user for lib, hidden_folder_ids in libraries.items(): if str(lib.id) == lib_id: lib_list.add_option(lib.name, lib.id, selected=True) - folders.append( lib.root_folder ) - for f in lib.root_folder.folders: - if str(f.id) not in hidden_folder_ids.split(','): - folders.append( f ) + selected_lib, selected_hidden_folder_ids = lib, hidden_folder_ids.split(',') else: lib_list.add_option(lib.name, lib.id) lib_list.refresh_on_change_values.append(lib.id) + # new data library option if lib_id == 'new': lib_list.add_option('Create a new data library', 'new', selected=True) else: lib_list.add_option('Create a new data library', 'new') + # widget lib_widget = dict(label='Data library', widget=lib_list, helptext='Data library where the resultant dataset will be stored.') - if folders: + if selected_lib: + # when editing a request if request: if request.folder: current_fid = request.folder.id @@ -778,11 +784,22 @@ else: current_fid = params.get( 'folder_id', 'none' ) folder_list = SelectField( 'folder_id') - for f in folders: - if str(f.id) == current_fid: + # first option + if lib_id == 'none': + folder_list.add_option('Select one', 'none', selected=True) + else: + folder_list.add_option('Select one', 'none') + # get all show-able folders for the selected library + showable_folders = trans.app.security_agent.get_showable_folders( user, roles, + selected_lib, + actions_to_check, + selected_hidden_folder_ids ) + for f in showable_folders: + if str(f.id) == str(current_fid): folder_list.add_option(f.name, f.id, selected=True) else: folder_list.add_option(f.name, f.id) + # folder widget folder_widget = dict(label='Folder', widget=folder_list, helptext='Folder of the selected data library where the resultant dataset will be stored.') @@ -793,7 +810,7 @@ helptext='Enter a name here to request a new data library') return [lib_widget, new_lib] else: - if folders: + if selected_lib: return [lib_widget, folder_widget] else: return [lib_widget]
participants (1)
-
Nate Coraor