Example #1
0
class InstitutionInlineForm(INSPIREForm):
    """Institution inline form."""

    rank_options = [("rank", _("Rank")), ("SENIOR", _("Senior (permanent)")),
                    ("JUNIOR", _("Junior (leads to Senior)")),
                    ("STAFF", _("Staff (non-research)")),
                    ("VISITOR", _("Visitor")), ("PD", _("PostDoc")),
                    ("PHD", _("PhD")), ("MAS", _("Master")),
                    ("UG", _("Undergrad"))]

    name = fields.StringField(
        widget_classes='form-control',
        widget=ColumnInput(class_="col-md-6"),
        autocomplete='affiliation',
        placeholder=_("Institution. Type for suggestions"),
    )

    rank = fields.SelectField(
        choices=rank_options,
        default="rank",
        widget=ColumnSelect(class_="col-md-6"),
        widget_classes='form-control',
        validators=[validators.DataRequired()],
    )

    start_year = fields.StringField(
        placeholder=_('Start Year'),
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6 col-margin-top">%(field)s</div>'),
        validators=[
            RegexpStopValidator(
                "^(\d{4})?$",
                message="{} is not a valid year. Please use <i>yyyy</i> format."
            )
        ],
        widget_classes="datepicker form-control")

    end_year = fields.StringField(
        placeholder=_('End Year'),
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6 col-margin-top">%(field)s</div>'),
        validators=[
            RegexpStopValidator(
                "^(\d{4})?$",
                message="{} is not a valid year. Please use <i>yyyy</i> format."
            )
        ],
        widget_classes="datepicker form-control")

    current = fields.BooleanField(widget=currentCheckboxWidget)

    email = fields.HiddenField()

    old_email = fields.HiddenField()
Example #2
0
class ExperimentsInlineForm(INSPIREForm):

    """Experiments inline form."""

    name = fields.StringField(
        placeholder="Experiment. Type for suggestions",
        label='Experiment',
        widget=ColumnInput(class_="col-md-6"),
        widget_classes="form-control",
        autocomplete="experiment"
    )

    start_year = fields.StringField(
        placeholder='Start Year',
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6">%(field)s</div>',
        ),
        validators=[
            LessThan('end_year', message='Start year should be earlier than End year'),
            RegexpStopValidator(
                r'^(\d{4})?$',
                message='{} is not a valid year. Please use <i>yyyy</i> format.',
            ),
        ],
        widget_classes="form-control"
    )

    end_year = fields.StringField(
        placeholder='End Year',
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6 col-margin-top">%(field)s</div>'
        ),
        validators=[
            RegexpStopValidator(
                r'^(\d{4})?$',
                message='{} is not a valid year. Please use <i>yyyy</i> format.',
            ),
        ],
        widget_classes="form-control"
    )

    current = fields.BooleanField(
        widget=currentCheckboxWidget
    )
Example #3
0
def test_regexp_stop_validator_raises_on_strings_that_dont_match_the_regexp():
    field = MockField(u'THIS-ORCID-IS-NOT-VALID')
    regexp_stop_validator = RegexpStopValidator(
        u'\d{4}-\d{4}-\d{4}-\d{3}[\dX]')

    with pytest.raises(StopValidation):
        regexp_stop_validator(None, field)
Example #4
0
def test_regexp_stop_validator_raises_with_custom_message():
    field = MockField(u'1993-02-02')
    regexp_stop_validator = RegexpStopValidator(
        u'^(\d{4})?$', message=u'{} is not a valid year.')

    with pytest.raises(StopValidation) as excinfo:
        regexp_stop_validator(None, field)
    assert u'1993-02-02 is not a valid year' in str(excinfo.value)
Example #5
0
class ExperimentsInlineForm(INSPIREForm):

    """Experiments inline form."""

    name = fields.StringField(
        placeholder=_("Experiment. Type for suggestions"),
        label=_('Experiment'),
        widget=ColumnInput(class_="col-md-6"),
        widget_classes="form-control",
        autocomplete="experiment"
    )

    start_year = fields.StringField(
        placeholder=_('Start Year'),
        description=u'Format: YYYY.',
        widget=WrappedInput(wrapped_widget=TextInput(),
                            wrapper='<div class="col-md-6">%(field)s</div>'
                            ),
        validators=[RegexpStopValidator(
            "^(\d{4})?$",
            message="{} is not a valid year. Please use <i>yyyy</i> format."
        )],
        widget_classes="datepicker form-control"
    )

    end_year = fields.StringField(
        placeholder=_('End Year'),
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6 col-margin-top">%(field)s</div>'
        ),
        validators=[RegexpStopValidator(
            "^(\d{4})?$",
            message="{} is not a valid year. Please use <i>yyyy</i> format."
        )],
        widget_classes="datepicker form-control"
    )

    status = fields.BooleanField(
        widget=currentCheckboxWidget
    )
Example #6
0
def test_regexp_stop_validator_accepts_strings_that_match_the_regexp():
    field = MockField(u'0000-0003-1032-3957')
    regexp_stop_validator = RegexpStopValidator(
        u'\d{4}-\d{4}-\d{4}-\d{3}[\dX]')

    assert regexp_stop_validator(None, field) is not None
Example #7
0
class InstitutionInlineForm(INSPIREForm):
    """Institution inline form."""

    rank_options = [
        ("rank", "Rank"),
        ("SENIOR", "Senior (permanent)"),
        ("JUNIOR", "Junior (leads to Senior)"),
        ("STAFF", "Staff (non-research)"),
        ("VISITOR", "Visitor"),
        ("PD", "PostDoc"),
        ("PHD", "PhD"),
        ("MASTER", "Master"),
        ("UNDERGRADUATE", "Undergrad"),
        ("OTHER", "Other"),
    ]

    name = fields.StringField(
        widget_classes='form-control',
        widget=ColumnInput(class_="col-md-6"),
        autocomplete='affiliation',
        placeholder="Institution. Type for suggestions",
    )

    rank = fields.SelectField(
        choices=rank_options,
        default="rank",
        widget=ColumnSelect(class_="col-md-6"),
        widget_classes='form-control',
        validators=[validators.DataRequired()],
    )

    start_year = fields.StringField(
        placeholder='Start Year',
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6 col-margin-top">%(field)s</div>'),
        validators=[
            LessThan('end_year',
                     message='Start year should be earlier than End year'),
            RegexpStopValidator(
                r'^(\d{4})?$',
                message=
                '{} is not a valid year. Please use <i>yyyy</i> format.',
            ),
        ],
        widget_classes="form-control")

    end_year = fields.StringField(
        placeholder='End Year',
        description=u'Format: YYYY.',
        widget=WrappedInput(
            wrapped_widget=TextInput(),
            wrapper='<div class="col-md-6 col-margin-top">%(field)s</div>'),
        validators=[
            RegexpStopValidator(
                "^(\d{4})?$",
                message="{} is not a valid year. Please use <i>yyyy</i> format."
            )
        ],
        widget_classes="form-control")

    current = fields.BooleanField(widget=currentCheckboxWidget)

    emails = fields.FieldList(fields.HiddenField(label=''),
                              widget_classes='hidden-list')

    old_emails = fields.FieldList(fields.HiddenField(label=''),
                                  widget_classes='hidden-list')
Example #8
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()
Example #9
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"