Beispiel #1
0
class MainForm(FlaskForm):
    """Parent form. Takes 1-20 forms"""
    locations = FieldList(FormField(GeoForm), min_entries=1, max_entries=20)
Beispiel #2
0
class ILLRequestForm(FlaskForm):
    """Form to create an ILL request."""

    document = FormField(ILLRequestDocumentForm)
    request_copy = RadioField(
        label=_('Scope'),
        choices=[(0, _('Loan')), (1, _('Copy'))],
        default=0,
        description=_('Define if the request is for a copy or full document.')
    )
    pages = StringField(
        label=_('Pages')
    )
    source = FormField(
        ILLRequestSourceForm,
        label=_('Found in')
    )
    note = TextAreaField(
        label='Note',
        render_kw={'rows': 5}
    )
    pickup_location = SelectField(
        label=_('Pickup location'),
        choices=[],  # Choices will be loaded dynamically because they should
                     # be given inside app_context
        validate_choice=False,
        description=_('Select the location where this request will be '
                      'operated')
    )

    def validate(self):
        """Add custom validation on the form."""
        form_validate = super().validate()

        # if 'request_copy' is set to True, then 'pages' is required field
        custom_validate = True
        if self.request_copy.data == '1' and len(self.pages.data.strip()) == 0:
            custom_validate = False
            self.pages.errors.append(
                _('As you request a document part, you need to specify '
                  'requested pages')
            )

        return form_validate and custom_validate

    def get_data(self):
        """Return the form as a valid ILLRequest data structure."""
        data = remove_empties_from_dict({
            'document': {
                'title': self.document.title.data,
                'authors': self.document.authors.data,
                'publisher': self.document.publisher.data,
                'year': str(self.document.year.data or ''),
                'identifier': self.document.identifier.data,
                'source': {
                    'journal_title': self.document.source.journal_title.data,
                    'volume': self.document.source.volume.data,
                    'number': self.document.source.number.data,
                }
            },
            'pickup_location': {
                '$ref': get_ref_for_pid('locations', self.pickup_location.data)
            },
            'pages': self.pages.data,
            'found_in': {
                'source': self.source.origin.data,
                'url': self.source.url.data
            }
        })
        if self.note.data:
            data['notes'] = [{
                'type': 'public_note',
                'content': self.note.data
            }]

        # if we put 'copy' in the dict before the dict cleaning and if 'copy'
        # is set to 'No', then it will be removed by `remove_empties_from_dict`
        # So we need to add it after the cleaning
        data['copy'] = self.request_copy.data == 1

        # if user select 'not specified' into the ILL request form, this value
        # must be removed from the dict.
        if data.get('document', {}).get('year') == 'n/a':
            del data['document']['year']

        return data
Beispiel #3
0
class FileEntityForm(EntityEditForm):
    # TODO: positive definite
    size = IntegerField("Size (bytes)", [validators.DataRequired()])
    md5 = StringField(
        "MD5", [validators.Optional(True),
                validators.Length(min=32, max=32)])
    sha1 = StringField(
        "SHA-1",
        [validators.DataRequired(),
         validators.Length(min=40, max=40)])
    sha256 = StringField(
        "SHA-256",
        [validators.Optional(True),
         validators.Length(min=64, max=64)])
    urls = FieldList(FormField(FileUrlForm))
    mimetype = StringField("Mimetype")
    release_ids = FieldList(
        StringField(
            "Release FCID",
            [validators.DataRequired(),
             validators.Length(min=26, max=26)]))

    @staticmethod
    def from_entity(fe: FileEntity) -> "FileEntityForm":
        """
        Initializes form with values from an existing file entity.
        """
        ref = FileEntityForm()
        for simple_attr in FILE_SIMPLE_ATTRS:
            a = getattr(ref, simple_attr)
            a.data = getattr(fe, simple_attr)
        for i, c in enumerate(fe.urls):
            ruf = FileUrlForm()
            ruf.rel = c.rel
            ruf.url = c.url
            ref.urls.append_entry(ruf)
        for r in fe.release_ids:
            ref.release_ids.append_entry(r)
        return ref

    def to_entity(self) -> FileEntity:
        assert self.sha1.data
        entity = FileEntity()
        self.update_entity(entity)
        return entity

    def update_entity(self, fe: FileEntity) -> None:
        """
        Mutates in place, updating fields with values from this form.

        Form must be validated *before* calling this function.
        """
        for simple_attr in FILE_SIMPLE_ATTRS:
            a = getattr(self, simple_attr).data
            # be flexible about hash capitalization
            if simple_attr in ("md5", "sha1", "sha256"):
                a = a.lower()
            # special case blank strings
            if a == "":
                a = None
            setattr(fe, simple_attr, a)
        fe.urls = []
        for u in self.urls:
            fe.urls.append(
                FileUrl(
                    rel=u.rel.data or None,
                    url=u.url.data or None,
                ))
        fe.release_ids = []
        for ri in self.release_ids:
            fe.release_ids.append(ri.data)
        if self.edit_description.data:
            fe.edit_extra = dict(description=self.edit_description.data)
