Template fixes: get current FormDefinition when inheriting templates, and use filter then retrieving FormDeinition for library templates. A few other miscellaneous bug fixes as well. Functional tests should now pass.

This commit is contained in:
Greg Von Kuster
2009-09-20 11:48:51 -04:00
parent 0f294b742c
commit 2cd2c865ad
7 changed files with 83 additions and 23 deletions
+20 -5
View File
@@ -693,7 +693,10 @@ class Library( object ):
return None, inherited
def get_template_widgets( self, trans, get_contents=True ):
# See if we have any associated templates - the returned value for
# inherited is not applicable at the library level
# inherited is not applicable at the library level. The get_contents
# param is passed by callers that are inheriting a template - these
# are usually new library datsets for which we want to include template
# fields on the upload form.
info_association, inherited = self.get_info_association()
if info_association:
template = info_association.template
@@ -738,10 +741,16 @@ class LibraryFolder( object ):
return self.library_root[0].get_info_association( inherited=True )
return None, inherited
def get_template_widgets( self, trans, get_contents=True ):
# See if we have any associated templates
# See if we have any associated templates. The get_contents
# param is passed by callers that are inheriting a template - these
# are usually new library datsets for which we want to include template
# fields on the upload form.
info_association, inherited = self.get_info_association()
if info_association:
template = info_association.template
if inherited:
template = info_association.template.current.latest_form
else:
template = info_association.template
# See if we have any field contents, but only if the info_association was
# not inherited ( we do not want to display the inherited contents ).
if not inherited and get_contents:
@@ -881,10 +890,16 @@ class LibraryDatasetDatasetAssociation( DatasetInstance ):
return None, inherited
return self.library_dataset.folder.get_info_association( inherited=True )
def get_template_widgets( self, trans, get_contents=True ):
# See if we have any associated templates
# See if we have any associated templatesThe get_contents
# param is passed by callers that are inheriting a template - these
# are usually new library datsets for which we want to include template
# fields on the upload form.
info_association, inherited = self.get_info_association()
if info_association:
template = info_association.template
if inherited:
template = info_association.template.current.latest_form
else:
template = info_association.template
# See if we have any field contents, but only if the info_association was
# not inherited ( we do not want to display the inherited contents ).
if not inherited and get_contents:
+23 -3
View File
@@ -717,11 +717,21 @@ class Library( BaseController ):
if trans.app.security_agent.can_add_library_item( user, roles, folder ) or \
( replace_dataset and trans.app.security_agent.can_modify_library_item( user, roles, replace_dataset ) ):
if params.get( 'new_dataset_button', False ):
# See if we have any inherited templates, but do not inherit contents.
info_association, inherited = folder.get_info_association( inherited=True )
if info_association:
template_id = str( info_association.template.id )
widgets = folder.get_template_widgets( trans, get_contents=False )
else:
template_id = None
widgets = []
upload_option = params.get( 'upload_option', 'upload_file' )
created_ldda_ids = trans.webapp.controllers[ 'library_dataset' ].upload_dataset( trans,
controller='library',
library_id=library_id,
folder_id=folder_id,
template_id=template_id,
widgets=widgets,
replace_dataset=replace_dataset,
**kwd )
if created_ldda_ids:
@@ -1049,6 +1059,17 @@ class Library( BaseController ):
library_item_desc = 'library'
response_action = 'browse_library'
response_id = library_id
forms = get_all_forms( trans,
filter=dict( deleted=False ),
form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE )
if not forms:
msg = "There are no forms on which to base the template, so create a form and "
msg += "try again to add the information template to the %s." % library_item_desc
trans.response.send_redirect( web.url_for( controller='forms',
action='new',
new=True,
msg=msg,
messagetype='done' ) )
if params.get( 'add', False ):
if params.get( 'add_info_template_button', False ):
form = trans.app.model.FormDefinition.get( int( kwd[ 'form_id' ] ) )
@@ -1068,14 +1089,13 @@ class Library( BaseController ):
id=response_id,
msg=msg,
message_type='done' ) )
return trans.fill_template( '/library/select_info_template.mako',
return trans.fill_template( '/admin/library/select_info_template.mako',
library_item_name=library_item.name,
library_item_desc=library_item_desc,
library_id=library_id,
folder_id=folder_id,
ldda_id=ldda_id,
forms=get_all_forms( trans, filter=dict(deleted=False),
form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ),
forms=forms,
msg=msg,
messagetype=messagetype )
@web.expose
+13 -1
View File
@@ -429,11 +429,21 @@ class LibraryAdmin( BaseController ):
ldatatypes = [ dtype_name for dtype_name, dtype_value in trans.app.datatypes_registry.datatypes_by_extension.iteritems() if dtype_value.allow_datatype_change ]
ldatatypes.sort()
if params.get( 'new_dataset_button', False ):
# See if we have any inherited templates, but do not inherit contents.
info_association, inherited = folder.get_info_association( inherited=True )
if info_association:
template_id = str( info_association.template.id )
widgets = folder.get_template_widgets( trans, get_contents=False )
else:
template_id = None
widgets = []
upload_option = params.get( 'upload_option', 'upload_file' )
created_ldda_ids = trans.webapp.controllers[ 'library_dataset' ].upload_dataset( trans,
controller='library_admin',
library_id=library_id,
folder_id=folder_id,
template_id=template_id,
widgets=widgets,
replace_dataset=replace_dataset,
**kwd )
if created_ldda_ids:
@@ -915,7 +925,9 @@ class LibraryAdmin( BaseController ):
library_item_desc = 'library'
response_action = 'browse_library'
response_id = library_id
forms = get_all_forms( trans, filter=dict(deleted=False) )
forms = get_all_forms( trans,
filter=dict( deleted=False ),
form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE )
if not forms:
msg = "There are no forms on which to base the template, so create a form and "
msg += "try again to add the information template to the %s." % library_item_desc
@@ -203,16 +203,20 @@ class UploadLibraryDataset( BaseController ):
err_redirect = False
# See if we have any template field contents
template_field_contents = []
template = None
template_id = params.get( 'template_id', None )
folder = trans.app.model.LibraryFolder.get( folder_id )
info_association, inherited = folder.get_info_association()
if info_association:
template = info_association.template
# We are inheriting the folder's info_association, so we did not
# receive any inherited contents, but we may have redirected here
# after the user entered template contents ( due to errors ).
if template_id:
template = trans.app.model.FormDefinition.get( template_id )
for field_index in range( len( template.fields ) ):
field_name = 'field_%i' % field_index
if params.get( field_name, False ):
field_value = util.restore_text( params.get( field_name, '' ) )
template_field_contents.append( field_value )
else:
template = None
if upload_option == 'upload_file' and data_file == '' and url_paste == '':
msg = 'Select a file, enter a URL or enter text'
err_redirect = True
+6 -6
View File
@@ -226,15 +226,15 @@ class RowCounter( object ):
<h2>Data Library &ldquo;${library.name}&rdquo;</h2>
<%
can_add = trans.app.security_agent.can_add_library_item( user, roles, library )
can_modify = trans.app.security_agent.can_modify_library_item( user, roles, library )
can_manage = trans.app.security_agent.can_manage_library_item( user, roles, library )
can_add = trans.app.security_agent.can_add_library_item( user, roles, library )
can_modify = trans.app.security_agent.can_modify_library_item( user, roles, library )
can_manage = trans.app.security_agent.can_manage_library_item( user, roles, library )
%>
<ul class="manage-table-actions">
%if can_add and not_deleted:
%if can_add:
<li>
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library.id, folder_id=library.root_folder.id )}"><span>Add datasets to this library</span></a>
<a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library.id, folder_id=library.root_folder.id )}"><span>Add datasets to this data library</span></a>
</li>
<li>
<a class="action-button" href="${h.url_for( controller='library', action='folder', new=True, id=library.root_folder.id, library_id=library.id )}">Add a folder to this library</a>
@@ -246,7 +246,7 @@ can_manage = trans.app.security_agent.can_manage_library_item( user, roles, libr
<li><a class="action-button" href="${h.url_for( controller='library', action='library', information=True, id=library.id )}">View this library's information</a></li>
%endif
%if can_add and forms and not library.info_association:
<a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, add=True )}">Add an information template to this library</a>
<a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, add=True )}">Add an information template to this data library</a>
%endif
%if can_manage:
<li><a class="action-button" href="${h.url_for( controller='library', action='library', permissions=True, id=library.id )}">Edit this library's permissions</a></li>
+12 -3
View File
@@ -169,9 +169,18 @@
</div>
</div>
<div style="clear: both"></div>
<% folder = trans.app.model.LibraryFolder.get( folder_id ) %>
%if upload_option == 'upload_file' and widgets:
${render_template_info( folder, library_id, widgets )}
%if widgets:
<p/>
%for i, field in enumerate( widgets ):
<div class="form-row">
<label>${field[ 'label' ]}</label>
${field[ 'widget' ].get_html()}
<div class="toolParamHelp" style="clear: both;">
${field[ 'helptext' ]}
</div>
<div style="clear: both"></div>
</div>
%endfor
%endif
<div class="form-row">
<input type="submit" class="primary-button" name="new_dataset_button" value="Upload to library"/>
@@ -488,7 +488,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
.order_by( galaxy.model.FormDefinitionCurrent.table.c.create_time.desc() ) \
.all()
for fdc in fdcs:
if form_name == fdc.latest_form.name:
if form_name == fdc.latest_form.name and form_type == fdc.latest_form.type:
form_one = fdc.latest_form
break
assert form_one is not None, 'Problem retrieving form named (%s) from the database' % form_name