def build_tool_dependencies_select_field(app,
                                         tool_shed_repository,
                                         name,
                                         multiple=True,
                                         display='checkboxes',
                                         uninstalled_only=False):
    """
    Generate a SelectField consisting of the current list of tool dependency ids
    for an installed tool shed repository.
    """
    tool_dependencies_select_field = SelectField(name=name,
                                                 multiple=multiple,
                                                 display=display)
    for tool_dependency in tool_shed_repository.tool_dependencies:
        if uninstalled_only:
            if tool_dependency.status not in [
                    app.install_model.ToolDependency.installation_status.
                    NEVER_INSTALLED, app.install_model.ToolDependency.
                    installation_status.UNINSTALLED
            ]:
                continue
        else:
            if tool_dependency.status in [
                    app.install_model.ToolDependency.installation_status.
                    NEVER_INSTALLED, app.install_model.ToolDependency.
                    installation_status.UNINSTALLED
            ]:
                continue
        option_label = '%s version %s' % (str(
            tool_dependency.name), str(tool_dependency.version))
        option_value = app.security.encode_id(tool_dependency.id)
        tool_dependencies_select_field.add_option(option_label, option_value)
    return tool_dependencies_select_field
Пример #2
0
def build_repository_type_select_field(trans,
                                       repository=None,
                                       name='repository_type'):
    """Called from the Tool Shed to generate the current list of supported repository types."""
    if repository:
        selected_type = str(repository.type)
    else:
        selected_type = None
    repository_type_select_field = SelectField(name=name)
    for type_label, type_class in trans.app.repository_types_registry.repository_types_by_label.items(
    ):
        option_label = str(type_class.label)
        option_value = str(type_class.type)
        if selected_type and selected_type == option_value:
            selected = True
        else:
            selected = False
        if repository:
            if repository.type == option_value:
                repository_type_select_field.add_option(option_label,
                                                        option_value,
                                                        selected=selected)
            elif type_class.is_valid_for_type(trans.app, repository):
                repository_type_select_field.add_option(option_label,
                                                        option_value,
                                                        selected=selected)
        else:
            repository_type_select_field.add_option(option_label,
                                                    option_value,
                                                    selected=selected)
    return repository_type_select_field
Пример #3
0
def build_changeset_revision_select_field( trans, repository, selected_value=None, add_id_to_name=True,
                                           downloadable=False, reviewed=False, not_reviewed=False ):
    """
    Build a SelectField whose options are the changeset_rev strings of certain revisions of the
    received repository.
    """
    options = []
    changeset_tups = []
    refresh_on_change_values = []
    if downloadable:
        # Restrict the options to downloadable revisions.
        repository_metadata_revisions = repository.downloadable_revisions
    elif reviewed:
        # Restrict the options to revisions that have been reviewed.
        repository_metadata_revisions = []
        metadata_changeset_revision_hashes = []
        for metadata_revision in repository.metadata_revisions:
            metadata_changeset_revision_hashes.append( metadata_revision.changeset_revision )
        for review in repository.reviews:
            if review.changeset_revision in metadata_changeset_revision_hashes:
                repository_metadata_revisions.append( review.repository_metadata )
    elif not_reviewed:
        # Restrict the options to revisions that have not yet been reviewed.
        repository_metadata_revisions = []
        reviewed_metadata_changeset_revision_hashes = []
        for review in repository.reviews:
            reviewed_metadata_changeset_revision_hashes.append( review.changeset_revision )
        for metadata_revision in repository.metadata_revisions:
            if metadata_revision.changeset_revision not in reviewed_metadata_changeset_revision_hashes:
                repository_metadata_revisions.append( metadata_revision )
    else:
        # Restrict the options to all revisions that have associated metadata.
        repository_metadata_revisions = repository.metadata_revisions
    for repository_metadata in repository_metadata_revisions:
        rev, label, changeset_revision = \
            hg_util.get_rev_label_changeset_revision_from_repository_metadata( trans.app,
                                                                               repository_metadata,
                                                                               repository=repository,
                                                                               include_date=True,
                                                                               include_hash=False )
        changeset_tups.append( ( rev, label, changeset_revision ) )
        refresh_on_change_values.append( changeset_revision )
    # Sort options by the revision label.  Even though the downloadable_revisions query sorts by update_time,
    # the changeset revisions may not be sorted correctly because setting metadata over time will reset update_time.
    for changeset_tup in sorted( changeset_tups ):
        # Display the latest revision first.
        options.insert( 0, ( changeset_tup[ 1 ], changeset_tup[ 2 ] ) )
    if add_id_to_name:
        name = 'changeset_revision_%d' % repository.id
    else:
        name = 'changeset_revision'
    select_field = SelectField( name=name,
                                refresh_on_change=True,
                                refresh_on_change_values=refresh_on_change_values )
    for option_tup in options:
        selected = selected_value and option_tup[ 1 ] == selected_value
        select_field.add_option( option_tup[ 0 ], option_tup[ 1 ], selected=selected )
    return select_field