Beispiel #4
0
class EmploymentListForm(Form):
    employmentlist = FieldList(FormField(EmploymentForm))
Beispiel #5
0
class PublicationFormListForm(Form):
    publicationlist = FieldList(FormField(PublicationForm))
Beispiel #6
0
class TranscriptStudentIntlForm(TranscriptStudentForm):
    student_address = FormField(InternationalAddressForm)
Beispiel #7
0
class TranscriptSchoolIntlForm(TranscriptSchoolForm):
    school_address = FormField(InternationalAddressForm)
Beispiel #8
0
class TargetForm(FlaskForm):

    time_min = IntegerField(
        _l('Time min (Minutes)'),
        widget=html5.NumberInput(min=t_min, max=t_max),
        validators=[validators.DataRequired(_l('Minimum time is required.'))])
    time_max = IntegerField(
        _l('Time max (Minutes)'),
        widget=html5.NumberInput(min=t_min, max=t_max),
        validators=[validators.DataRequired(_l('Maximum time is required.'))])
    cost_min = IntegerField(
        _l('Cost min (€)'),
        widget=html5.NumberInput(min=c_min, max=c_max),
        validators=[validators.DataRequired(_l('Minimum cost is required.'))])
    cost_max = IntegerField(
        _l('Cost max (€)'),
        widget=html5.NumberInput(min=c_min, max=c_max),
        validators=[validators.DataRequired(_l('Maximum cost is required.'))])
    reput_average = IntegerField(
        _l('Reput average (?/50)'),
        widget=html5.NumberInput(min=r_min, max=r_max),
        validators=[validators.DataRequired(_l('Reput average is required.'))])
    reput_min = IntegerField(
        _l('Reput min (?/50)'),
        widget=html5.NumberInput(min=r_min, max=r_max),
        validators=[validators.DataRequired(_l('Reput Minimum is required.'))])

    nk_min = IntegerField(_l('Minimum module number (?/5)'),
                          widget=html5.NumberInput(min=n_min_range[0],
                                                   max=n_min_range[1]),
                          validators=[
                              validators.DataRequired(
                                  _l('Minimum module number is required.'))
                          ])

    nk_max = IntegerField(
        _l('Maximum number of modules (?/10)'),
        widget=html5.NumberInput(min=n_max_range[0], max=n_max_range[1]),
        validators=[
            validators.DataRequired(
                _l('Maximum number of modules. is required.'))
        ])

    selectWroles = SelectField(_l('selectWroles'),
                               validators=[validators.DataRequired()])

    ksas = FieldList(FormField(TargetKsaForm))
    submit = SubmitField('Next')

    def validate(self, **kwargs):

        if self.time_min.data < t_min or self.time_min.data > t_max:
            #Volvemos al estado base, porque la modificacion dinamica de la selecion de wk roles
            # se hace en el javascript y este vuelve a un estado base cuando hay una validacion incorrecta
            message_error = f'{"Choose a value greater or equal than Time min: "}{t_min}{"or less or equal than Time max: "}{t_max}'
            self.selectWroles.data = 'Default'
            self.time_min.errors = (super().errors, message_error)
            return False

        if self.time_max.data < t_min or self.time_max.data > t_max:
            message_error = f'{"Choose a value greater or equal than Time min: "}{t_min}{"or less or equal than Time max: "}{t_max}'
            self.selectWroles.data = 'Default'
            self.time_max.errors = (super().errors, message_error)
            return False

        if self.time_max.data < self.time_min.data:
            self.selectWroles.data = 'Default'
            self.time_max.errors = (super().errors,
                                    "Choose a value greater than Time min.")
            return False

        if self.cost_min.data < c_min or self.cost_min.data > c_max:
            message_error = f'{"Choose a value greater or equal than Cost min: "}{c_min}{"or less or equal than Cost max: "}{c_max}'
            self.selectWroles.data = 'Default'
            self.cost_min.errors = (super().errors, message_error)
            return False

        if self.cost_max.data < c_min or self.cost_max.data > c_max:
            message_error = f'{"Choose a value greater or equal than Cost min: "}{c_min}{"or less or equal than Cost max: "}{c_max}'
            self.selectWroles.data = 'Default'
            self.cost_max.errors = (super().errors, message_error)
            return False

        if self.cost_max.data < self.cost_min.data:
            #Volvemos al estado base
            self.selectWroles.data = 'Default'
            self.cost_max.errors = (super().errors,
                                    "Choose a value greater than Cost min.")
            return False


        if (self.reput_min.data < r_min or self.reput_min.data > r_max) or\
            (self.reput_average.data < r_min or self.reput_average.data > r_max):
            #Volvemos al estado base
            self.selectWroles.data = 'Default'
            self.reput_min.errors = (
                super().errors,
                f'{"Choose a value between "}{r_min}{"and "}{r_max}')
            self.reput_average.errors = (
                super().errors,
                f'{"Choose a value between "}{r_min}{"and "}{r_max}')
            return False


        if (self.nk_min.data < n_min_range[0] or self.nk_min.data > n_min_range[1]) or\
            (self.nk_max.data < n_max_range[0] or self.nk_max.data > n_max_range[1]):
            #Volvemos al estado base
            self.selectWroles.data = 'Default'
            self.nk_min.errors = (
                super().errors,
                f'{"Choose a value between "}{n_min_range[0]}{"and "}{n_min_range[1]}'
            )
            self.nk_max.errors = (
                super().errors,
                f'{"Choose a value between "}{n_max_range[0]}{"and "}{n_max_range[1]}'
            )
            return False

        if self.nk_max.data < self.nk_min.data:
            #Volvemos al estado base
            self.selectWroles.data = 'Default'
            self.nk_max.errors = (
                super().errors,
                "Choose a value greater than Minimum module number.")
            return False

        return True
