예제 #1
0
파일: form.py 프로젝트: yjarosz/pygdv
class NewTrackSequence(twf.TableForm):
    file_upload = twf.FileField(label='Upload : ',
                                help_text='Upload file from filesystem')
    url = twf.TextField(label='Url : ', help_text='Provide an url')
    sequence_id = twf.HiddenField()
    track_admin = twf.HiddenField()
    submit = twf.SubmitButton(id="submit", value="New")
예제 #2
0
class NewPresentationForm(AddRecordForm):
    __model__ = Presentation
    __require_fields__ = ['title', 'date']
    __omit_fields__ = ['files', '_other_authors']
    __field_order__ = [
        'title', 'description', 'date', 'thumbnail', 'repo_url', 'authors',
        'other_authors', 'file', 'file_description', 'file_2',
        'file_2_description', 'file_3', 'file_3_description'
    ]
    __base_validator__ = form_validator
    other_authors = twf.TextField('other_authors',
                                  placeholder='Separate by commas')
    repo_url = twf.UrlField('repo_url')
    # this sucks, but I can't figure out a cleaner, simpler way of doing it
    file = twf.FileField('file')
    file_description = twf.TextField('file_description')
    file_2 = twf.FileField('file_2')
    file_2_description = twf.TextField('file_2_description')
    file_3 = twf.FileField('file_3')
    file_3_description = twf.TextField('file_3_description')
예제 #3
0
파일: form.py 프로젝트: yjarosz/pygdv
class NewTrackPrefilled(twf.TableForm):
    file_upload = twf.FileField(label='Upload : ',
                                help_text='Upload file from filesystem')
    url = twf.TextField(label='Url : ', help_text='Provide an url')
    trackname = twf.TextField(label='Name : ')
    extension = twf.TextField(
        label='Extension : ',
        help_text=
        "Specify the extension of your file if it's not already provided by your file name."
    )
    project_id = twf.HiddenField()
    submit = twf.SubmitButton(id="submit", value="New")
예제 #4
0
        class child(twf.TableLayout):
            file = twf.FileField(validator=twf.FileValidator(required=True, extention='.html'))
            email = twf.TextField(validator=twc.EmailValidator(required=True))
#            confirm_email = twf.TextField()

            class fred(twf.GridLayout):
                repetitions = 3
                class child(twf.RowLayout):
                    bob = twf.TextField()
                    rob = twf.TextField()
                    validator = twc.MatchValidator('bob', 'rob')

            select = twf.SingleSelectField(options=list(enumerate(opts)), validator=twc.Validator(required=True), item_validator=twc.IntValidator())
예제 #5
0
파일: form.py 프로젝트: yjarosz/pygdv
class NewTrack(twf.TableForm):
    file_upload = twf.FileField(label='Upload : ',
                                help_text='Upload file from filesystem')
    url = twf.TextField(label='Url : ', help_text='Provide an url')
    smapping = twf.HiddenField()
    trackname = twf.TextField(label='Name : ')
    extension = twf.TextField(
        label='Extension : ',
        help_text=
        "Specify the extension of your file if it's not already provided by your file name."
    )
    species = twf.SingleSelectField(label='Species :')
    assembly = twf.SingleSelectField(label='Assembly :', options=[])
    submit = twf.SubmitButton(id="submit", value="New")
예제 #6
0
파일: form.py 프로젝트: yjarosz/pygdv
class MultipleFileUpload(twd.GrowingGridLayout):
    f = twf.FileField()
    more = twf.CheckBox()
