Пример #1
0
class AuthorUpdateForm(INSPIREForm):
    """Author update form."""

    bai = fields.StringField(
        label='Bai',
        description=u'e.g. M.Santos.1',
        widget=HiddenInput(),
        widget_classes="form-control",
        validators=[
            validators.Optional(),
            RegexpStopValidator(
                "(\\w+\\.)+\\d+",
                message="A valid Bai is in the form of 'M.Santos.1'.",
            )
        ])

    inspireid = fields.StringField(
        label='Inspireid',
        description=u'e.g. INSPIRE-0000000',
        widget=HiddenInput(),
        widget_classes="form-control",
        validators=[
            validators.Optional(),
            RegexpStopValidator(
                "INSPIRE-\\d{8}",
                message=
                "A valid Inspireid is in the form of 'INSPIRE-0000000'.",
            )
        ])

    # Hidden field to hold record id information
    control_number = fields.IntegerField(
        widget=HiddenInput(),
        validators=[validators.Optional()],
    )

    given_names = fields.StringField(label='Given Names',
                                     description=u'e.g. Diego',
                                     validators=[validators.DataRequired()],
                                     widget_classes="form-control")

    family_name = fields.StringField(label='Family Name',
                                     description=u'e.g. Martínez Santos',
                                     widget_classes="form-control")

    display_name = fields.StringField(
        label='Display Name',
        description=
        u'How should the author be addressed throughout the site? e.g. Diego Martínez',
        validators=[validators.DataRequired()],
        widget_classes="form-control")

    native_name = fields.StringField(
        label='Native Name',
        description=u'For non-Latin names e.g. 麦迪娜 or Эдгар Бугаев',
        widget_classes="form-control")

    public_emails = fields.DynamicFieldList(
        fields.FormField(EmailInlineForm,
                         widget=ExtendedListWidget(
                             item_widget=ItemWidget(),
                             html_tag='div',
                         ),
                         widget_classes="col-xs-10"),
        description=
        u"This emails will be displayed online in the INSPIRE Author Profile.",
        label='Public emails',
        add_label='Add another email',
        min_entries=1,
        widget=DynamicUnsortedNonRemoveWidget(),
        widget_classes="ui-disable-sort")

    orcid = fields.StringField(
        label=
        'ORCID <img src="/static/images/orcid_icon_24.png" style="height:20px">',
        widget_classes="form-control",
        description=
        u"""ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at <a href="http://orcid.org" tabIndex="-1" target="_blank">orcid.org</a>""",
        widget=WrappedInput(wrapper="""
        <div class="input-group">
        <span class="input-group-addon" id="sizing-addon2">orcid.org/</span>
        %(field)s
        </div>
        """),
        placeholder="0000-0000-0000-0000",
        validators=[
            validators.Optional(),
            RegexpStopValidator(
                "\d{4}-\d{4}-\d{4}-\d{3}[\dX]",
                message=
                "A valid ORCID iD consists of 16 digits separated by dashes.",
            ), ORCIDValidator, duplicated_orcid_validator
        ])

    status_options = [("active", "Active"), ("retired", "Retired"),
                      ("departed", "Departed"), ("deceased", "Deceased")]

    status = fields.SelectField(
        label='Status',
        choices=status_options,
        default="active",
        validators=[validators.DataRequired()],
        widget_classes='form-control',
    )

    blog_url = fields.StringField(
        label='Blog',
        placeholder='http://www.example.com',
        icon="fa fa-wordpress",
        widget_classes="form-control",
    )

    twitter_url = fields.StringField(
        label='Twitter',
        placeholder='https://twitter.com/inspirehep',
        icon="fa fa-twitter",
        widget_classes="form-control",
    )

    linkedin_url = fields.StringField(
        label='Linkedin',
        placeholder=
        'https://www.linkedin.com/pub/john-francis-lampen/16/750/778',
        icon="fa fa-linkedin-square",
        widget_classes="form-control",
    )

    websites = fields.DynamicFieldList(fields.FormField(
        WebpageInlineForm,
        widget=ExtendedListWidget(
            item_widget=ItemWidget(),
            html_tag='div',
        ),
    ),
                                       add_label='Add another website',
                                       min_entries=1,
                                       widget_classes='ui-disable-sort',
                                       icon="fa fa-globe",
                                       widget=DynamicUnsortedWidget())

    arxiv_categories_schema = load_schema('elements/arxiv_categories.json')
    research_field_options = [
        (val, val) for val in arxiv_categories_schema['enum']
        if '.' not in val or val in ('physics.ins-det', 'physics.acc-ph',
                                     'physics.data-an')
    ]

    research_field = fields.SelectMultipleField(
        label='Field of Research',
        choices=research_field_options,
        widget_classes="form-control",
        filters=[clean_empty_list],
        validators=[validators.DataRequired()])

    institution_history = fields.DynamicFieldList(
        fields.FormField(InstitutionInlineForm,
                         widget=ExtendedListWidget(
                             item_widget=ItemWidget(),
                             html_tag='div',
                         ),
                         widget_classes="col-xs-10"),
        label='Institution History',
        add_label='Add another institution',
        min_entries=1,
        widget=DynamicUnsortedWidget(),
        widget_classes="ui-disable-sort")

    advisors = fields.DynamicFieldList(fields.FormField(
        AdvisorsInlineForm,
        widget=ExtendedListWidget(
            item_widget=ItemWidget(),
            html_tag='div',
        ),
    ),
                                       label='Advisors',
                                       add_label='Add another advisor',
                                       min_entries=1,
                                       widget=DynamicUnsortedWidget(),
                                       widget_classes="ui-disable-sort")

    experiments = fields.DynamicFieldList(fields.FormField(
        ExperimentsInlineForm,
        widget=ExtendedListWidget(
            item_widget=ItemWidget(),
            html_tag='div',
        ),
        widget_classes="col-xs-10"),
                                          label='Experiment History',
                                          add_label='Add another experiment',
                                          min_entries=1,
                                          widget=DynamicUnsortedWidget(),
                                          widget_classes="ui-disable-sort")

    extra_comments = fields.TextAreaField(
        label='Comments',
        description=
        u'Send us any comments you might have. They will not be visible.',
        widget_classes="form-control")

    #
    # Form Configuration
    #
    _title = "Update author details"

    # Group fields in categories

    groups = [
        ('Personal Information', [
            'given_names', 'family_name', 'display_name', 'native_name',
            'email', 'public_emails', 'status', 'orcid', 'bai', 'inspireid'
        ], {
            "icon": "fa fa-user"
        }),
        ('Personal Websites', [
            'websites', 'linkedin_url', 'blog_url', 'twitter_url',
            "twitter_hidden"
        ], {
            "icon": "fa fa-globe"
        }),
        ('Career Information',
         ['research_field', 'institution_history', 'experiments',
          'advisors'], {
              "icon": "fa fa-university"
          }), ('Comments', ['extra_comments'], {
              "icon": "fa fa-comments"
          })
    ]

    def __init__(self, *args, **kwargs):
        """Constructor."""
        super(AuthorUpdateForm, self).__init__(*args, **kwargs)
        is_update = kwargs.pop('is_update', False)
        is_review = kwargs.pop('is_review', False)
        if is_update:
            self.orcid.widget = HiddenInput()
            self.orcid.validators = []
        if is_review:
            self.bai.widget = TextInput()
            self.bai.flags = Flags()
            self.inspireid.widget = TextInput()
            self.inspireid.flags = Flags()