Beispiel #9
0
class Notes(Form):
    """ Multiple notes form for inclusion into admin forms """
    notes = FieldList(FormField(Note))
Beispiel #10
0
class CreatorForm(FlaskForm):
    creators = FieldList(FormField(Person2Form, default={'role': 'A'}), max_entries=3)
    submit = SubmitField('Sumbit')
Beispiel #11
0
class TestForm(FlaskForm):
    ksas = FieldList(FormField(KsaForm))
    # tasks = SelectMultipleField('Tasks',  validators=[
    #                             Validation_MultiSelect])
    tasks = SelectMultipleField(_l('Tasks'))
    submit = SubmitField('Next')
Beispiel #12
0
class NewBlockchainForm(Form):
    efficiency_subform = FormField(EfficiencyForm, 'Efficiency')
    security_subform = FormField(SecurityForm, 'Security')
    reliability_subform = FormField(ReliabilityForm, 'Reliability')
    features_subform = FormField(FeaturesForm, 'Features')
    submit_button = SubmitField('Save')
Beispiel #13
0
class FeaturesForm(Form):
    blockchain_features = FormField(BlockchainFeatures, 'Blockchain features')
    blockchain_archtype = FormField(BlockchainArchType,
                                    'Blockchain architectural type')
Beispiel #14
0
class PollForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])
    description = TextAreaField('Description', validators=[DataRequired()])
    recipes = FieldList(FormField(RecipesSubForm), validators=[])
    submit = SubmitField('Submit Poll')
Beispiel #15
0
class EditSettingsForm(FlaskForm):
    class LightForm(LightSettingsForm):
        class Meta(FlaskForm.Meta):
            csrf = False

    settings = FieldList(FormField(LightForm))