예제 #7
0
def clone_form(user_lab, id_object):
    '''
    to clone dynamic measurement form
    '''
    lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()
    #static list    ]
    list_static = [
        twf.HiddenField(id="IDselected", label_text="ID selected :"),
        twf.TextField(id="name",
                      label_text="Name :",
                      placeholder="Measurement name...",
                      validator=twc.Validator(required=True)),
        twf.TextArea(id="description", label_text="Description :"),
        twf.MultipleSelectField(
            id="samples",
            label_text="Your samples : ",
            help_text="You can add some of your existing data to this project."
        ),
        twf.CheckBox(
            id="status_type",
            label_text="Privacy : ",
            help_text=
            "Check to have it available from outside EPFL (required for UCSC visualisation)"
        ),
        twf.CheckBox(id="type",
                     label_text="Raw data : ",
                     help_text="Check if raw data"),
        #twf.MultipleSelectField(id="parents", label_text="Parents : ", help_text="Parent(s) of this measurement."),
        twd.HidingRadioButtonList(id="upload_way",
                                  label_text='Upload my file via...',
                                  options=('my computer', 'a Vital-IT path',
                                           'a URL'),
                                  mapping={
                                      'my computer': ['upload'],
                                      'a Vital-IT path': ['vitalit_path'],
                                      'a URL': ['url_path', 'url_up'],
                                  }),
        twf.FileField(id="upload", help_text='Please provide a data'),
        twf.TextField(id="vitalit_path",
                      label_text="Scratch path",
                      placeholder="/scratch/el/biorepo/dropbox/"),
        twf.TextField(id="url_path",
                      label_text="File's url",
                      placeholder="http://www..."),
        twf.CheckBox(id="url_up",
                     label_text="I want to upload the file from this URL : ",
                     help_text="tick it if you want to download it in BioRepo")
    ]

    list_dynamic = []
    if lab is None:
        print "----- no dynamic fields detected ---------"
        list_fields = [list_static, list_dynamic]
        return list_fields
    else:
        to_clone = DBSession.query(Measurements).filter(
            Measurements.id == int(id_object)).first()
        tag = "measurements"

        if to_clone is not None:
            list_dynamic_attributes = to_clone.attributs
            for att in list_dynamic_attributes:
                if att.deprecated == False:
                    twf_type = convert_widget(att.widget)
                    twf_type.id = att.key
                    list_a_values = att.values

                    if att.widget == "textfield" or att.widget == "textarea" or att.widget == "hiding_textfield" or att.widget == "hiding_textarea":
                        for v in list_a_values:
                            if hasattr(v, tag):
                                value_object = getattr(v, tag)
                            if to_clone in value_object:
                                twf_type.value = v.value
                        list_dynamic.append(twf_type)
                    elif att.widget == "checkbox" or att.widget == "hiding_checkbox":
                        for v in list_a_values:
                            if hasattr(v, tag):
                                value_object = getattr(v, tag)
                            if to_clone in value_object:
                                #dynamic boolean are stored in varchar in the db, we have to cast them in boolean for the display
                                value_2_display = check_boolean(v.value)
                                twf_type.value = value_2_display
                        list_dynamic.append(twf_type)
                    elif att.widget == "multipleselectfield" or att.widget == "hiding_multipleselectfield":
                        list_possible_values = []
                        for v in list_a_values:
                            list_possible_values.append(v.value)
                        twf_type.options = list_possible_values
                        selected_values = []
                        for v in list_a_values:
                            if hasattr(v, tag):
                                value_object = getattr(v, tag)
                            if to_clone in value_object:
                                selected_values.append(v.value)
                        twf_type.value = selected_values
                        list_dynamic.append(twf_type)

                    elif att.widget == "singleselectfield" or att.widget == "hiding_singleselectfield":
                        list_possible_values = []
                        for v in list_a_values:
                            if v.value not in list_possible_values:
                                list_possible_values.append(v.value)
                        twf_type.options = list_possible_values
                        for v in list_a_values:
                            if hasattr(v, tag):
                                value_object = getattr(v, tag)
                            if to_clone in value_object:
                                twf_type.value = v.value
                        list_dynamic.append(twf_type)

        else:
            print "Your measurement was not found. ID problem. id :", id_object
            raise

        list_fields = [list_static, list_dynamic]
        return list_fields