Пример #4
0
def build_tool_panel_section_select_field(app):
    """Build a SelectField whose options are the sections of the current in-memory toolbox."""
    options = []
    for section_id, section_name in app.toolbox.get_sections():
        options.append((section_name, section_id))
    select_field = SelectField(name='tool_panel_section_id', display='radio')
    for option_tup in options:
        select_field.add_option(option_tup[0], option_tup[1])
    return select_field
 def build_repository_ids_select_field( self, name='repository_ids', multiple=True, display='checkboxes' ):
     """Generate the current list of repositories for resetting metadata."""
     repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
     query = self.get_query_for_setting_metadata_on_repositories( order=True )
     for repository in query:
         owner = str( repository.owner )
         option_label = '%s (%s)' % ( str( repository.name ), owner )
         option_value = '%s' % self.app.security.encode_id( repository.id )
         repositories_select_field.add_option( option_label, option_value )
     return repositories_select_field
Пример #6
0
def build_tool_panel_section_select_field( app ):
    """Build a SelectField whose options are the sections of the current in-memory toolbox."""
    options = []
    for k, v in app.toolbox.tool_panel.items():
        if isinstance( v, galaxy.tools.ToolSection ):
            options.append( ( v.name, v.id ) )
    select_field = SelectField( name='tool_panel_section_id', display='radio' )
    for option_tup in options:
        select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] )
    return select_field
Пример #7
0
def build_approved_select_field(trans, name, selected_value=None, for_component=True):
    options = [('No', trans.model.ComponentReview.approved_states.NO),
               ('Yes', trans.model.ComponentReview.approved_states.YES)]
    if for_component:
        options.append(('Not applicable', trans.model.ComponentReview.approved_states.NA))
        if selected_value is None:
            selected_value = trans.model.ComponentReview.approved_states.NA
    select_field = SelectField(name=name)
    for option_tup in options:
        selected = selected_value and option_tup[1] == selected_value
        select_field.add_option(option_tup[0], option_tup[1], selected=selected)
    return select_field
Пример #8
0
def build_shed_tool_conf_select_field(app):
    """Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs."""
    options = []
    for dynamic_tool_conf_filename in app.toolbox.dynamic_conf_filenames():
        if dynamic_tool_conf_filename.startswith('./'):
            option_label = dynamic_tool_conf_filename.replace('./', '', 1)
        else:
            option_label = dynamic_tool_conf_filename
        options.append((option_label, dynamic_tool_conf_filename))
    select_field = SelectField(name='shed_tool_conf')
    for option_tup in options:
        select_field.add_option(option_tup[0], option_tup[1])
    return select_field
Пример #9
0
 def __build_form_types_widget(self, trans, selected='none'):
     form_type_select_field = SelectField('form_type_select_field')
     if selected == 'none':
         form_type_select_field.add_option('Select one', 'none', selected=True)
     else:
         form_type_select_field.add_option('Select one', 'none')
     fd_types = trans.app.model.FormDefinition.types.items()
     fd_types.sort()
     for ft in fd_types:
         if selected == ft[1]:
             form_type_select_field.add_option(ft[1], ft[1], selected=True)
         else:
             form_type_select_field.add_option(ft[1], ft[1])
     return form_type_select_field
Пример #10
0
def build_shed_tool_conf_select_field( app ):
    """Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs."""
    options = []
    for shed_tool_conf_dict in app.toolbox.shed_tool_confs:
        shed_tool_conf_filename = shed_tool_conf_dict[ 'config_filename' ]
        if shed_tool_conf_filename != app.config.migrated_tools_config:
            if shed_tool_conf_filename.startswith( './' ):
                option_label = shed_tool_conf_filename.replace( './', '', 1 )
            else:
                option_label = shed_tool_conf_filename
            options.append( ( option_label, shed_tool_conf_filename ) )
    select_field = SelectField( name='shed_tool_conf' )
    for option_tup in options:
        select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] )
    return select_field