Beispiel #16
0
class AddOfficerForm(Form):
    department = QuerySelectField('Department',
                                  validators=[DataRequired()],
                                  query_factory=dept_choices,
                                  get_label='name')
    first_name = StringField(
        'First name',
        default='',
        validators=[Regexp(r'\w*'), Length(max=50),
                    Optional()])
    last_name = StringField(
        'Last name',
        default='',
        validators=[Regexp(r'\w*'),
                    Length(max=50),
                    DataRequired()])
    middle_initial = StringField(
        'Middle initial',
        default='',
        validators=[Regexp(r'\w*'), Length(max=50),
                    Optional()])
    suffix = SelectField('Suffix',
                         default='',
                         choices=SUFFIX_CHOICES,
                         validators=[AnyOf(allowed_values(SUFFIX_CHOICES))])
    race = SelectField('Race',
                       default='WHITE',
                       choices=RACE_CHOICES,
                       validators=[AnyOf(allowed_values(RACE_CHOICES))])
    gender = SelectField('Gender',
                         default='M',
                         choices=GENDER_CHOICES,
                         validators=[AnyOf(allowed_values(GENDER_CHOICES))])
    star_no = StringField('Badge Number',
                          default='',
                          validators=[Regexp(r'\w*'),
                                      Length(max=50)])
    unique_internal_identifier = StringField(
        'Unique Internal Identifier',
        default='',
        validators=[Regexp(r'\w*'), Length(max=50)])
    job_id = StringField('Job ID')  # Gets rewritten by Javascript
    unit = QuerySelectField('Unit',
                            validators=[Optional()],
                            query_factory=unit_choices,
                            get_label='descrip',
                            allow_blank=True,
                            blank_text=u'None')
    employment_date = DateField('Employment Date', validators=[Optional()])
    birth_year = IntegerField('Birth Year', validators=[Optional()])
    links = FieldList(
        FormField(LinkForm, widget=FormFieldWidget()),
        description='Links to articles about or videos of the incident.',
        min_entries=1,
        widget=BootstrapListWidget())
    notes = FieldList(
        FormField(BaseTextForm, widget=FormFieldWidget()),
        description=
        'This note about the officer will be attributed to your username.',
        min_entries=1,
        widget=BootstrapListWidget())
    descriptions = FieldList(
        FormField(BaseTextForm, widget=FormFieldWidget()),
        description=
        'This description of the officer will be attributed to your username.',
        min_entries=1,
        widget=BootstrapListWidget())
    salaries = FieldList(FormField(SalaryForm, widget=FormFieldWidget()),
                         description='Officer salaries',
                         min_entries=1,
                         widget=BootstrapListWidget())

    submit = SubmitField(label='Add')
Beispiel #17
0
class TranscriptStudentUSForm(TranscriptStudentForm):
    student_address = FormField(USAddressForm)
