# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User Greg Von Kuster greg@bx.psu.edu # Date 1282855215 14400 # Node ID 39484914b8920148a4ac845570f7e2f743122f2f # Parent 1d373ebcef62fbe016d893d247eb6023cf705d05 Move the get_all_forms() method to the new base controller UsesFormDefinitionWidgets class and uncomment the final reset data method in the test_forms_and_request functional test script ( all library functional tests should once again pass ).
--- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -285,6 +285,22 @@ class UsesHistory( SharableItemSecurity
class UsesFormDefinitionWidgets: """Mixin for controllers that use Galaxy form objects.""" + def get_all_forms( self, trans, all_versions=False, filter=None, form_type='All' ): + """ + Return all the latest forms from the form_definition_current table + if all_versions is set to True. Otherwise return all the versions + of all the forms from the form_definition table. + """ + if all_versions: + return trans.sa_session.query( trans.app.model.FormDefinition ) + if filter: + fdc_list = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ).filter_by( **filter ) + else: + fdc_list = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ) + if form_type == 'All': + return [ fdc.latest_form for fdc in fdc_list ] + else: + return [ fdc.latest_form for fdc in fdc_list if fdc.latest_form.type == form_type ] def widget_fields_have_contents( self, widgets ): # Return True if any of the fields in widgets contain contents, widgets is a list of dictionaries that looks something like: # [{'widget': <galaxy.web.form_builder.TextField object at 0x10867aa10>, 'helptext': 'Field 0 help (Optional)', 'label': 'Field 0'}]
--- a/test/functional/test_forms_and_requests.py +++ b/test/functional/test_forms_and_requests.py @@ -360,44 +360,44 @@ class TestFormsAndRequests( TwillTestCas # check if the request's state is now set to 'submitted' assert request_two.state is not request_two.states.REJECTED, "The state of the request '%s' should be set to '%s'" \ % ( request_two.name, request_two.states.REJECTED ) -# def test_055_reset_data_for_later_test_runs( self ): -# """Reseting data to enable later test runs to pass""" -# # Logged in as admin_user -# # remove the request_type permissions -# rt_actions = sa_session.query( galaxy.model.RequestTypePermissions ) \ -# .filter(and_(galaxy.model.RequestTypePermissions.table.c.request_type_id==request_type.id) ) \ -# .order_by( desc( galaxy.model.RequestTypePermissions.table.c.create_time ) ) \ -# .all() -# for a in rt_actions: -# sa_session.delete( a ) -# sa_session.flush() -# ################## -# # Purge all libraries -# ################## -# for library in [ library_one ]: -# self.delete_library_item( 'library_admin', -# self.security.encode_id( library.id ), -# self.security.encode_id( library.id ), -# library.name, -# item_type='library' ) -# self.purge_library( self.security.encode_id( library.id ), library.name ) -# ################## -# # Eliminate all non-private roles -# ################## -# for role in [ role_one, role_two ]: -# self.mark_role_deleted( self.security.encode_id( role.id ), role.name ) -# self.purge_role( self.security.encode_id( role.id ), role.name ) -# # Manually delete the role from the database -# sa_session.refresh( role ) -# sa_session.delete( role ) -# sa_session.flush() -# ################## -# # Eliminate all groups -# ################## -# for group in [ group_one ]: -# self.mark_group_deleted( self.security.encode_id( group.id ), group.name ) -# self.purge_group( self.security.encode_id( group.id ), group.name ) -# # Manually delete the group from the database -# refresh( group ) -# sa_session.delete( group ) -# sa_session.flush() + def test_055_reset_data_for_later_test_runs( self ): + """Reseting data to enable later test runs to pass""" + # Logged in as admin_user + # remove the request_type permissions + rt_actions = sa_session.query( galaxy.model.RequestTypePermissions ) \ + .filter(and_(galaxy.model.RequestTypePermissions.table.c.request_type_id==request_type.id) ) \ + .order_by( desc( galaxy.model.RequestTypePermissions.table.c.create_time ) ) \ + .all() + for a in rt_actions: + sa_session.delete( a ) + sa_session.flush() + ################## + # Purge all libraries + ################## + for library in [ library_one ]: + self.delete_library_item( 'library_admin', + self.security.encode_id( library.id ), + self.security.encode_id( library.id ), + library.name, + item_type='library' ) + self.purge_library( self.security.encode_id( library.id ), library.name ) + ################## + # Eliminate all non-private roles + ################## + for role in [ role_one, role_two ]: + self.mark_role_deleted( self.security.encode_id( role.id ), role.name ) + self.purge_role( self.security.encode_id( role.id ), role.name ) + # Manually delete the role from the database + sa_session.refresh( role ) + sa_session.delete( role ) + sa_session.flush() + ################## + # Eliminate all groups + ################## + for group in [ group_one ]: + self.mark_group_deleted( self.security.encode_id( group.id ), group.name ) + self.purge_group( self.security.encode_id( group.id ), group.name ) + # Manually delete the group from the database + refresh( group ) + sa_session.delete( group ) + sa_session.flush()
--- a/templates/user/new_address.mako +++ b/templates/user/new_address.mako @@ -43,7 +43,7 @@ <div style="clear: both"></div></div><div class="form-row"> - <label>Address Line 1:</label> + <label>Address:</label><div style="float: left; width: 250px; margin-right: 10px;"><input type="text" name="address" value="${address}" size="40"></div>
--- a/lib/galaxy/web/controllers/user.py +++ b/lib/galaxy/web/controllers/user.py @@ -216,14 +216,10 @@ class User( BaseController, UsesFormDefi the one that user has selected. And for existing users, the user info form is retrieved from the db. ''' - # TODO: the user controller must be decoupled from the model, so this import causes problems. - # The get_all_forms method is used only if Galaxy is the webapp, so it needs to be re-worked - # so that it can be imported with no problems if the controller is not 'galaxy'. - from galaxy.web.controllers.forms import get_all_forms params = util.Params( kwd ) # get all the user information forms - user_info_forms = get_all_forms( trans, filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.USER_INFO ) + user_info_forms = self.get_all_forms( trans, filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.USER_INFO ) if new_user: # if there are no user forms available then there is nothing to save if not len( user_info_forms ): @@ -331,10 +327,9 @@ class User( BaseController, UsesFormDefi error = self.__validate_username( trans, username ) if not error: if webapp == 'galaxy': - from galaxy.web.controllers.forms import get_all_forms - if len( get_all_forms( trans, - filter=dict( deleted=False ), - form_type=trans.app.model.FormDefinition.types.USER_INFO ) ): + if len( self.get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.USER_INFO ) ): if not params.get( 'user_info_select', False ): return "Select the user's type and information" return error @@ -347,12 +342,11 @@ class User( BaseController, UsesFormDefi show a selectbox containing all the forms, then the user can select the one that fits the user's description the most ''' - from galaxy.web.controllers.forms import get_all_forms params = util.Params( kwd ) # get all the user information forms - user_info_forms = get_all_forms( trans, - filter=dict( deleted=False ), - form_type=trans.app.model.FormDefinition.types.USER_INFO ) + user_info_forms = self.get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.USER_INFO ) user_info_select = None if user: if user.values: @@ -423,7 +417,6 @@ class User( BaseController, UsesFormDefi message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) if webapp == 'galaxy': - from galaxy.web.controllers.forms import get_all_forms user_info_select, user_info_form, widgets = self.__user_info_ui( trans, user, **kwd ) # user's addresses show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) ) @@ -433,9 +426,9 @@ class User( BaseController, UsesFormDefi addresses = [address for address in user.addresses if address.deleted] else: addresses = [address for address in user.addresses if not address.deleted] - user_info_forms = get_all_forms( trans, - filter=dict( deleted=False ), - form_type=trans.app.model.FormDefinition.types.USER_INFO ) + user_info_forms = self.get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.USER_INFO ) return trans.fill_template( '/webapps/galaxy/user/info.mako', user=user, email=email,
--- a/lib/galaxy/web/controllers/requests_common.py +++ b/lib/galaxy/web/controllers/requests_common.py @@ -7,7 +7,6 @@ from galaxy.util.streamball import Strea import logging, tempfile, zipfile, tarfile, os, sys, subprocess from galaxy.web.form_builder import * from datetime import datetime, timedelta -from galaxy.web.controllers.forms import get_all_forms from sqlalchemy.sql.expression import func, and_ from sqlalchemy.sql import select import pexpect
--- a/lib/galaxy/web/controllers/forms.py +++ b/lib/galaxy/web/controllers/forms.py @@ -665,21 +665,3 @@ class Forms( BaseController ): current_form_type=current_form[ 'type' ], layout_grids=form_layout, response_redirect=response_redirect ) - -# Common methods for all components that use forms -def get_all_forms( trans, all_versions=False, filter=None, form_type='All' ): - ''' - Return all the latest forms from the form_definition_current table - if all_versions is set to True. Otherwise return all the versions - of all the forms from the form_definition table. - ''' - if all_versions: - return trans.sa_session.query( trans.app.model.FormDefinition ) - if filter: - fdc_list = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ).filter_by( **filter ) - else: - fdc_list = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ) - if form_type == 'All': - return [ fdc.latest_form for fdc in fdc_list ] - else: - return [ fdc.latest_form for fdc in fdc_list if fdc.latest_form.type == form_type ]
--- a/templates/user/edit_address.mako +++ b/templates/user/edit_address.mako @@ -42,7 +42,7 @@ <div style="clear: both"></div></div><div class="form-row"> - <label>Address Line 1:</label> + <label>Address:</label><div style="float: left; width: 250px; margin-right: 10px;"><input type="text" name="address" value="${address_obj.address}" size="40"></div>
--- a/lib/galaxy/web/controllers/requests_admin.py +++ b/lib/galaxy/web/controllers/requests_admin.py @@ -8,7 +8,6 @@ import logging, tempfile, zipfile, tarfi from galaxy.web.form_builder import * from datetime import datetime, timedelta from email.MIMEText import MIMEText -from galaxy.web.controllers.forms import get_all_forms from sqlalchemy.sql.expression import func, and_ from sqlalchemy.sql import select import pexpect @@ -264,7 +263,7 @@ class DataTransferGrid( grids.Grid ): # ---- Request Controller ------------------------------------------------------ #
-class RequestsAdmin( BaseController ): +class RequestsAdmin( BaseController, UsesFormDefinitionWidgets ): request_grid = RequestsGrid() requesttype_grid = RequestTypeGrid() datatx_grid = DataTransferGrid() @@ -1061,7 +1060,7 @@ class RequestsAdmin( BaseController ): message="Invalid requesttype ID") ) return trans.fill_template( '/admin/requests/view_request_type.mako', request_type=rt, - forms=get_all_forms( trans ), + forms=self.get_all_forms( trans ), states_list=rt.states, rename_dataset_selectbox=self.__rename_dataset_selectbox(trans, rt) ) def __view_form(self, trans, **kwd): @@ -1104,7 +1103,7 @@ class RequestsAdmin( BaseController ): rt, message = self.__save_request_type(trans, **kwd) if not rt: return trans.fill_template( '/admin/requests/create_request_type.mako', - forms=get_all_forms( trans ), + forms=self.get_all_forms( trans ), message=message, status='error') return trans.response.send_redirect( web.url_for( controller='requests_admin', @@ -1144,12 +1143,12 @@ class RequestsAdmin( BaseController ): status=status, rename_dataset_selectbox=self.__rename_dataset_selectbox(trans)) def __create_request_type_form(self, trans, **kwd): - request_forms=get_all_forms( trans, - filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.REQUEST ) - sample_forms=get_all_forms( trans, - filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.SAMPLE ) + request_forms=self.get_all_forms( trans, + filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.REQUEST ) + sample_forms=self.get_all_forms( trans, + filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.SAMPLE ) if not len(request_forms) or not len(sample_forms): return [],[] params = util.Params( kwd )
--- a/lib/galaxy/web/controllers/library_common.py +++ b/lib/galaxy/web/controllers/library_common.py @@ -5,7 +5,6 @@ from galaxy.datatypes import sniff from galaxy.security import RBACAgent from galaxy.util.json import to_json_string from galaxy.tools.actions import upload_common -from galaxy.web.controllers.forms import get_all_forms from galaxy.model.orm import * from galaxy.util.streamball import StreamBall import logging, tempfile, zipfile, tarfile, os, sys @@ -1935,9 +1934,9 @@ class LibraryCommon( BaseController, Use @web.expose def add_template( self, trans, cntrller, item_type, library_id, folder_id=None, ldda_id=None, **kwd ): # Template can only be added to a Library, Folder or LibraryDatasetDatasetAssociation. - forms = get_all_forms( trans, - filter=dict( deleted=False ), - form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ) + forms = self.get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ) if not forms: message = "There are no forms on which to base the template, so create a form and then add the template." return trans.response.send_redirect( web.url_for( controller='forms',
galaxy-commits@lists.galaxyproject.org