예제 #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"
예제 #3
0
class LiteratureForm(INSPIREForm):
    """Literature form fields."""

    doi = fields.DOIField(
        label=_('DOI'),
        processors=[],
        export_key='doi',
        description='e.g. 10.1086/305772 or doi:10.1086/305772',
        placeholder='',
        validators=[
            DOISyntaxValidator(
                "The provided DOI is invalid - it should look similar to '10.1086/305772'."
            ), duplicated_doi_validator
        ],
    )

    arxiv_id = ArXivField(
        label=_('arXiv ID'),
        export_key="arxiv_id",
        validators=[arxiv_syntax_validation, duplicated_arxiv_id_validator],
    )

    categories_arXiv = fields.TextField(
        export_key='categories',
        widget=HiddenInput(),
    )

    # isbn = ISBNField(
    #     label=_('ISBN'),
    #     widget_classes='form-control',
    # )

    import_buttons = fields.SubmitField(label=_(' '),
                                        widget=import_buttons_widget)

    types_of_doc = [("article", _("Article/Conference paper")),
                    ("thesis", _("Thesis"))]

    # ("chapter", _("Book Chapter")),
    # ("book", _("Book")),
    # ("proceedings", _("Proceedings"))]

    type_of_doc = fields.SelectField(
        label='Type of Document',
        choices=types_of_doc,
        default="article",
        # widget=radiochoice_buttons,
        widget_classes='form-control',
        validators=[validators.DataRequired()],
    )

    title = fields.TitleField(
        label=_('Title'),
        widget_classes="form-control",
        validators=[validators.DataRequired()],
        export_key='title',
    )

    title_crossref = fields.TitleField(
        export_key='title_crossref',
        widget=HiddenInput(),
    )

    title_arXiv = fields.TitleField(
        export_key='title_arXiv',
        widget=HiddenInput(),
    )

    title_translation = fields.TitleField(
        label=_('Translated Title'),
        description='Original title translated to english language.',
        widget_classes="form-control",
        export_key='title_translation',
    )

    authors = fields.DynamicFieldList(
        fields.FormField(
            AuthorInlineForm,
            widget=ExtendedListWidget(
                item_widget=ItemWidget(),
                html_tag='div',
            ),
        ),
        label='Authors',
        add_label='Add another author',
        min_entries=1,
        widget_classes='',
        export_key='authors',
        validators=[AuthorsValidation],
    )

    collaboration = fields.TextField(label=_('Collaboration'),
                                     export_key="collaboration",
                                     widget_classes="form-control" +
                                     ARTICLE_CLASS)

    experiment = fields.TextField(
        placeholder=_("Start typing for suggestions"),
        export_key="experiment",
        label=_('Experiment'),
        widget_classes="form-control",
        autocomplete="experiment")

    subject = fields.SelectMultipleField(
        label=_('Subject'),
        widget_classes="form-control",
        export_key='subject_term',
        filters=[clean_empty_list],
        validators=[validators.DataRequired()])

    abstract = fields.TextAreaField(
        label=_('Abstract'),
        default='',
        widget_classes="form-control",
        export_key='abstract',
    )

    languages = [("en", _("English")), ("rus", _("Russian")),
                 ("ger", _("German")), ("fre", _("French")),
                 ("ita", _("Italian")), ("spa", _("Spanish")),
                 ("chi", _("Chinese")), ("por", _("Portuguese")),
                 ("oth", _("Other"))]

    language = fields.LanguageField(label=_("Language"),
                                    export_key="language",
                                    choices=languages)

    other_language = fields.TextField(
        label=_("Other Language"),
        export_key="other_language",
        widget_classes="form-control",
        description="What is the language of the publication?")

    conf_name = fields.TextField(
        placeholder=_("Start typing for suggestions"),
        label=_('Conference Information'),
        description=_('Conference name, acronym, place, date'),
        widget_classes="form-control" + ARTICLE_CLASS,
        autocomplete='conference')

    conference_id = fields.TextField(
        export_key='conference_id',
        widget=HiddenInput(),
    )

    license_url = fields.TextField(
        label=_('License URL'),
        export_key='license_url',
        widget=HiddenInput(),
    )

    report_numbers = fields.DynamicFieldList(
        fields.FormField(
            ReportNumberInlineForm,
            widget=ExtendedListWidget(
                item_widget=ItemWidget(),
                html_tag='div',
            ),
        ),
        add_label=_('Add another report number'),
        min_entries=1,
        widget_classes='',
        widget=UnsortedDynamicListWidget(),
    )

    # ==============
    # Thesis related
    # ==============
    supervisors = fields.DynamicFieldList(
        fields.FormField(
            AuthorInlineForm,
            widget=ExtendedListWidget(
                item_widget=ItemWidget(),
                html_tag='div',
            ),
        ),
        label=_('Supervisors'),
        add_label=_('Add another supervisor'),
        min_entries=1,
        widget_classes=THESIS_CLASS,
    )

    thesis_date = fields.TextField(
        label=_('Date of Submission'),
        description='Format: YYYY-MM-DD, YYYY-MM or YYYY.',
        validators=[date_validator],
        widget=defensedate_widget,
    )

    defense_date = fields.TextField(
        label=_('Date of Defense'),
        description='Format: YYYY-MM-DD, YYYY-MM or YYYY.',
        validators=[date_validator],
        widget=defensedate_widget,
    )

    degree_type = fields.SelectField(
        label=_('Degree Type'),
        widget_classes="form-control" + THESIS_CLASS,
    )

    institution = fields.TextField(
        autocomplete='affiliation',
        placeholder='Start typing for suggestions',
        label=_('Institution'),
        widget_classes="form-control" + THESIS_CLASS,
    )

    # license = fields.SelectField(
    #     label=_('License'),
    #     default='',
    #     widget_classes="form-control" + THESIS_CLASS,
    # )

    # ============
    # Journal Info
    # ============
    journal_title = fields.TextField(
        placeholder=_("Start typing for suggestions"),
        label=_('Journal Title'),
        widget_classes="form-control" + ARTICLE_CLASS,
        autocomplete='journal')

    page_range_article_id = fields.TextField(label=_('Page Range/Article ID'),
                                             description=_('e.g. 1-100'),
                                             widget_classes="form-control" +
                                             ARTICLE_CLASS)

    volume = fields.TextField(label=_('Volume'),
                              widget_classes="form-control" + ARTICLE_CLASS)

    year = fields.TextField(label=_('Year'),
                            widget_classes="form-control" + ARTICLE_CLASS)

    issue = fields.TextField(label=_('Issue'),
                             widget_classes="form-control" + ARTICLE_CLASS)

    nonpublic_note = fields.TextAreaField(
        label=_('Proceedings'),
        description=
        'Editors, title of proceedings, publisher, year of publication, page range, URL',
        widget=wrap_nonpublic_note,
        widget_classes="form-control" + ARTICLE_CLASS)

    note = fields.TextAreaField(
        widget=HiddenInput(),
        export_key='note',
    )

    # ============
    # References
    # ============

    references = fields.TextAreaField(
        label=_('References'),
        description='Please paste the references in plain text',
        widget_classes="form-control")

    # ====================
    # Preprint Information
    # ====================
    preprint_created = fields.TextField(
        widget=HiddenInput(),
        export_key='preprint_created',
    )

    # ====================
    # Fulltext Information
    # ====================
    # file_field = fields.FileUploadField(
    #     label="",
    #     widget=plupload_widget,
    #     widget_classes="form-control" + THESIS_CLASS,
    #     export_key=False
    # )

    # url = fields.DynamicFieldList(
    #     fields.FormField(
    #         UrlInlineForm,
    #         widget=ExtendedListWidget(
    #             item_widget=ItemWidget(),
    #             html_tag='div',
    #         ),
    #     ),
    #     #validators=[validators.URL(), validators.Optional, ],
    #     label=_('If available, please provide us with an accessible URL for the pdf'),
    #     add_label=_('Add another url'),
    #     min_entries=1,
    #     export_key='url',
    #     widget_classes='',
    # )

    url = fields.TextField(
        label=_('Link to PDF'),
        description=_('Where can we find a PDF to check the references?'),
        placeholder='http://www.example.com/document.pdf',
        validators=[pdf_validator],
        widget_classes="form-control",
    )

    additional_url = fields.TextField(
        label=_('Link to additional information (e.g. abstract)'),
        description=_('Which page should we link from INSPIRE?'),
        placeholder='http://www.example.com/splash-page.html',
        # validators=[pdf_validator],
        widget_classes="form-control",
    )

    # ====================
    # Extra comments
    # ====================

    extra_comments = fields.TextAreaField(
        label=_('Comments'),
        description='Any extra comments related to your submission',
        widget_classes="form-control")

    # ok_to_upload = fields.BooleanField(
    #     label="",
    #     default=False,
    #     widget=CheckboxButton(msg=_('I confirm I have read the License Agreement')),
    #     validators=[required_if_files('file_field',
    #                                   message=_("Please, check this box to upload material.")
    #                                   ),
    #                 ]
    #     )

    #
    # Form Configuration
    #
    _title = _("Suggest content")

    # Group fields in categories

    groups = [
        ('Import information', ['arxiv_id', 'doi', 'import_buttons']),
        ('Document Type', [
            'type_of_doc',
        ]),
        ('Links', ['url', 'additional_url']),
        ('Basic Information', [
            'title', 'title_arXiv', 'categories_arXiv', 'language',
            'other_language', 'title_translation', 'subject', 'authors',
            'collaboration', 'experiment', 'abstract', 'page_nr',
            'report_numbers'
        ]),
        ('Thesis Information', [
            'supervisors', 'thesis_date', 'defense_date', 'degree_type',
            'institution', 'license_url'
        ]),
        # ('Licenses and copyright',
        #     ['license', 'license_url'], {'classes': 'collapse'}),
        ('Journal Information',
         ['journal_title', 'volume', 'issue', 'year',
          'page_range_article_id']),
        ('Conference Information', ['conf_name', 'conference_id'], {
            'classes': 'collapse'
        }),
        ('Proceedings Information (if not published in a journal)',
         ['nonpublic_note'], {
             'classes': 'collapse'
         }),
        ('References', ['references'], {
            'classes': 'collapse'
        }),
        # ('Upload files',
        #     ['file_field', 'ok_to_upload']),
        ('Additional comments', ['extra_comments'], {
            'classes': 'collapse'
        }),
    ]

    field_sizes = {
        'type_of_doc': 'col-xs-12 col-md-3',
        'wrap_nonpublic_note': 'col-md-9',
        'defense_date': 'col-xs-12 col-md-4',
        'thesis_date': 'col-xs-12 col-md-4',
        'degree_type': 'col-xs-12 col-md-3',
    }

    def __init__(self, *args, **kwargs):
        """Constructor."""
        super(LiteratureForm, self).__init__(*args, **kwargs)
        # from invenio_knowledge.api import get_kb_mappings
        self.subject.choices = [('dummy', 'dummy')]
        self.degree_type.choices = [('dummy', 'dummy')]