Пример #11
0
 def __build_external_service_type_select_field(
         self,
         trans,
         selected_value,
         refresh_on_change=True,
         visible_external_service_types_only=False):
     external_service_types = trans.app.external_service_types.all_external_service_types
     if visible_external_service_types_only:
         objs_list = [
             external_service_types[seq_type_id] for seq_type_id in
             trans.app.external_service_types.visible_external_service_types
         ]
     else:
         objs_list = external_service_types.values()
     refresh_on_change_values = ['none']
     refresh_on_change_values.extend(
         [trans.security.encode_id(obj.id) for obj in objs_list])
     select_external_service_type = SelectField(
         'external_service_type_id',
         refresh_on_change=refresh_on_change,
         refresh_on_change_values=refresh_on_change_values)
     if selected_value == 'none':
         select_external_service_type.add_option('Select one',
                                                 'none',
                                                 selected=True)
     else:
         select_external_service_type.add_option('Select one', 'none')
     for seq_type in objs_list:
         if seq_type.version:
             option_name = " ".join(
                 [seq_type.name, "version", seq_type.version])
         else:
             option_name = seq_type.name
         if selected_value == seq_type.id:
             select_external_service_type.add_option(option_name,
                                                     seq_type.id,
                                                     selected=True)
         else:
             select_external_service_type.add_option(
                 option_name, seq_type.id)
     return select_external_service_type
Пример #12
0
 def build_form_definition_field_widgets(self, trans, layout_grids,
                                         field_index, field, form_type):
     '''
     This method returns a list of widgets which describes a form definition field. This
     includes the field label, helptext, type, selectfield options, required/optional & layout
     '''
     # field label
     label = TextField('field_label_' + str(field_index), 40,
                       field['label'])
     # help text
     helptext = TextField('field_helptext_' + str(field_index), 40,
                          field['helptext'])
     # field type
     field_type_select_field = SelectField(
         'field_type_' + str(field_index),
         refresh_on_change=True,
         refresh_on_change_values=[SelectField.__name__])
     # fill up the field type selectfield options
     field_type_options = []
     # if the form is for defining samples, then use the sample field types
     # which does not include TextArea & AddressField
     if form_type == trans.model.FormDefinition.types.SAMPLE:
         for supported_field_type in trans.model.Sample.supported_field_types:
             if supported_field_type.__name__ == field['type']:
                 field_type_select_field.add_option(
                     supported_field_type.__name__,
                     supported_field_type.__name__,
                     selected=True)
                 if supported_field_type.__name__ == SelectField.__name__:
                     # when field type is Selectfield, add option Textfields
                     field_type_options = self.__build_field_type_select_field_options(
                         field, field_index)
             else:
                 field_type_select_field.add_option(
                     supported_field_type.__name__,
                     supported_field_type.__name__)
     else:
         for supported_field_type in trans.model.FormDefinition.supported_field_types:
             if supported_field_type.__name__ == field['type']:
                 field_type_select_field.add_option(
                     supported_field_type.__name__,
                     supported_field_type.__name__,
                     selected=True)
                 if supported_field_type.__name__ == SelectField.__name__:
                     # when field type is Selectfield, add option Textfields
                     field_type_options = self.__build_field_type_select_field_options(
                         field, field_index)
             else:
                 field_type_select_field.add_option(
                     supported_field_type.__name__,
                     supported_field_type.__name__)
     # required/optional radio button
     required = SelectField('field_required_' + str(field_index),
                            display='radio')
     if field['required'] == 'required':
         required.add_option('Required', 'required', selected=True)
         required.add_option('Optional', 'optional')
     else:
         required.add_option('Required', 'required')
         required.add_option('Optional', 'optional', selected=True)
     # layout grid option select_field
     if layout_grids and form_type == trans.model.FormDefinition.types.SAMPLE:
         layout_select_field = SelectField('field_layout_' +
                                           str(field_index))
         for index, grid_name in enumerate(layout_grids):
             if str(field.get('layout', None)) == str(
                     index
             ):  # existing behavior: integer indexes are stored as strings.
                 grid_selected = True
             else:
                 grid_selected = False
             layout_select_field.add_option("%i. %s" %
                                            (index + 1, grid_name),
                                            index,
                                            selected=grid_selected)
     # default value
     default_value = TextField('field_default_' + str(field_index), 40,
                               field.get('default', ''))
     # field name
     name = TextField('field_name_' + str(field_index), 40, field['name'])
     name_helptext = "The field name must be unique for each field and must contain only alphanumeric characters and underscore ."
     if layout_grids and form_type == trans.model.FormDefinition.types.SAMPLE:
         return [('Field label', label), ('Help text', helptext),
                 ('Type', field_type_select_field, "Add options below",
                  field_type_options), ('Default value', default_value),
                 ('', required),
                 ('Select the grid layout to place this field',
                  layout_select_field), ('Field name', name, name_helptext)]
     return [('Field label', label), ('Help text', helptext),
             ('Type', field_type_select_field, "Add options below",
              field_type_options), ('Default value', default_value),
             ('', required), ('Field name', name, name_helptext)]