예제 #1
0
파일: forms.py 프로젝트: mmiladi/galaxy-old
 def show_editable_form_definition(self, trans, form_definition, current_form, message='', status='done', response_redirect=None, **kwd):
     """
     Displays the form and any of the changes made to it in edit mode. In this method
     all the widgets are build for all name, description and all the fields of a form
     definition.
     """
     util.Params(kwd)
     # name & description
     form_details = [('Name', TextField('name', 40, current_form['name'])),
                     ('Description', TextField('description', 40, current_form['desc'])),
                     ('Type', HiddenField('form_type_select_field', current_form['type']))]
     form_layout = []
     if current_form['type'] == trans.app.model.FormDefinition.types.SAMPLE:
         for index, layout_name in enumerate(current_form['layout']):
             form_layout.append(TextField('grid_layout%i' % index, 40, layout_name))
     # fields
     field_details = []
     for field_index, field in enumerate(current_form['fields']):
         field_widgets = self.build_form_definition_field_widgets(trans=trans,
                                                                  layout_grids=current_form['layout'],
                                                                  field_index=field_index,
                                                                  field=field,
                                                                  form_type=current_form['type'])
         field_details.append(field_widgets)
     return trans.fill_template('/admin/forms/edit_form_definition.mako',
                                form_details=form_details,
                                field_details=field_details,
                                form_definition=form_definition,
                                field_types=trans.model.FormDefinition.supported_field_types,
                                message=message,
                                status=status,
                                current_form_type=current_form['type'],
                                layout_grids=form_layout,
                                response_redirect=response_redirect)
예제 #2
0
파일: forms.py 프로젝트: mmiladi/galaxy-old
 def create_form_definition(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     self.__imported_from_file = False
     if params.get('create_form_button', False):
         form_definition, message = self.save_form_definition(trans, form_definition_current_id=None, **kwd)
         if not form_definition:
             return trans.response.send_redirect(web.url_for(controller='forms',
                                                             action='create_form_definition',
                                                             message=message,
                                                             status='error',
                                                             name=util.restore_text(params.get('name', '')),
                                                             description=util.restore_text(params.get('description', ''))))
         if self.__imported_from_file:
             return trans.response.send_redirect(web.url_for(controller='forms',
                                                             action='edit_form_definition',
                                                             id=trans.security.encode_id(form_definition.current.id)))
         else:
             return trans.response.send_redirect(web.url_for(controller='forms',
                                                             action='edit_form_definition',
                                                             id=trans.security.encode_id(form_definition.current.id),
                                                             add_field_button='Add field',
                                                             name=form_definition.name,
                                                             description=form_definition.desc,
                                                             form_type_select_field=form_definition.type))
     inputs = [('Name', TextField('name', 40, util.restore_text(params.get('name', '')))),
               ('Description', TextField('description', 40, util.restore_text(params.get('description', '')))),
               ('Type', self.__build_form_types_widget(trans, selected=params.get('form_type', 'none'))),
               ('Import from csv file (Optional)', FileField('file_data', 40, ''))]
     return trans.fill_template('/admin/forms/create_form.mako',
                                inputs=inputs,
                                message=message,
                                status=status)
예제 #3
0
 def __get_populated_request_type_widgets(self, trans, **kwd):
     request_form_definitions = self.get_all_forms(
         trans,
         filter=dict(deleted=False),
         form_type=trans.model.FormDefinition.types.REQUEST)
     sample_form_definitions = self.get_all_forms(
         trans,
         filter=dict(deleted=False),
         form_type=trans.model.FormDefinition.types.SAMPLE)
     if not request_form_definitions or not sample_form_definitions:
         return [], []
     params = util.Params(kwd)
     request_form_id = params.get('request_form_id', 'none')
     sample_form_id = params.get('sample_form_id', 'none')
     request_form_id_select_field = build_select_field(
         trans,
         objs=request_form_definitions,
         label_attr='name',
         select_field_name='request_form_id',
         selected_value=request_form_id,
         refresh_on_change=False)
     sample_form_id_select_field = build_select_field(
         trans,
         objs=sample_form_definitions,
         label_attr='name',
         select_field_name='sample_form_id',
         selected_value=sample_form_id,
         refresh_on_change=False)
     rt_info_widgets = [
         dict(label='Name',
              widget=TextField('name', 40,
                               util.restore_text(params.get('name', '')))),
         dict(label='Description',
              widget=TextField('desc', 40,
                               util.restore_text(params.get('desc', '')))),
         dict(label='Request form', widget=request_form_id_select_field),
         dict(label='Sample form', widget=sample_form_id_select_field)
     ]
     # Unsaved sample states being defined for this request type
     rt_states = []
     i = 0
     while True:
         if 'state_name_%i' % i in kwd:
             rt_states.append(
                 (util.restore_text(params.get('state_name_%i' % i, '')),
                  util.restore_text(params.get('state_desc_%i' % i, ''))))
             i += 1
         else:
             break
     return rt_info_widgets, rt_states
예제 #4
0
 def __build_external_service_widgets(self,
                                      trans,
                                      external_service=None,
                                      **kwd):
     params = util.Params(kwd)
     if external_service:
         name = external_service.name
         description = external_service.description
         version = external_service.version
         seq_type = external_service.external_service_type_id
     else:
         name = util.restore_text(params.get('external_service_name', ''))
         description = util.restore_text(
             params.get('external_service_description', ''))
         version = util.restore_text(
             params.get('external_service_version', ''))
         selected_seq_type = params.get('external_service_type_id', '')
         if selected_seq_type in trans.app.external_service_types.all_external_service_types:
             seq_type = trans.app.external_service_types.all_external_service_types[
                 selected_seq_type].id
         else:
             seq_type = 'none'
     widgets = [
         dict(label='Name',
              widget=TextField('external_service_name', 40, name),
              helptext=''),
         dict(label='Description',
              widget=TextField('external_service_description', 40,
                               description),
              helptext=''),
         dict(label='Version',
              widget=TextField('external_service_version', 40, version),
              helptext='')
     ]
     # Do not show the external_service_type selectfield when editing a external_service
     if not external_service:
         widgets.append(
             dict(label='External service type',
                  widget=self.__build_external_service_type_select_field(
                      trans,
                      seq_type,
                      visible_external_service_types_only=True),
                  helptext=''))
     return widgets
예제 #5
0
파일: forms.py 프로젝트: mmiladi/galaxy-old
 def __build_field_type_select_field_options(self, field, field_index):
     '''
     Returns a list of TextFields, one for each select field option
     '''
     field_type_options = []
     if field['selectlist']:
         for ctr, option in enumerate(field['selectlist']):
             option_textfield = TextField('field_' + str(field_index) + '_option_' + str(ctr), 40, option)
             field_type_options.append(('Option ' + str(ctr + 1), option_textfield))
     return field_type_options
예제 #6
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)]