예제 #4
0
class LiteratureForm(INSPIREForm):

    """Literature form fields."""

    doi = fields.DOIField(
        label='DOI',
        processors=[],
        export_key='doi',
        description='e.g. 10.1086/305772 or doi:10.1086/305772',
        placeholder='',
        validators=[DOISyntaxValidator("The provided DOI is invalid - it should look similar to '10.1086/305772'."),
                    duplicated_doi_validator],
    )

    arxiv_id = fields.ArXivField(
        label='arXiv ID',
        export_key="arxiv_id",
        validators=[arxiv_syntax_validation, duplicated_arxiv_id_validator],
    )

    categories_arXiv = fields.TextField(
        widget=HiddenInput(),
        export_key='categories',
    )

    import_buttons = fields.SubmitField(
        label=' ',
        widget=import_buttons_widget
    )

    types_of_doc = [("article", "Article/Conference paper"),
                    ("thesis", "Thesis"),
                    ('book', 'Book'),
                    ('chapter', 'Book chapter')]
    # ("proceedings", _("Proceedings"))

    type_of_doc = fields.SelectField(
        label='Type of Document',
        choices=types_of_doc,
        default="article",
        # widget=radiochoice_buttons,
        widget_classes='form-control',
        validators=[validators.DataRequired()],
    )

    title = fields.TitleField(
        label='Title',
        widget_classes="form-control",
        validators=[validators.DataRequired()],
        export_key='title',
    )

    title_crossref = fields.TitleField(
        export_key='title_crossref',
        widget=HiddenInput(),
    )

    title_arXiv = fields.TitleField(
        export_key='title_arXiv',
        widget=HiddenInput(),
    )

    title_translation = fields.TitleField(
        label='Translated Title',
        description='Original title translated to english language.',
        widget_classes="form-control",
        export_key='title_translation',
    )

    authors = fields.DynamicFieldList(
        fields.FormField(
            AuthorInlineForm,
            widget=ExtendedListWidget(
                item_widget=ItemWidget(),
                html_tag='div',
            ),
        ),
        label='Authors',
        add_label='Add another author',
        min_entries=1,
        widget_classes='',
        export_key='authors',
        validators=[AuthorsValidation],
    )

    collaboration = fields.TextField(
        label='Collaboration',
        export_key="collaboration",
        widget_classes="form-control" + ARTICLE_CLASS
    )

    experiment = fields.TextField(
        placeholder="Start typing for suggestions",
        export_key="experiment",
        label='Experiment',
        widget_classes="form-control",
        autocomplete="experiment"
    )

    subject = fields.SelectMultipleField(
        label='Subject',
        widget_classes="form-control",
        export_key='subject_term',
        filters=[clean_empty_list],
        validators=[validators.DataRequired()]
    )

    abstract = fields.TextAreaField(
        label='Abstract',
        default='',
        widget_classes="form-control",
        export_key='abstract',
    )

    language_choices = [
        (language, Locale('en').languages.get(language))
        for language in FORM_LANGUAGES
    ]
    language_choices.sort(key=lambda x: x[1])
    language_choices.append(
        ('oth', 'Other')
    )

    language = fields.LanguageField(
        label="Language",
        export_key="language",
        default="en",
        choices=language_choices
    )

    def _is_other_language(language):
        return language[0] not in FORM_LANGUAGES and len(language[0]) == 2

    other_language_choices = filter(
        _is_other_language,
        Locale('en').languages.items()
    )
    other_language_choices.sort(key=lambda x: x[1])

    other_language = fields.LanguageField(
        label="Other Language",
        export_key="other_language",
        widget_classes="form-control",
        choices=other_language_choices,
        description="What is the language of the publication?"
    )

    conf_name = fields.TextField(
        placeholder="Start typing for suggestions",
        label='Conference Information',
        description='Conference name, acronym, place, date',
        widget_classes="form-control" + ARTICLE_CLASS,
        autocomplete='conference'
    )

    conference_id = fields.TextField(
        export_key='conference_id',
        widget=HiddenInput(),
    )

    license_url = fields.TextField(
        label='License URL',
        export_key='license_url',
        widget=HiddenInput(),
    )

    report_numbers = fields.DynamicFieldList(
        fields.FormField(
            ReportNumberInlineForm,
            widget=ExtendedListWidget(
                item_widget=ItemWidget(),
                html_tag='div',
            ),
        ),
        add_label='Add another report number',
        min_entries=1,
        widget_classes='',
        widget=UnsortedDynamicListWidget(),
    )

    # ==============
    # Thesis related
    # ==============

    supervisors = fields.DynamicFieldList(
        fields.FormField(
            AuthorInlineForm,
            widget=ExtendedListWidget(
                item_widget=ItemWidget(),
                html_tag='div',
            ),
        ),
        label='Supervisors',
        add_label='Add another supervisor',
        min_entries=1,
        widget_classes=THESIS_CLASS,
    )

    thesis_date = fields.TextField(
        label='Date of Submission',
        description='Format: YYYY-MM-DD, YYYY-MM or YYYY.',
        validators=[date_validator],
        widget_classes='form-control' + THESIS_CLASS,
    )

    defense_date = fields.TextField(
        label='Date of Defense',
        description='Format: YYYY-MM-DD, YYYY-MM or YYYY.',
        validators=[date_validator],
        widget_classes='form-control' + THESIS_CLASS,
    )

    degree_type = fields.SelectField(
        label='Degree Type',
        default='phd',
        widget_classes="form-control" + THESIS_CLASS,
    )

    institution = fields.TextField(
        autocomplete='affiliation',
        placeholder='Start typing for suggestions',
        label='Institution',
        widget_classes="form-control" + THESIS_CLASS,
    )

    # =========
    # Book Info
    # =========

    publisher_name = fields.TextField(
        label='Publisher',
        widget_classes="form-control" + BOOK_CLASS,
    )

    publication_place = fields.TextField(
        label='Publication Place',
        widget_classes="form-control" + BOOK_CLASS,
    )

    series_title = fields.TextField(
        label='Series Title',
        widget_classes="form-control" + BOOK_CLASS,
        autocomplete='journal'
    )

    series_volume = fields.TextField(
        label='Volume',
        widget_classes="form-control" + BOOK_CLASS,
    )

    publication_date = fields.TextField(
        label='Publication Date',
        description='Format: YYYY-MM-DD, YYYY-MM or YYYY.',
        widget_classes="form-control" + BOOK_CLASS,
        validators=[date_validator],
    )

    # =================
    # Book Chapter Info
    # =================

    book_title = fields.TextField(
        label='Book Title',
        widget_classes="form-control" + CHAPTER_CLASS,
    )

    start_page = fields.TextField(
        placeholder='Start page of the chapter',
        widget_classes="form-control" + CHAPTER_CLASS,
    )

    end_page = fields.TextField(
        placeholder='End page of the chapter',
        widget_classes="form-control" + CHAPTER_CLASS,
    )

    find_book = fields.TextField(
        placeholder="Start typing for suggestions",
        label='Find Book',
        description='Book name, ISBN, Publisher',
        widget_classes="form-control" + CHAPTER_CLASS,
    )
    parent_book = fields.TextField(
        widget=HiddenInput(),
    )

    # ============
    # Journal Info
    # ============

    journal_title = fields.TextField(
        placeholder="Start typing for suggestions",
        label='Journal Title',
        widget_classes="form-control" + ARTICLE_CLASS,
        autocomplete='journal'
    )

    page_range_article_id = fields.TextField(
        label='Page Range/Article ID',
        description='e.g. 1-100',
        widget_classes="form-control" + ARTICLE_CLASS
    )

    volume = fields.TextField(
        label='Volume',
        widget_classes="form-control" + ARTICLE_CLASS
    )

    year = fields.TextField(
        label='Year',
        widget_classes="form-control" + ARTICLE_CLASS,
        validators=[year_validator],
    )

    issue = fields.TextField(
        label='Issue',
        widget_classes="form-control" + ARTICLE_CLASS
    )

    nonpublic_note = fields.TextAreaField(
        label='Proceedings',
        description='Editors, title of proceedings, publisher, year of publication, page range, URL',
        widget=wrap_nonpublic_note,
        widget_classes="form-control" + ARTICLE_CLASS
    )

    note = fields.TextAreaField(
        widget=HiddenInput(),
        export_key='note',
    )

    # ==========
    # References
    # ==========

    references = fields.TextAreaField(
        label='References',
        description='Please paste the references in plain text',
        widget_classes="form-control"
    )

    # ====================
    # Preprint Information
    # ====================

    preprint_created = fields.TextField(
        widget=HiddenInput(),
        export_key='preprint_created',
    )

    # ====================
    # Fulltext Information
    # ====================

    url = fields.TextField(
        label='Link to PDF',
        description='Where can we find a PDF to check the references?',
        placeholder='http://www.example.com/document.pdf',
        validators=[pdf_validator],
        widget_classes="form-control",
    )

    additional_url = fields.TextField(
        label='Link to additional information (e.g. abstract)',
        description='Which page should we link from INSPIRE?',
        placeholder='http://www.example.com/splash-page.html',
        validators=[no_pdf_validator],
        widget_classes="form-control",
    )

    # ==============
    # Extra comments
    # ==============

    extra_comments = fields.TextAreaField(
        label='Comments',
        description='Any extra comments related to your submission',
        widget_classes="form-control"
    )

    #
    # Form Configuration
    #
    _title = "Suggest content"

    # Group fields in categories

    groups = [
        ('Import information',
            ['arxiv_id', 'doi', 'import_buttons']),
        ('Document Type',
            ['type_of_doc', ]),
        ('Links',
            ['url', 'additional_url']),
        ('Publication Information',
            ['find_book', 'parent_book', 'book_title', 'start_page', 'end_page']),
        ('Basic Information',
            ['title', 'title_arXiv', 'categories_arXiv', 'language',
             'other_language', 'title_translation', 'subject', 'authors',
             'collaboration', 'experiment', 'abstract',
             'report_numbers']),
        ('Thesis Information',
            ['degree_type', 'thesis_date', 'defense_date', 'institution',
             'supervisors', 'license_url']),
        ('Publication Information',
            ['journal_title', 'volume', 'issue',
             'year', 'page_range_article_id']),
        ('Publication Information',
            ['series_title', 'series_volume', 'publication_date',
             'publisher_name', 'publication_place']),
        ('Conference Information',
            ['conf_name', 'conference_id'], {'classes': 'collapse'}),
        ('Proceedings Information (if not published in a journal)',
            ['nonpublic_note'], {'classes': 'collapse'}),
        ('References',
            ['references'], {'classes': 'collapse'}),
        ('Additional comments',
            ['extra_comments'], {'classes': 'collapse'}),
    ]

    field_sizes = {
        'type_of_doc': 'col-xs-12 col-md-3',
        'wrap_nonpublic_note': 'col-md-9',
        'publisher_name': 'col-xs-12 col-md-9',
        'publication_date': 'col-xs-12 col-md-4',
        'thesis_date': 'col-xs-12 col-md-4',
        'defense_date': 'col-xs-12 col-md-4',
        'degree_type': 'col-xs-12 col-md-3',
        'start_page': 'col-xs-12 col-md-3',
        'end_page': 'col-xs-12 col-md-3',
    }

    def __init__(self, *args, **kwargs):
        """Constructor."""
        super(LiteratureForm, self).__init__(*args, **kwargs)

        inspire_categories_schema = load_schema('elements/inspire_field.json')
        categories = inspire_categories_schema['properties']['term']['enum']
        self.subject.choices = [(val, val) for val in categories]

        degree_type_schema = load_schema('elements/degree_type.json')
        degree_choices = [
            (val, val.capitalize()) if val != 'phd' else ('phd', 'PhD')
            for val in degree_type_schema['enum']
        ]
        degree_choices.sort(key=lambda x: x[1])
        self.degree_type.choices = degree_choices