class GluuGatewayForm(FlaskForm):
    """
    Gluu Gateway Form

    Fields :
        install_gluu_gateway (string|required|default: N)
        postgres (form field form postgresForm)
        kong_namespace (string|required_if install_gluu_gateway = Y|default: gluu-gateway)
        gluu_gateway_ui_namesapce (string|required_if install_gluu_gateway = Y|default: gg-ui)
        kong_database (string|required_if install_gluu_gateway = Y|default: kong)
        kong_pg_user (string|required_if install_gluu_gateway = Y|default: kong)
        kong_pg_password (string|required_if install_gluu_gateway = Y|default: auto generated)
        kong_pg_password_confirmation (string|required_if install_gluu_gateway = Y|default: auto generated)
        gluu_gateway_ui_database (string|required_if install_gluu_gateway = Y|default: konga)
        gluu_gateway_ui_user (string|required_if install_gluu_gateway = Y|default: konga)
        gluu_gateway_ui_pg_password (string|required_if install_gluu_gateway = Y|default: auto generated)
        gluu_gateway_ui_pg_password_confirmation (string|required_if install_gluu_gateway = Y|default: auto generated)
    """
    install_gluu_gateway = RadioField("Install Gluu Gateway Database mode",
                                      choices=[("Y", "Yes"), ("N", "No")],
                                      default="N",
                                      validators=[DataRequired()])
    postgres = FormField(PostgresForm)
    kong_namespace = StringField(
        "Please enter a namespace for Gluu Gateway",
        default="gluu-gateway",
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y")])
    gluu_gateway_ui_namespace = StringField(
        "Please enter a namespace for gluu gateway ui",
        default="gg-ui",
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y")])
    kong_database = StringField(
        "Please enter gluu-gateway postgres database name",
        default="kong",
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y")])
    kong_pg_user = StringField(
        "Please enter a user for gluu-gateway postgres database",
        default="kong",
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y")])
    kong_pg_password = StringField(
        "Kong Postgress Password",
        widget=PasswordInput(hide_value=False),
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y"),
                    password_requirement_check()],
        description="Password is randomly generated with 6 characters contain "
                    "number, uppercase letter, lower case letter and symbol")
    kong_pg_password_confirm = StringField(
        "Kong Postgress Password Confirmation",
        widget=PasswordInput(hide_value=False),
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y"),
                    EqualTo('kong_pg_password_confirm',
                            message='Passwords do not match')])
    gluu_gateway_ui_database = StringField(
        "Please enter gluu-gateway-ui postgres database name",
        default="konga",
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y")])
    gluu_gateway_ui_pg_user = StringField(
        "Please enter a user for gluu-gateway-ui postgres database",
        default="konga",
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y")])
    gluu_gateway_ui_pg_password = StringField(
        "Gluu Gateway UI postgres password",
        widget=PasswordInput(hide_value=False),
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y"),
                    password_requirement_check()],
        description="Password is randomly generated with 6 characters contain "
                    "number, uppercase letter, lower case letter and symbol")
    gluu_gateway_ui_pg_password_confirm = StringField(
        "Gluu Gateway UI postgres password confirmation",
        widget=PasswordInput(hide_value=False),
        validators=[RequiredIfFieldEqualTo("install_gluu_gateway", "Y"),
                    EqualTo('gluu_gateway_ui_pg_password',
                            message='Passwords do not match')])
Beispiel #19
0
class TranscriptSchoolUSForm(TranscriptSchoolForm):
    school_address = FormField(USAddressForm)
Beispiel #20
0
class PartialRefundForm(Form):
    tickets = FieldList(FormField(PartialRefundTicketForm))
    refund = SubmitField('I have refunded these tickets by bank transfer')
    stripe_refund = SubmitField('Refund through Stripe')
Beispiel #21
0
class CreateSomethingCoolReqBody(Form):
    
    robprop = FormField(rob)
Beispiel #22
0
class BiopsyForm(SectionForm):
    def get_summary(self):
        return self.fld_biopsy_tumour_diagnosis.data

    fld_block_serial_number_biopsy = StringField(
        'Block Serial Number', [validators.Length(min=1, max=50)], default=tbd)
    fld_block_location_biopsy = StringField(
        "Block Location ID (Cabinet No.-Drawer No.-Column No.-Front/Back",
        default='To be Filled')
    fld_block_current_location_biopsy = StringField(
        "Current location of block", default=tbd)
    fld_reason_for_biopsy = SelectField(
        "Reason for biopsy", choices=BiopsyDict.biopsy_reason_choice)
    fld_reason_for_biopsy_other = StringField("Give details")

    fld_biopsy_site = SelectField("Site of biopsy",
                                  choices=BiopsyDict.biopsy_site_choice)
    fld_biopsy_site_other = StringField("Other")
    fld_biopsy_custody_pccm = SelectField(
        'Is the biopsy report in PCCM custody?',
        choices=BiopsyDict.biopsy_custody_pccm_choice
    )  #is this the cjoice as mentioned or yes/no?
    fld_biopsy_custody_pccm_other = StringField("Other")
    fld_block_received_pccm_date = DateField(
        "Date when block was placed in the cabinet", default=date.today())
    fld_biopsy_ihc_report_pccm = SelectField(
        "Biopsy IHC report in PCCM custody", choices=CommonDict.yes_no_choice)
    fld_biopsy_block_id = StringField("Biopsy Block ID",
                                      default=tbd)  #major doubt
    fld_biopsy_block_id_other = StringField("other")
    fld_biopsy_no_of_blocks = IntegerField("Number of blocks", default=tbd)
    fld_biopsy_date = DateField("Date of Biopsy", default=date.today())
    fld_biopsy_block_source = SelectField(
        "Reports have been generated from",
        choices=BiopsyDict.biopsy_block_source_choice)
    fld_biopsy_block_source_other = StringField("Give details")
    fld_biopsy_lab_id_sid = StringField("Biopsy Lab ID", default=tbd)
    fld_biopsy_type = SelectField("Biopsy Type",
                                  choices=BiopsyDict.biopsy_type_choice)
    fld_biopsy_type_other = StringField("Other")
    fld_biopsy_diagnosis = TextAreaField(
        'Mention the diagnosis in its fullform.'
        ' Eg: Infiltrating Duct Carcinoma/Invasive Mammary Carcinoma/ DCIS/Fibroadenoma; '
        'Infiltrating Duct Carcinoma + DCIS',
        default=tbd)
    fld_biopsy_diagnosis_comment = StringField(
        "Include descriptive or indicative notes here and not in Diagnosis",
        default=tbd)
    fld_biopsy_tumour_grade = SelectField(
        "Tumour Grade", choices=BiopsyDict.tumour_grade_choice)
    fld_biopsy_tumour_grade_other = StringField("Give details")
    fld_biopsy_lymphovascular_emboli = SelectField(
        'Are Lymphovascular emboli seen?',
        choices=BiopsyDict.lymphovascular_emboli_choice)
    fld_biopsy_lymphovascular_emboli_other = StringField("Other")
    fld_dcis_biopsy = SelectField("Does the biopsy show DCIS",
                                  choices=BiopsyDict.dcis_biopsy_choice)
    fld_dcis_biopsy_other = StringField("Other")
    fld_tumour_er_biopsy = SelectField("Biopsy block ER Status",
                                       choices=BiopsyDict.tumour_er_choice)
    fld_tumour_er_biopsy_other = StringField("Other")
    fld_tumour_er_percent_biopsy = StringField("ER Percent", default=tbd)
    fld_tumour_pr_biopsy = SelectField("Biopsy block PR Status",
                                       choices=BiopsyDict.tumour_pr_choice)
    fld_tumour_pr_biopsy_other = StringField("Other")
    fld_tumour_pr_percent_biopsy = StringField("PR Percent", default=tbd)
    fld_tumour_her2_biopsy = SelectField("Biopsy block HER2 Status",
                                         choices=BiopsyDict.tumour_her2_choice)
    fld_tumour_her2_biopsy_other = StringField("Other")
    fld_tumour_her2_grade_biopsy = StringField("HER2 Grade", default=tbd)
    fld_tumor_biopsy_fish = SelectField(
        "Tumor biopsy FISH", choices=BiopsyDict.tumor_biopsy_fish_choice)
    fld_tumor_biopsy_fish_other = StringField("Other")
    fld_tumour_ki67_biopsy = StringField("Ki67 Percent", default=tbd)
    fld_fnac = SelectField("Lymph Node biopsy FNAC",
                           choices=BiopsyDict.fnac_choice)
    fld_fnac_other = StringField("Other")
    fld_fnac_location = SelectField("FNAC Location",
                                    choices=BiopsyDict.fnac_location_choice)
    fld_fnac_location_other = StringField("Other")
    fld_fnac_diagnosis = SelectField("FNAC Diagnosis",
                                     choices=BiopsyDict.fnac_diagnosis_choice)
    fld_fnac_diagnosis_other = StringField("Other")
    fld_surgery_form_present = SelectField("Is surgery performed?",
                                           choices=CommonDict.yes_no_choice)
    surgery_form = FormField(SurgeryBlockForm)
    submit_button = SubmitField('Submit Form')
Beispiel #23
0
class EducationFormListForm(Form):
    educationlist = FieldList(FormField(EducationForm))
Beispiel #24
0
 class RegisterForm(Form):
     recaptcha = FormField(RegistrationFormRecaptcha, separator='.')
Beispiel #25
0
class PatentFormListForm(Form):
    patentlist = FieldList(FormField(PatentForm))
Beispiel #26
0
class CartForm(FlaskForm):

    quantities = FieldList(FormField(QuantityForm))

    submit = SubmitField(label='Buy cart form')
Beispiel #27
0
class ReleaseEntityForm(EntityEditForm):
    """
    TODO:
    - field types: fatcat id
    - date
    """

    title = StringField("Title", [validators.DataRequired()])
    original_title = StringField("Title in Original Language (if different)")
    work_id = StringField(
        "Work FCID",
        [validators.Optional(True),
         validators.Length(min=26, max=26)])
    container_id = StringField(
        "Container FCID",
        [validators.Optional(True),
         validators.Length(min=26, max=26)])
    release_type = SelectField("Release Type", [validators.DataRequired()],
                               choices=release_type_options,
                               default="")
    release_stage = SelectField(choices=release_stage_options)
    withdrawn_status = SelectField(
        "Withdrawn Status",
        [validators.Optional(True)],
        choices=withdrawn_status_options,
        default="",
    )
    release_date = DateField("Release Date", [validators.Optional(True)])
    release_year = IntegerField("Release Year",
                                [validators.Optional(True), valid_year])
    doi = StringField(
        "DOI",
        [
            validators.Regexp(r"^10\..*\/.*", message="DOI must be valid"),
            validators.Optional(True),
        ],
    )
    wikidata_qid = StringField("Wikidata QID")
    isbn13 = StringField("ISBN-13")
    pmid = StringField("PubMed Id")
    pmcid = StringField("PubMed Central Id")
    # core_id
    # arxiv_id
    # jstor_id
    # oai
    # hdl
    volume = StringField("Volume")
    issue = StringField("Issue")
    pages = StringField("Pages")
    publisher = StringField("Publisher (optional)")
    language = StringField("Language (code)",
                           [validators.Optional(True), valid_2char_ascii])
    license_slug = StringField("License (slug)")
    contribs = FieldList(FormField(ReleaseContribForm))
    # refs
    # abstracts

    @staticmethod
    def from_entity(re: ReleaseEntity) -> "ReleaseEntityForm":
        """
        Initializes form with values from an existing release entity.
        """
        ref = ReleaseEntityForm()
        for simple_attr in RELEASE_SIMPLE_ATTRS:
            a = getattr(ref, simple_attr)
            a.data = getattr(re, simple_attr)
        for extid_attr in RELEASE_EXTID_ATTRS:
            a = getattr(ref, extid_attr)
            a.data = getattr(re.ext_ids, extid_attr)
        for i, c in enumerate(re.contribs):
            rcf = ReleaseContribForm()
            rcf.prev_index = i
            rcf.role = c.role
            rcf.raw_name = c.raw_name
            ref.contribs.append_entry(rcf)
        return ref

    def to_entity(self) -> ReleaseEntity:
        assert self.title.data
        entity = ReleaseEntity(title=self.title.data, ext_ids=ReleaseExtIds())
        self.update_entity(entity)
        return entity

    def update_entity(self, re: ReleaseEntity) -> None:
        """
        Mutates a release entity in place, updating fields with values from
        this form.

        Form must be validated *before* calling this function.
        """
        for simple_attr in RELEASE_SIMPLE_ATTRS:
            a = getattr(self, simple_attr).data
            # special case blank strings
            if a == "":
                a = None
            setattr(re, simple_attr, a)
        for extid_attr in RELEASE_EXTID_ATTRS:
            a = getattr(self, extid_attr).data
            # special case blank strings
            if a == "":
                a = None
            setattr(re.ext_ids, extid_attr, a)
        if self.release_date.data:
            re.release_year = self.release_date.data.year
        # bunch of complexity here to preserve old contrib metadata (eg,
        # affiliation and extra) not included in current forms
        # TODO: this may be broken; either way needs tests
        if re.contribs:
            old_contribs = re.contribs.copy()
            re.contribs = []
        else:
            old_contribs = []
            re.contribs = []
        for c in self.contribs:
            if c.prev_index.data not in ("", None):
                rc = old_contribs[int(c.prev_index.data)]
                rc.role = c.role.data or None
                rc.raw_name = c.raw_name.data or None
            else:
                rc = ReleaseContrib(
                    role=c.role.data or None,
                    raw_name=c.raw_name.data or None,
                )
            re.contribs.append(rc)
        if self.edit_description.data:
            re.edit_extra = dict(description=self.edit_description.data)
Beispiel #28
0
class RefundForm(Form):
    purchases = FieldList(FormField(RefundPurchaseForm))
    refund = SubmitField("I have refunded these purchases by bank transfer")
    stripe_refund = SubmitField("Refund through Stripe")
Beispiel #29
0
class EditVideosForm(FlaskForm):
	videos = FieldList(FormField(VideoForm))
	submit = SubmitField('Update')
Beispiel #30
0
class ClientList(Form):
    client_list = FieldList(FormField(ClientForm))