예제 #8
0
def new_form_parents(user_lab):
    '''for new form with parents'''
    lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()

    #static lists
    list_static_samples = [
        twf.SingleSelectField(id="project",
                              label_text="Your projects : ",
                              help_text="Select project for this sample",
                              prompt_text=None),
        twf.TextField(id="name",
                      label_text="Name :",
                      validator=twc.Validator(required=True)),
        twf.SingleSelectField(id="type",
                              label_text="Type : ",
                              help_text="Technique used",
                              prompt_text=None),
        twf.TextArea(
            id="protocole",
            label_text="Protocole :",
        )
    ]
    list_static_measurements = [
        twf.HiddenField(id="IDselected", label_text="ID selected :"),
        twf.TextField(id="name",
                      label_text="Name :",
                      placeholder="Measurement name...",
                      validator=twc.Validator(required=True)),
        twf.TextArea(id="description", label_text="Description :"),
        twf.MultipleSelectField(
            id="samples",
            label_text="Your samples : ",
            help_text="You can add some of your existing data to this project."
        ),
        twf.CheckBox(
            id="status_type",
            label_text="Privacy : ",
            help_text=
            "Check to have it available from outside EPFL (required for UCSC visualisation)"
        ),
        twf.CheckBox(id="type",
                     label_text="Raw data : ",
                     help_text="Check if raw data"),
        twf.MultipleSelectField(id="parents",
                                label_text="Parents : ",
                                help_text="Parent(s) of this measurement."),
        twd.HidingRadioButtonList(id="upload_way",
                                  label_text='Upload my file via...',
                                  options=('my computer', 'a Vital-IT path',
                                           'a URL'),
                                  mapping={
                                      'my computer': ['upload'],
                                      'a Vital-IT path': ['vitalit_path'],
                                      'a URL': ['url_path', 'url_up'],
                                  }),
        twf.FileField(id="upload", help_text='Please provide a data'),
        twf.TextField(id="vitalit_path",
                      label_text="Scratch path",
                      placeholder="/scratch/el/biorepo/dropbox/"),
        twf.TextField(id="url_path",
                      label_text="File's url",
                      placeholder="http://www..."),
        twf.CheckBox(id="url_up",
                     label_text="I want to upload the file from this URL : ",
                     help_text="tick it if you want to download it in BioRepo")
    ]
    list_dynamic_samples = []
    list_hiding_samples = []
    list_dynamic_measurements = []
    list_hiding_meas = []
    #catch the dynamic hiding fields
    dic_hiding_meas = session.get("hiding_meas", {})
    dic_hiding_samples = session.get("hiding_sample", {})

    if lab is None:
        print "----- no dynamic fields detected ---------"
        list_fields = [
            list_static_samples, list_dynamic_samples,
            list_static_measurements, list_dynamic_measurements
        ]
        return list_fields
    else:
        lab_id = lab.id
        list_attributs = DBSession.query(Attributs).filter(
            Attributs.lab_id == lab_id).all()

        if len(list_attributs) > 0:
            #lists_construction(list_attributs)
            for a in list_attributs:
                attribut_key = a.key
                deprecated = a.deprecated
                fixed_value = a.fixed_value
                widget = a.widget
                owner = a.owner
                #############################
                ######### NEW SAMPLE ########
                #############################
                if owner == "sample":
                    #dynamic
                    if not deprecated and fixed_value:
                        twf_type = convert_widget(widget)
                        twf_type.id = attribut_key
                        if widget == "multipleselectfield" or widget == "singleselectfield":
                            list_values = []
                            list_attributes_values = DBSession.query(
                                Attributs_values).filter(
                                    Attributs_values.attribut_id ==
                                    a.id).all()
                            for av in list_attributes_values:
                                if not av.deprecated and av.value not in list_values:
                                    list_values.append(av.value)
                            twf_type.options = list_values
                            list_dynamic_samples.append(twf_type)

                        elif widget == "checkbox":
                            list_dynamic_samples.append(twf_type)

                        elif widget == "hiding_singleselectfield":
                            list_values = []
                            list_attributes_values = DBSession.query(
                                Attributs_values).filter(
                                    Attributs_values.attribut_id ==
                                    a.id).all()
                            for av in list_attributes_values:
                                if not av.deprecated and av.value not in list_values:
                                    list_values.append(av.value)
                            twf_type.options = list_values
                            list_hiding_samples.append(twf_type)

                        elif widget == "hiding_checkbox":
                            list_hiding_samples.append(twf_type)

                        else:
                            print widget, "-----ERROR----- ELSE, type samples widget in forms.py"
                    elif not deprecated and not fixed_value:
                        twf_type = convert_widget(widget)
                        twf_type.id = attribut_key
                        if widget == "textfield" or widget == "textarea":
                            twf_type.placeholder = "Write here..."
                            list_dynamic_samples.append(twf_type)
                        elif widget == "checkbox":
                            list_dynamic_samples.append(twf_type)
                        elif widget == "hiding_textfield" or widget == "hiding_textarea":
                            twf_type.placeholder = "Write here..."
                            list_hiding_samples.append(twf_type)
                        elif widget == "hiding_checkbox":
                            list_hiding_samples.append(twf_type)
                        else:
                            print widget, "WIDGET SAMPLE NOT FOUND, add an elif please"
                            raise
                    elif deprecated:
                        pass
                    else:
                        print "WIDGET SAMPLES ERROR : widget type is not known --> ", widget
                        raise
                ################################
                ######## NEW MEASUREMENT #######
                ################################
                elif owner == "measurement":
                    #dynamic
                    #for attributes with fixed values
                    if not deprecated and fixed_value:
                        twf_type = convert_widget(widget)
                        twf_type.id = attribut_key
                        if widget == "multipleselectfield" or widget == "singleselectfield":
                            list_values = []
                            list_attributes_values = DBSession.query(
                                Attributs_values).filter(
                                    Attributs_values.attribut_id ==
                                    a.id).all()
                            for av in list_attributes_values:
                                if not av.deprecated and av.value not in list_values:
                                    list_values.append(av.value)
                            twf_type.options = list_values
                            list_dynamic_measurements.append(twf_type)

                        elif widget == "hiding_singleselectfield":
                            list_values = []
                            list_attributes_values = DBSession.query(
                                Attributs_values).filter(
                                    Attributs_values.attribut_id ==
                                    a.id).all()
                            for av in list_attributes_values:
                                if not av.deprecated and av.value not in list_values:
                                    list_values.append(av.value)
                            twf_type.options = list_values
                            list_hiding_meas.append(twf_type)
                        #elif widget == "checkbox":
                        #list_dynamic_measurements.append(twf_type)
                        else:
                            print widget, "-----ERROR----- ELSE, type measurements widget in forms.py"
                            raise

                    #for others attributes
                    elif not deprecated and not fixed_value:
                        twf_type = convert_widget(widget)
                        twf_type.id = attribut_key
                        if widget == "textfield" or widget == "textarea":
                            twf_type.placeholder = "Write here..."
                            list_dynamic_measurements.append(twf_type)
                        elif widget == "checkbox":
                            list_dynamic_measurements.append(twf_type)
                        elif widget == "hiding_textfield" or widget == "hiding_textarea":
                            twf_type.placeholder = "Write here..."
                            list_hiding_meas.append(twf_type)
                        elif widget == "hiding_checkbox":
                            list_hiding_meas.append(twf_type)
                        else:
                            print widget, "WIGDET MEASUREMENT NOT FOUND, add an elif please"
                            raise
                    elif deprecated:
                        pass
                    #in bugs case
                    else:
                        print "WIDGET MEASUREMENTS ERROR : widget type is not known --> ", widget
                        raise
            #TO TEST WITH SEVERAL TWD OBJECTS
            #build dynamic dynamic fields
            #samples
            list_twd_s = []
            for k in dic_hiding_samples:
                twd_object = twd.HidingRadioButtonList()
                twd_object.id = k
                dico_mapping = dic_hiding_samples[k]
                options = []
                for key in dico_mapping.keys():
                    options.append(key)
                twd_object.options = options
                twd_object.mapping = dico_mapping
                list_twd_s.append(twd_object)
            list_dynamic_samples = list_dynamic_samples + list_twd_s + list_hiding_samples

            #measurements
            list_twd_m = []
            for k in dic_hiding_meas:
                twd_object = twd.HidingRadioButtonList()
                twd_object.id = k
                dico_mapping = dic_hiding_meas[k]
                options = []
                for key in dico_mapping.keys():
                    options.append(key)
                twd_object.options = options
                twd_object.mapping = dico_mapping
                list_twd_m.append(twd_object)
            list_dynamic_measurements = list_dynamic_measurements + list_twd_m + list_hiding_meas

            list_fields = [
                list_static_samples, list_dynamic_samples,
                list_static_measurements, list_dynamic_measurements
            ]
            return list_fields

        else:
            print "-----forms.py----- Houston, we have a problem : The lab ", lab.name, " doesn't get any attributes -----"
            raise