Пример #2
0
class AuthorUpdateForm(INSPIREForm):
    """Author update form."""

    # Hidden field to hold author id information
    bai = fields.StringField(widget=HiddenInput())

    inspireid = fields.StringField(widget=HiddenInput())

    # Hidden field to hold record id information
    recid = fields.IntegerField(
        widget=HiddenInput(),
        validators=[validators.Optional()],
    )

    given_names = fields.StringField(label=_('Given Names'),
                                     description=u'e.g. Diego',
                                     validators=[validators.DataRequired()],
                                     widget_classes="form-control")

    family_name = fields.StringField(label=_('Family Name'),
                                     description=u'e.g. Martínez Santos',
                                     widget_classes="form-control")

    display_name = fields.StringField(
        label=_('Display Name'),
        description=
        u'How should the author be addressed throughout the site? e.g. Diego Martínez',
        validators=[validators.DataRequired()],
        widget_classes="form-control")

    native_name = fields.StringField(
        label=_('Native Name'),
        description=u'For non-Latin names e.g. 麦迪娜 or Эдгар Бугаев',
        widget_classes="form-control")

    public_email = fields.StringField(
        label=_('Public Email'),
        description=
        u"This email will be displayed online in the INSPIRE Author Profile.",
        widget_classes="form-control",
        validators=[validators.Optional(),
                    validators.Email()],
    )

    orcid = fields.StringField(
        label=
        'ORCID <img src="/static/images/orcid_icon_24.png" style="height:20px">',
        widget_classes="form-control",
        description=
        u"""ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at <a href="http://orcid.org" tabIndex="-1" target="_blank">orcid.org</a>""",
        widget=WrappedInput(wrapper="""
        <div class="input-group">
        <span class="input-group-addon" id="sizing-addon2">orcid.org/</span>
        %(field)s
        </div>
        """),
        placeholder="0000-0000-0000-0000",
        validators=[
            validators.Optional(),
            RegexpStopValidator(
                "\d{4}-\d{4}-\d{4}-\d{3}[\dX]",
                message=
                "A valid ORCID iD consists of 16 digits separated by dashes.",
            ), ORCIDValidator
        ])

    status_options = [("active", _("Active")), ("retired", _("Retired")),
                      ("departed", _("Departed")), ("deceased", _("Deceased"))]

    status = fields.SelectField(
        label='Status',
        choices=status_options,
        default="active",
        validators=[validators.DataRequired()],
        widget_classes='form-control',
    )

    blog_url = fields.StringField(
        label=_('Blog'),
        placeholder='http://www.example.com',
        icon="fa fa-wordpress",
        widget_classes="form-control",
    )

    twitter_url = fields.StringField(
        label=_('Twitter'),
        placeholder='https://twitter.com/inspirehep',
        icon="fa fa-twitter",
        widget_classes="form-control",
    )

    linkedin_url = fields.StringField(
        label=_('Linkedin'),
        placeholder=
        'https://www.linkedin.com/pub/john-francis-lampen/16/750/778',
        icon="fa fa-linkedin-square",
        widget_classes="form-control",
    )

    websites = fields.DynamicFieldList(fields.FormField(
        WebpageInlineForm,
        widget=ExtendedListWidget(
            item_widget=ItemWidget(),
            html_tag='div',
        ),
    ),
                                       add_label=_('Add another website'),
                                       min_entries=1,
                                       widget_classes='ui-disable-sort',
                                       icon="fa fa-globe",
                                       widget=DynamicUnsortedWidget())

    research_field_options = [
        ("ACC-PHYS", _("acc-phys")), ("ASTRO-PH", _("astro-ph")),
        ("ATOM-PH", _("atom-ph")), ("CHAO-DYN", _("chao-dyn")),
        ("CLIMATE", _("climate")), ("COMP", _("comp")),
        ("COND-MAT", _("cond-mat")), ("GENL-TH", _("genl-th")),
        ("GR-QC", _("gr-qc")), ("HEP-EX", _("hep-ex")),
        ("HEP-LAT", _("hep-lat")), ("HEP-PH", _("hep-ph")),
        ("HEP-TH", _("hep-th")), ("INSTR", _("instr")),
        ("LIBRARIAN", _("librarian")), ("MATH", _("math")),
        ("MATH-PH", _("math-ph")), ("MED-PHYS", _("med-phys")),
        ("NLIN", _("nlin")), ("NUCL-EX", _("nucl-ex")),
        ("NUCL-TH", _("nucl-th")), ("PHYSICS", _("physics")),
        ("PLASMA-PHYS", _("plasma-phys")), ("Q-BIO", _("q-bio")),
        ("QUANT-PH", _("quant-ph")), ("SSRL", _("ssrl")), ("OTHER", _("other"))
    ]

    research_field = fields.SelectMultipleField(
        label=_('Field of Research'),
        choices=research_field_options,
        widget_classes="form-control",
        filters=[clean_empty_list],
        validators=[validators.DataRequired()])

    institution_history = fields.DynamicFieldList(
        fields.FormField(InstitutionInlineForm,
                         widget=ExtendedListWidget(
                             item_widget=ItemWidget(),
                             html_tag='div',
                         ),
                         widget_classes="col-xs-10"),
        label='Institution History',
        add_label='Add another institution',
        min_entries=1,
        widget=DynamicUnsortedWidget(),
        widget_classes="ui-disable-sort")

    advisors = fields.DynamicFieldList(fields.FormField(
        AdvisorsInlineForm,
        widget=ExtendedListWidget(
            item_widget=ItemWidget(),
            html_tag='div',
        ),
    ),
                                       label='Advisors',
                                       add_label='Add another advisor',
                                       min_entries=1,
                                       widget=DynamicUnsortedWidget(),
                                       widget_classes="ui-disable-sort")

    experiments = fields.DynamicFieldList(fields.FormField(
        ExperimentsInlineForm,
        widget=ExtendedListWidget(
            item_widget=ItemWidget(),
            html_tag='div',
        ),
        widget_classes="col-xs-10"),
                                          label='Experiment History',
                                          add_label='Add another experiment',
                                          min_entries=1,
                                          widget=DynamicUnsortedWidget(),
                                          widget_classes="ui-disable-sort")

    comments = fields.TextAreaField(
        label=_('Comments'),
        description=
        u'Send us any comments you might have. They will not be visible.',
        widget_classes="form-control")

    #
    # Form Configuration
    #
    _title = _("Update author details")

    # Group fields in categories

    groups = [
        ('Personal Information', [
            'given_names', 'family_name', 'display_name', 'native_name',
            'email', 'public_email', 'status', 'orcid', 'bai', 'inspireid'
        ], {
            "icon": "fa fa-user"
        }),
        ('Personal Websites', [
            'websites', 'linkedin_url', 'blog_url', 'twitter_url',
            "twitter_hidden"
        ], {
            "icon": "fa fa-globe"
        }),
        ('Career Information',
         ['research_field', 'institution_history', 'experiments',
          'advisors'], {
              "icon": "fa fa-university"
          }), ('Comments', ['comments'], {
              "icon": "fa fa-comments"
          })
    ]

    def __init__(self, is_review=False, *args, **kwargs):
        """Constructor."""
        super(AuthorUpdateForm, self).__init__(*args, **kwargs)
        if is_review:
            self.bai.widget = TextInput()
            self.bai.widget_classes = "form-control"
            self.inspireid.widget = TextInput()
            self.inspireid.widget_classes = "form-control"