Ejemplo n.º 1
0
def refresh_subjects(record):
    """ Using the GenericBibjson we can fix the subjects on journals, applications and articles with this function """
    bj = record.bibjson()
    assert isinstance(bj, models.GenericBibJSON)
    old_subjects = bj.subjects()
    bj.remove_subjects()

    new_subjects = []
    for s in old_subjects:
        try:
            sobj = {
                "scheme": 'LCC',
                "term": lcc.lookup_code(s['code']),
                "code": s['code']
            }
            new_subjects.append(sobj)
        except KeyError:
            # Carry over the DOAJ schema subjects
            if 'scheme' in s and s['scheme'] == 'DOAJ':
                new_subjects.append(s)
            else:
                print("Missing code:", s)

    bj.set_subjects(new_subjects)
    if old_subjects != record.bibjson().subjects():
        print('{0} Changed.\nold: {1}\nnew: {2}'.format(
            record['id'], old_subjects,
            record.bibjson().subjects()))
    return record
Ejemplo n.º 2
0
def refresh_subjects(record):
    """ Using the GenericBibjson we can fix the subjects on journals, applications and articles with this function """
    bj = record.bibjson()
    assert isinstance(bj, models.GenericBibJSON)
    old_subjects = bj.subjects()
    bj.remove_subjects()

    new_subjects = []
    for s in old_subjects:
        try:
            sobj = {"scheme": u'LCC', "term": lcc.lookup_code(s['code']), "code": s['code']}
            new_subjects.append(sobj)
        except KeyError:
            # Carry over the DOAJ schema subjects
            if 'scheme' in s and s['scheme'] == 'DOAJ':
                new_subjects.append(s)
            else:
                print "Missing code:", s

    bj.set_subjects(new_subjects)
    if old_subjects != record.bibjson().subjects():
        print '{0} Changed.\nold: {1}\nnew: {2}'.format(record['id'], old_subjects, record.bibjson().subjects())
    return record
Ejemplo n.º 3
0
    def form2obj(form, existing_journal):
        journal = Journal()
        bibjson = journal.bibjson()

        # The if statements that wrap practically every field are there due to this
        # form being used to edit old journals which don't necessarily have most of
        # this info.
        # It also allows admins to delete the contents of any field if they wish,
        # by ticking the "Allow incomplete form" checkbox and deleting the contents
        # of that field. The if condition(s) will then *not* add the relevant field to the
        # new journal object being constructed.
        # add_url in the journal model has a safeguard against empty URL-s.

        if form.title.data:
            bibjson.title = form.title.data
        bibjson.add_url(form.url.data, urltype='homepage')
        if form.alternative_title.data:
            bibjson.alternative_title = form.alternative_title.data
        if form.pissn.data:
            bibjson.add_identifier(bibjson.P_ISSN, form.pissn.data)
        if form.eissn.data:
            bibjson.add_identifier(bibjson.E_ISSN, form.eissn.data)
        if form.publisher.data:
            bibjson.publisher = form.publisher.data
        if form.society_institution.data:
            bibjson.institution = form.society_institution.data
        if form.platform.data:
            bibjson.provider = form.platform.data
        if form.contact_name.data or form.contact_email.data:
            journal.add_contact(form.contact_name.data, form.contact_email.data)
        if form.country.data:
            bibjson.country = form.country.data

        if forms.interpret_special(form.processing_charges.data):
            bibjson.set_apc(form.processing_charges_currency.data, form.processing_charges_amount.data)

        if forms.interpret_special(form.submission_charges.data):
            bibjson.set_submission_charges(form.submission_charges_currency.data, form.submission_charges_amount.data)

        if forms.interpret_special(form.waiver_policy.data):
            bibjson.add_url(form.waiver_policy_url.data, 'waiver_policy')

        # checkboxes
        if forms.interpret_special(form.digital_archiving_policy.data) or form.digital_archiving_policy_url.data:
            archiving_policies = forms.interpret_special(form.digital_archiving_policy.data)
            archiving_policies = forms.interpret_other(archiving_policies, form.digital_archiving_policy_other.data, store_other_label=True)
            archiving_policies = forms.interpret_other(archiving_policies, form.digital_archiving_policy_library.data, forms.digital_archiving_policy_specific_library_value, store_other_label=True)
            bibjson.set_archiving_policy(archiving_policies, form.digital_archiving_policy_url.data)

        if form.crawl_permission.data and form.crawl_permission.data != 'None':
            bibjson.allows_fulltext_indexing = forms.interpret_special(form.crawl_permission.data)  # just binary

        # checkboxes
        article_ids = forms.interpret_special(form.article_identifiers.data)
        article_ids = forms.interpret_other(article_ids, form.article_identifiers_other.data)
        if article_ids:
            bibjson.persistent_identifier_scheme = article_ids

        if (form.download_statistics.data and form.download_statistics.data != 'None') or form.download_statistics_url.data:
            bibjson.set_article_statistics(form.download_statistics_url.data, forms.interpret_special(form.download_statistics.data))

        if form.first_fulltext_oa_year.data:
            bibjson.set_oa_start(year=form.first_fulltext_oa_year.data)

        # checkboxes
        fulltext_format = forms.interpret_other(form.fulltext_format.data, form.fulltext_format_other.data)
        if fulltext_format:
            bibjson.format = fulltext_format

        if form.keywords.data:
            bibjson.set_keywords(form.keywords.data)  # tag list field

        if form.languages.data:
            bibjson.set_language(form.languages.data)  # select multiple field - gives a list back

        bibjson.add_url(form.editorial_board_url.data, urltype='editorial_board')

        if form.review_process.data or form.review_process_url.data:
            bibjson.set_editorial_review(form.review_process.data, form.review_process_url.data)

        bibjson.add_url(form.aims_scope_url.data, urltype='aims_scope')
        bibjson.add_url(form.instructions_authors_url.data, urltype='author_instructions')

        if (form.plagiarism_screening.data and form.plagiarism_screening.data != 'None') or form.plagiarism_screening_url.data:
            bibjson.set_plagiarism_detection(
                form.plagiarism_screening_url.data,
                has_detection=forms.interpret_special(form.plagiarism_screening.data)
            )

        if form.publication_time.data:
            bibjson.publication_time = form.publication_time.data

        bibjson.add_url(form.oa_statement_url.data, urltype='oa_statement')

        license_type = forms.interpret_other(form.license.data, form.license_other.data)
        if forms.interpret_special(license_type):
        # "None" and "False" as strings like they come out of the WTForms processing)
        # would get interpreted correctly by this check, so "None" licenses should not appear
            if license_type in licenses:
                by = licenses[license_type]['BY']
                nc = licenses[license_type]['NC']
                nd = licenses[license_type]['ND']
                sa = licenses[license_type]['SA']
                license_title = licenses[license_type]['title']
            elif form.license_checkbox.data:
                by = True if 'BY' in form.license_checkbox.data else False
                nc = True if 'NC' in form.license_checkbox.data else False
                nd = True if 'ND' in form.license_checkbox.data else False
                sa = True if 'SA' in form.license_checkbox.data else False
                license_title = license_type
            else:
                by = None; nc = None; nd = None; sa = None;
                license_title = license_type

            bibjson.set_license(
                license_title,
                license_type,
                url=form.license_url.data,
                open_access=forms.interpret_special(form.open_access.data),
                by=by, nc=nc, nd=nd, sa=sa,
                embedded=forms.interpret_special(form.license_embedded.data),
                embedded_example_url=form.license_embedded_url.data
            )

        # checkboxes
        deposit_policies = forms.interpret_special(form.deposit_policy.data)  # need empty list if it's just "None"
        deposit_policies = forms.interpret_other(deposit_policies, form.deposit_policy_other.data)
        if deposit_policies:
            bibjson.deposit_policy = deposit_policies

        if form.copyright.data and form.copyright.data != 'None':
            holds_copyright = forms.interpret_other(
                forms.interpret_special(form.copyright.data),
                form.copyright_other.data
            )
            bibjson.set_author_copyright(form.copyright_url.data, holds_copyright=holds_copyright)

        if form.publishing_rights.data and form.publishing_rights.data != 'None':
            publishing_rights = forms.interpret_other(
                forms.interpret_special(form.publishing_rights.data),
                form.publishing_rights_other.data
            )
            bibjson.set_author_publishing_rights(form.publishing_rights_url.data, holds_rights=publishing_rights)

        # need to copy over the notes from the existing journal object, if any, otherwise
        # the dates on all the notes will get reset to right now (i.e. last_updated)
        # since the journal object we're creating in this xwalk is a new, empty one
        journal.set_notes(existing_journal.notes())

        # generate index of notes, just the text
        curnotes = []
        for curnote in journal.notes():
            curnotes.append(curnote['note'])

        # add any new notes
        formnotes = []
        for formnote in form.notes.data:
            if formnote['note']:
                if formnote['note'] not in curnotes and formnote["note"] != "":
                    journal.add_note(formnote['note'])
                # also generate another text index of notes, this time an index of the form notes
                formnotes.append(formnote['note'])

        if current_user.has_role("delete_note"):
            # delete all notes not coming back from the form, means they've been deleted
            # also if one of the saved notes is completely blank, delete it
            for curnote in journal.notes()[:]:
                if not curnote['note'] or curnote['note'] not in formnotes:
                    journal.remove_note(curnote)

        new_subjects = []
        for code in form.subject.data:
            sobj = {"scheme": 'LCC', "term": lcc.lookup_code(code), "code": code}
            new_subjects.append(sobj)
        bibjson.set_subjects(new_subjects)

        owner = form.owner.data.strip()
        if owner:
            journal.set_owner(owner)

        editor_group = form.editor_group.data.strip()
        if editor_group:
            journal.set_editor_group(editor_group)

        editor = form.editor.data.strip()
        if editor:
            journal.set_editor(editor)

        # old fields - only create them in the journal record if the values actually exist
        # need to use interpret_special in the test condition in case 'None' comes back from the form
        if getattr(form, 'author_pays', None):
            if forms.interpret_special(form.author_pays.data):
                bibjson.author_pays = form.author_pays.data
        if getattr(form, 'author_pays_url', None):
            if forms.interpret_special(form.author_pays_url.data):
                bibjson.author_pays_url = form.author_pays_url.data
        if getattr(form, 'oa_end_year', None):
            if forms.interpret_special(form.oa_end_year.data):
                bibjson.set_oa_end(form.oa_end_year.data)

        return journal
Ejemplo n.º 4
0
    def form2obj(cls, form):
        journal = models.Journal()
        bibjson = journal.bibjson()

        # The if statements that wrap practically every field are there due to this
        # form being used to edit old journals which don't necessarily have most of
        # this info.
        # It also allows admins to delete the contents of any field if they wish,
        # by ticking the "Allow incomplete form" checkbox and deleting the contents
        # of that field. The if condition(s) will then *not* add the relevant field to the
        # new journal object being constructed.
        # add_url in the journal model has a safeguard against empty URL-s.

        if form.title.data:
            bibjson.title = form.title.data
        bibjson.add_url(form.url.data, urltype='homepage')
        if form.alternative_title.data:
            bibjson.alternative_title = form.alternative_title.data
        if form.pissn.data:
            bibjson.add_identifier(bibjson.P_ISSN, form.pissn.data)
        if form.eissn.data:
            bibjson.add_identifier(bibjson.E_ISSN, form.eissn.data)
        if form.publisher.data:
            bibjson.publisher = form.publisher.data
        if form.society_institution.data:
            bibjson.institution = form.society_institution.data
        if form.platform.data:
            bibjson.provider = form.platform.data
        if form.contact_name.data or form.contact_email.data:
            journal.add_contact(form.contact_name.data,
                                form.contact_email.data)
        if form.country.data:
            bibjson.country = form.country.data

        if interpret_special(form.processing_charges.data):
            bibjson.set_apc(form.processing_charges_currency.data,
                            form.processing_charges_amount.data)

        if form.processing_charges_url.data:
            bibjson.apc_url = form.processing_charges_url.data

        if interpret_special(form.submission_charges.data):
            bibjson.set_submission_charges(
                form.submission_charges_currency.data,
                form.submission_charges_amount.data)

        if form.submission_charges_url.data:
            bibjson.submission_charges_url = form.submission_charges_url.data

        if interpret_special(form.waiver_policy.data):
            bibjson.add_url(form.waiver_policy_url.data, 'waiver_policy')

        # checkboxes
        if interpret_special(form.digital_archiving_policy.data
                             ) or form.digital_archiving_policy_url.data:
            archiving_policies = interpret_special(
                form.digital_archiving_policy.data)
            archiving_policies = interpret_other(
                archiving_policies,
                form.digital_archiving_policy_other.data,
                store_other_label=True)
            archiving_policies = interpret_other(
                archiving_policies,
                form.digital_archiving_policy_library.data,
                Choices.digital_archiving_policy_val("library"),
                store_other_label=True)
            bibjson.set_archiving_policy(
                archiving_policies, form.digital_archiving_policy_url.data)

        if form.crawl_permission.data and form.crawl_permission.data != 'None':
            bibjson.allows_fulltext_indexing = interpret_special(
                form.crawl_permission.data)  # just binary

        # checkboxes
        article_ids = interpret_special(form.article_identifiers.data)
        article_ids = interpret_other(article_ids,
                                      form.article_identifiers_other.data)
        if article_ids:
            bibjson.persistent_identifier_scheme = article_ids

        if (form.download_statistics.data and form.download_statistics.data !=
                'None') or form.download_statistics_url.data:
            bibjson.set_article_statistics(
                form.download_statistics_url.data,
                interpret_special(form.download_statistics.data))

        if form.first_fulltext_oa_year.data:
            bibjson.set_oa_start(year=form.first_fulltext_oa_year.data)

        # checkboxes
        fulltext_format = interpret_other(form.fulltext_format.data,
                                          form.fulltext_format_other.data)
        if fulltext_format:
            bibjson.format = fulltext_format

        if form.keywords.data:
            bibjson.set_keywords(form.keywords.data)  # tag list field

        if form.languages.data:
            bibjson.set_language(form.languages.data
                                 )  # select multiple field - gives a list back

        bibjson.add_url(form.editorial_board_url.data,
                        urltype='editorial_board')

        if form.review_process.data or form.review_process_url.data:
            bibjson.set_editorial_review(form.review_process.data,
                                         form.review_process_url.data)

        bibjson.add_url(form.aims_scope_url.data, urltype='aims_scope')
        bibjson.add_url(form.instructions_authors_url.data,
                        urltype='author_instructions')

        if (form.plagiarism_screening.data and form.plagiarism_screening.data
                != 'None') or form.plagiarism_screening_url.data:
            bibjson.set_plagiarism_detection(
                form.plagiarism_screening_url.data,
                has_detection=interpret_special(
                    form.plagiarism_screening.data))

        if form.publication_time.data:
            bibjson.publication_time = form.publication_time.data

        bibjson.add_url(form.oa_statement_url.data, urltype='oa_statement')

        license_type = interpret_other(form.license.data,
                                       form.license_other.data)
        if interpret_special(license_type):
            # "None" and "False" as strings like they come out of the WTForms processing)
            # would get interpreted correctly by this check, so "None" licenses should not appear
            if license_type in licenses:
                by = licenses[license_type]['BY']
                nc = licenses[license_type]['NC']
                nd = licenses[license_type]['ND']
                sa = licenses[license_type]['SA']
                license_title = licenses[license_type]['title']
            elif form.license_checkbox.data:
                by = True if 'BY' in form.license_checkbox.data else False
                nc = True if 'NC' in form.license_checkbox.data else False
                nd = True if 'ND' in form.license_checkbox.data else False
                sa = True if 'SA' in form.license_checkbox.data else False
                license_title = license_type
            else:
                by = None
                nc = None
                nd = None
                sa = None
                license_title = license_type

            bibjson.set_license(
                license_title,
                license_type,
                url=form.license_url.data,
                open_access=interpret_special(form.open_access.data),
                by=by,
                nc=nc,
                nd=nd,
                sa=sa,
                embedded=interpret_special(form.license_embedded.data),
                embedded_example_url=form.license_embedded_url.data)

        # checkboxes
        deposit_policies = interpret_special(
            form.deposit_policy.data)  # need empty list if it's just "None"
        deposit_policies = interpret_other(deposit_policies,
                                           form.deposit_policy_other.data)
        if deposit_policies:
            bibjson.deposit_policy = deposit_policies

        if form.copyright.data and form.copyright.data != 'None':
            holds_copyright = interpret_other(
                interpret_special(form.copyright.data),
                form.copyright_other.data)
            bibjson.set_author_copyright(form.copyright_url.data,
                                         holds_copyright=holds_copyright)

        if form.publishing_rights.data and form.publishing_rights.data != 'None':
            publishing_rights = interpret_other(
                interpret_special(form.publishing_rights.data),
                form.publishing_rights_other.data)
            bibjson.set_author_publishing_rights(
                form.publishing_rights_url.data,
                holds_rights=publishing_rights)

        for formnote in form.notes.data:
            if formnote["note"]:
                journal.add_note(formnote["note"])

        new_subjects = []
        for code in form.subject.data:
            sobj = {
                "scheme": 'LCC',
                "term": lcc.lookup_code(code),
                "code": code
            }
            new_subjects.append(sobj)
        bibjson.set_subjects(new_subjects)

        if getattr(form, 'owner', None):
            owner = form.owner.data.strip()
            if owner:
                journal.set_owner(owner)

        if getattr(form, 'editor_group', None):
            editor_group = form.editor_group.data.strip()
            if editor_group:
                journal.set_editor_group(editor_group)

        if getattr(form, "editor", None):
            editor = form.editor.data.strip()
            if editor:
                journal.set_editor(editor)

        # old fields - only create them in the journal record if the values actually exist
        # need to use interpret_special in the test condition in case 'None' comes back from the form
        if getattr(form, 'author_pays', None):
            if interpret_special(form.author_pays.data):
                bibjson.author_pays = form.author_pays.data
        if getattr(form, 'author_pays_url', None):
            if interpret_special(form.author_pays_url.data):
                bibjson.author_pays_url = form.author_pays_url.data
        if getattr(form, 'oa_end_year', None):
            if interpret_special(form.oa_end_year.data):
                bibjson.set_oa_end(form.oa_end_year.data)

        return journal
Ejemplo n.º 5
0
    def form2obj(cls, form):
        suggestion = models.Suggestion()
        bibjson = suggestion.bibjson()

        if form.title.data:
            bibjson.title = form.title.data
        bibjson.add_url(form.url.data, urltype='homepage')
        if form.alternative_title.data:
            bibjson.alternative_title = form.alternative_title.data
        if form.pissn.data:
            bibjson.add_identifier(bibjson.P_ISSN, form.pissn.data)
        if form.eissn.data:
            bibjson.add_identifier(bibjson.E_ISSN, form.eissn.data)
        if form.publisher.data:
            bibjson.publisher = form.publisher.data
        if form.society_institution.data:
            bibjson.institution = form.society_institution.data
        if form.platform.data:
            bibjson.provider = form.platform.data
        if form.contact_name.data or form.contact_email.data:
            suggestion.add_contact(form.contact_name.data,
                                   form.contact_email.data)
        if form.country.data:
            bibjson.country = form.country.data

        if interpret_special(form.processing_charges.data):
            bibjson.set_apc(form.processing_charges_currency.data,
                            form.processing_charges_amount.data)

        if form.processing_charges_url.data:
            bibjson.apc_url = form.processing_charges_url.data

        if interpret_special(form.submission_charges.data):
            bibjson.set_submission_charges(
                form.submission_charges_currency.data,
                form.submission_charges_amount.data)

        if form.submission_charges_url.data:
            bibjson.submission_charges_url = form.submission_charges_url.data

        suggestion.set_articles_last_year(form.articles_last_year.data,
                                          form.articles_last_year_url.data)

        if interpret_special(form.waiver_policy.data):
            bibjson.add_url(form.waiver_policy_url.data, 'waiver_policy')

        # checkboxes
        if interpret_special(form.digital_archiving_policy.data
                             ) or form.digital_archiving_policy_url.data:
            archiving_policies = interpret_special(
                form.digital_archiving_policy.data)
            archiving_policies = interpret_other(
                archiving_policies,
                form.digital_archiving_policy_other.data,
                store_other_label=True)
            archiving_policies = interpret_other(
                archiving_policies,
                form.digital_archiving_policy_library.data,
                Choices.digital_archiving_policy_val("library"),
                store_other_label=True)
            bibjson.set_archiving_policy(
                archiving_policies, form.digital_archiving_policy_url.data)

        if form.crawl_permission.data and form.crawl_permission.data != 'None':
            bibjson.allows_fulltext_indexing = interpret_special(
                form.crawl_permission.data)  # just binary

        # checkboxes
        article_ids = interpret_special(form.article_identifiers.data)
        article_ids = interpret_other(article_ids,
                                      form.article_identifiers_other.data)
        if article_ids:
            bibjson.persistent_identifier_scheme = article_ids

        if form.metadata_provision.data and form.metadata_provision.data != 'None':
            suggestion.article_metadata = interpret_special(
                form.metadata_provision.data)  # just binary

        if (form.download_statistics.data and form.download_statistics.data !=
                'None') or form.download_statistics_url.data:
            bibjson.set_article_statistics(
                form.download_statistics_url.data,
                interpret_special(form.download_statistics.data))

        if form.first_fulltext_oa_year.data:
            bibjson.set_oa_start(year=form.first_fulltext_oa_year.data)

        # checkboxes
        fulltext_format = interpret_other(form.fulltext_format.data,
                                          form.fulltext_format_other.data)
        if fulltext_format:
            bibjson.format = fulltext_format

        if form.keywords.data:
            bibjson.set_keywords(form.keywords.data)  # tag list field

        if form.languages.data:
            bibjson.set_language(form.languages.data
                                 )  # select multiple field - gives a list back

        bibjson.add_url(form.editorial_board_url.data,
                        urltype='editorial_board')

        if form.review_process.data or form.review_process_url.data:
            bibjson.set_editorial_review(form.review_process.data,
                                         form.review_process_url.data)

        bibjson.add_url(form.aims_scope_url.data, urltype='aims_scope')
        bibjson.add_url(form.instructions_authors_url.data,
                        urltype='author_instructions')

        if (form.plagiarism_screening.data and form.plagiarism_screening.data
                != 'None') or form.plagiarism_screening_url.data:
            bibjson.set_plagiarism_detection(
                form.plagiarism_screening_url.data,
                has_detection=interpret_special(
                    form.plagiarism_screening.data))

        if form.publication_time.data:
            bibjson.publication_time = form.publication_time.data

        bibjson.add_url(form.oa_statement_url.data, urltype='oa_statement')

        license_type = interpret_other(form.license.data,
                                       form.license_other.data)
        if interpret_special(license_type):
            # "None" and "False" as strings like they come out of the WTForms processing)
            # would get interpreted correctly by this check, so "None" licenses should not appear
            if license_type in licenses:
                by = licenses[license_type]['BY']
                nc = licenses[license_type]['NC']
                nd = licenses[license_type]['ND']
                sa = licenses[license_type]['SA']
                license_title = licenses[license_type]['title']
            elif form.license_checkbox.data:
                by = True if 'BY' in form.license_checkbox.data else False
                nc = True if 'NC' in form.license_checkbox.data else False
                nd = True if 'ND' in form.license_checkbox.data else False
                sa = True if 'SA' in form.license_checkbox.data else False
                license_title = license_type
            else:
                by = None
                nc = None
                nd = None
                sa = None
                license_title = license_type

            bibjson.set_license(
                license_title,
                license_type,
                url=form.license_url.data,
                open_access=interpret_special(form.open_access.data),
                by=by,
                nc=nc,
                nd=nd,
                sa=sa,
                embedded=interpret_special(form.license_embedded.data),
                embedded_example_url=form.license_embedded_url.data)

        # checkboxes
        deposit_policies = interpret_special(
            form.deposit_policy.data)  # need empty list if it's just "None"
        deposit_policies = interpret_other(deposit_policies,
                                           form.deposit_policy_other.data)
        if deposit_policies:
            bibjson.deposit_policy = deposit_policies

        if form.copyright.data and form.copyright.data != 'None':
            holds_copyright = interpret_other(
                interpret_special(form.copyright.data),
                form.copyright_other.data)
            bibjson.set_author_copyright(form.copyright_url.data,
                                         holds_copyright=holds_copyright)

        if form.publishing_rights.data and form.publishing_rights.data != 'None':
            publishing_rights = interpret_other(
                interpret_special(form.publishing_rights.data),
                form.publishing_rights_other.data)
            bibjson.set_author_publishing_rights(
                form.publishing_rights_url.data,
                holds_rights=publishing_rights)

        if getattr(form, "suggester_name", None) or getattr(
                form, "suggester_email", None):
            name = None
            email = None
            if getattr(form, "suggester_name", None):
                name = form.suggester_name.data
            if getattr(form, "suggester_email", None):
                email = form.suggester_email.data
            suggestion.set_suggester(name, email)

        # admin stuff
        if getattr(form, 'application_status', None):
            suggestion.set_application_status(form.application_status.data)

        if getattr(form, 'notes', None):
            for formnote in form.notes.data:
                if formnote["note"]:
                    suggestion.add_note(formnote["note"])

        if getattr(form, 'subject', None):
            new_subjects = []
            for code in form.subject.data:
                sobj = {
                    "scheme": 'LCC',
                    "term": lcc.lookup_code(code),
                    "code": code
                }
                new_subjects.append(sobj)
            bibjson.set_subjects(new_subjects)

        if getattr(form, 'owner', None):
            owns = form.owner.data.strip()
            if owns:
                suggestion.set_owner(form.owner.data.strip())

        if getattr(form, 'editor_group', None):
            editor_group = form.editor_group.data.strip()
            if editor_group:
                suggestion.set_editor_group(editor_group)

        if getattr(form, "editor", None):
            editor = form.editor.data.strip()
            if editor:
                suggestion.set_editor(editor)

        return suggestion
Ejemplo n.º 6
0
    def form2obj(form, existing_suggestion=None):
        suggestion = models.Suggestion()
        bibjson = suggestion.bibjson()

        if form.title.data:
            bibjson.title = form.title.data
        bibjson.add_url(form.url.data, urltype='homepage')
        if form.alternative_title.data:
            bibjson.alternative_title = form.alternative_title.data
        if form.pissn.data:
            bibjson.add_identifier(bibjson.P_ISSN, form.pissn.data)
        if form.eissn.data:
            bibjson.add_identifier(bibjson.E_ISSN, form.eissn.data)
        if form.publisher.data:
            bibjson.publisher = form.publisher.data
        if form.society_institution.data:
            bibjson.institution = form.society_institution.data
        if form.platform.data:
            bibjson.provider = form.platform.data
        if form.contact_name.data or form.contact_email.data:
            suggestion.add_contact(form.contact_name.data, form.contact_email.data)
        if form.country.data:
            bibjson.country = form.country.data

        if forms.interpret_special(form.processing_charges.data):
            bibjson.set_apc(form.processing_charges_currency.data, form.processing_charges_amount.data)

        if forms.interpret_special(form.submission_charges.data):
            bibjson.set_submission_charges(form.submission_charges_currency.data, form.submission_charges_amount.data)

        suggestion.set_articles_last_year(form.articles_last_year.data, form.articles_last_year_url.data)

        if forms.interpret_special(form.waiver_policy.data):
            bibjson.add_url(form.waiver_policy_url.data, 'waiver_policy')

        # checkboxes
        if forms.interpret_special(form.digital_archiving_policy.data) or form.digital_archiving_policy_url.data:
            archiving_policies = forms.interpret_special(form.digital_archiving_policy.data)
            archiving_policies = forms.interpret_other(archiving_policies, form.digital_archiving_policy_other.data, store_other_label=True)
            archiving_policies = forms.interpret_other(archiving_policies, form.digital_archiving_policy_library.data, forms.digital_archiving_policy_specific_library_value, store_other_label=True)
            bibjson.set_archiving_policy(archiving_policies, form.digital_archiving_policy_url.data)

        if form.crawl_permission.data and form.crawl_permission.data != 'None':
            bibjson.allows_fulltext_indexing = forms.interpret_special(form.crawl_permission.data)  # just binary

        # checkboxes
        article_ids = forms.interpret_special(form.article_identifiers.data)
        article_ids = forms.interpret_other(article_ids, form.article_identifiers_other.data)
        if article_ids:
            bibjson.persistent_identifier_scheme = article_ids

        if form.metadata_provision.data and form.metadata_provision.data != 'None':
            suggestion.article_metadata = forms.interpret_special(form.metadata_provision.data)  # just binary

        if (form.download_statistics.data and form.download_statistics.data != 'None') or form.download_statistics_url.data:
            bibjson.set_article_statistics(form.download_statistics_url.data, forms.interpret_special(form.download_statistics.data))

        if form.first_fulltext_oa_year.data:
            bibjson.set_oa_start(year=form.first_fulltext_oa_year.data)

        # checkboxes
        fulltext_format = forms.interpret_other(form.fulltext_format.data, form.fulltext_format_other.data)
        if fulltext_format:
            bibjson.format = fulltext_format

        if form.keywords.data:
            bibjson.set_keywords(form.keywords.data)  # tag list field

        if form.languages.data:
            bibjson.set_language(form.languages.data)  # select multiple field - gives a list back

        bibjson.add_url(form.editorial_board_url.data, urltype='editorial_board')

        if form.review_process.data or form.review_process_url.data:
            bibjson.set_editorial_review(form.review_process.data, form.review_process_url.data)

        bibjson.add_url(form.aims_scope_url.data, urltype='aims_scope')
        bibjson.add_url(form.instructions_authors_url.data, urltype='author_instructions')

        if (form.plagiarism_screening.data and form.plagiarism_screening.data != 'None') or form.plagiarism_screening_url.data:
            bibjson.set_plagiarism_detection(
                form.plagiarism_screening_url.data,
                has_detection=forms.interpret_special(form.plagiarism_screening.data)
            )

        if form.publication_time.data:
            bibjson.publication_time = form.publication_time.data

        bibjson.add_url(form.oa_statement_url.data, urltype='oa_statement')

        license_type = forms.interpret_other(form.license.data, form.license_other.data)
        if forms.interpret_special(license_type):
        # "None" and "False" as strings like they come out of the WTForms processing)
        # would get interpreted correctly by this check, so "None" licenses should not appear
            if license_type in licenses:
                by = licenses[license_type]['BY']
                nc = licenses[license_type]['NC']
                nd = licenses[license_type]['ND']
                sa = licenses[license_type]['SA']
                license_title = licenses[license_type]['title']
            elif form.license_checkbox.data:
                by = True if 'BY' in form.license_checkbox.data else False
                nc = True if 'NC' in form.license_checkbox.data else False
                nd = True if 'ND' in form.license_checkbox.data else False
                sa = True if 'SA' in form.license_checkbox.data else False
                license_title = license_type
            else:
                by = None; nc = None; nd = None; sa = None;
                license_title = license_type

            bibjson.set_license(
                license_title,
                license_type,
                url=form.license_url.data,
                open_access=forms.interpret_special(form.open_access.data),
                by=by, nc=nc, nd=nd, sa=sa,
                embedded=forms.interpret_special(form.license_embedded.data),
                embedded_example_url=form.license_embedded_url.data
            )

        # checkboxes
        deposit_policies = forms.interpret_special(form.deposit_policy.data)  # need empty list if it's just "None"
        deposit_policies = forms.interpret_other(deposit_policies, form.deposit_policy_other.data)
        if deposit_policies:
            bibjson.deposit_policy = deposit_policies

        if form.copyright.data and form.copyright.data != 'None':
            holds_copyright = forms.interpret_other(
                forms.interpret_special(form.copyright.data),
                form.copyright_other.data
            )
            bibjson.set_author_copyright(form.copyright_url.data, holds_copyright=holds_copyright)

        if form.publishing_rights.data and form.publishing_rights.data != 'None':
            publishing_rights = forms.interpret_other(
                forms.interpret_special(form.publishing_rights.data),
                form.publishing_rights_other.data
            )
            bibjson.set_author_publishing_rights(form.publishing_rights_url.data, holds_rights=publishing_rights)

        if form.suggester_name.data or form.suggester_email.data:
            suggestion.set_suggester(form.suggester_name.data, form.suggester_email.data)
        
        # admin stuff
        if getattr(form, 'application_status', None):
            suggestion.set_application_status(form.application_status.data)

        if getattr(form, 'notes', None):
            # need to copy over the notes from the existing suggestion object, if any, otherwise
            # the dates on all the notes will get reset to right now (i.e. last_updated)
            # since the suggestion object we're creating in this xwalk is a new, empty one
            if existing_suggestion:
                suggestion.set_notes(existing_suggestion.notes())

            # generate index of notes, just the text
            curnotes = []
            for curnote in suggestion.notes():
                curnotes.append(curnote['note'])

            # add any new notes
            formnotes = []
            for formnote in form.notes.data:
                if formnote['note']:
                    if formnote['note'] not in curnotes and formnote["note"] != "":
                        suggestion.add_note(formnote['note'])
                    # also generate another text index of notes, this time an index of the form notes
                    formnotes.append(formnote['note'])

            if current_user.has_role("delete_note"):
                # delete all notes not coming back from the form, means they've been deleted
                # also if one of the saved notes is completely blank, delete it
                for curnote in suggestion.notes()[:]:
                    if not curnote['note'] or curnote['note'] not in formnotes:
                        suggestion.remove_note(curnote)

        if getattr(form, 'subject', None):
            new_subjects = []
            for code in form.subject.data:
                sobj = {"scheme": 'LCC', "term": lcc.lookup_code(code), "code": code}
                new_subjects.append(sobj)
            bibjson.set_subjects(new_subjects)
            
        if getattr(form, 'owner', None):
            owns = form.owner.data.strip()
            if owns:
                suggestion.set_owner(form.owner.data.strip())

        if getattr(form, 'editor_group', None):
            editor_group = form.editor_group.data.strip()
            if editor_group:
                suggestion.set_editor_group(editor_group)

        if getattr(form, "editor", None):
            editor = form.editor.data.strip()
            if editor:
                suggestion.set_editor(editor)

        return suggestion
Ejemplo n.º 7
0
    def form2obj(cls, form):
        suggestion = models.Suggestion()
        bibjson = suggestion.bibjson()

        if form.title.data:
            bibjson.title = form.title.data
        bibjson.add_url(form.url.data, urltype='homepage')
        if form.alternative_title.data:
            bibjson.alternative_title = form.alternative_title.data
        if form.pissn.data:
            bibjson.add_identifier(bibjson.P_ISSN, form.pissn.data)
        if form.eissn.data:
            bibjson.add_identifier(bibjson.E_ISSN, form.eissn.data)
        if form.publisher.data:
            bibjson.publisher = form.publisher.data
        if form.society_institution.data:
            bibjson.institution = form.society_institution.data
        if form.platform.data:
            bibjson.provider = form.platform.data
        if form.contact_name.data or form.contact_email.data:
            suggestion.add_contact(form.contact_name.data, form.contact_email.data)
        if form.country.data:
            bibjson.country = form.country.data

        if interpret_special(form.processing_charges.data):
            bibjson.set_apc(form.processing_charges_currency.data, form.processing_charges_amount.data)

        if form.processing_charges_url.data:
            bibjson.apc_url = form.processing_charges_url.data

        if interpret_special(form.submission_charges.data):
            bibjson.set_submission_charges(form.submission_charges_currency.data, form.submission_charges_amount.data)

        if form.submission_charges_url.data:
            bibjson.submission_charges_url = form.submission_charges_url.data

        suggestion.set_articles_last_year(form.articles_last_year.data, form.articles_last_year_url.data)

        if interpret_special(form.waiver_policy.data):
            bibjson.add_url(form.waiver_policy_url.data, 'waiver_policy')

        # checkboxes
        if interpret_special(form.digital_archiving_policy.data) or form.digital_archiving_policy_url.data:
            archiving_policies = interpret_special(form.digital_archiving_policy.data)
            archiving_policies = interpret_other(archiving_policies, form.digital_archiving_policy_other.data, store_other_label=True)
            archiving_policies = interpret_other(archiving_policies, form.digital_archiving_policy_library.data, Choices.digital_archiving_policy_val("library"), store_other_label=True)
            bibjson.set_archiving_policy(archiving_policies, form.digital_archiving_policy_url.data)

        if form.crawl_permission.data and form.crawl_permission.data != 'None':
            bibjson.allows_fulltext_indexing = interpret_special(form.crawl_permission.data)  # just binary

        # checkboxes
        article_ids = interpret_special(form.article_identifiers.data)
        article_ids = interpret_other(article_ids, form.article_identifiers_other.data)
        if article_ids:
            bibjson.persistent_identifier_scheme = article_ids

        if form.metadata_provision.data and form.metadata_provision.data != 'None':
            suggestion.article_metadata = interpret_special(form.metadata_provision.data)  # just binary

        if (form.download_statistics.data and form.download_statistics.data != 'None') or form.download_statistics_url.data:
            bibjson.set_article_statistics(form.download_statistics_url.data, interpret_special(form.download_statistics.data))

        if form.first_fulltext_oa_year.data:
            bibjson.set_oa_start(year=form.first_fulltext_oa_year.data)

        # checkboxes
        fulltext_format = interpret_other(form.fulltext_format.data, form.fulltext_format_other.data)
        if fulltext_format:
            bibjson.format = fulltext_format

        if form.keywords.data:
            bibjson.set_keywords(form.keywords.data)  # tag list field

        if form.languages.data:
            bibjson.set_language(form.languages.data)  # select multiple field - gives a list back

        bibjson.add_url(form.editorial_board_url.data, urltype='editorial_board')

        if form.review_process.data or form.review_process_url.data:
            bibjson.set_editorial_review(form.review_process.data, form.review_process_url.data)

        bibjson.add_url(form.aims_scope_url.data, urltype='aims_scope')
        bibjson.add_url(form.instructions_authors_url.data, urltype='author_instructions')

        if (form.plagiarism_screening.data and form.plagiarism_screening.data != 'None') or form.plagiarism_screening_url.data:
            bibjson.set_plagiarism_detection(
                form.plagiarism_screening_url.data,
                has_detection=interpret_special(form.plagiarism_screening.data)
            )

        if form.publication_time.data:
            bibjson.publication_time = form.publication_time.data

        bibjson.add_url(form.oa_statement_url.data, urltype='oa_statement')

        license_type = interpret_other(form.license.data, form.license_other.data)
        if interpret_special(license_type):
        # "None" and "False" as strings like they come out of the WTForms processing)
        # would get interpreted correctly by this check, so "None" licenses should not appear
            if license_type in licenses:
                by = licenses[license_type]['BY']
                nc = licenses[license_type]['NC']
                nd = licenses[license_type]['ND']
                sa = licenses[license_type]['SA']
                license_title = licenses[license_type]['title']
            elif form.license_checkbox.data:
                by = True if 'BY' in form.license_checkbox.data else False
                nc = True if 'NC' in form.license_checkbox.data else False
                nd = True if 'ND' in form.license_checkbox.data else False
                sa = True if 'SA' in form.license_checkbox.data else False
                license_title = license_type
            else:
                by = None; nc = None; nd = None; sa = None;
                license_title = license_type

            bibjson.set_license(
                license_title,
                license_type,
                url=form.license_url.data,
                open_access=interpret_special(form.open_access.data),
                by=by, nc=nc, nd=nd, sa=sa,
                embedded=interpret_special(form.license_embedded.data),
                embedded_example_url=form.license_embedded_url.data
            )

        # checkboxes
        deposit_policies = interpret_special(form.deposit_policy.data)  # need empty list if it's just "None"
        deposit_policies = interpret_other(deposit_policies, form.deposit_policy_other.data)
        if deposit_policies:
            bibjson.deposit_policy = deposit_policies

        if form.copyright.data and form.copyright.data != 'None':
            holds_copyright = interpret_other(
                interpret_special(form.copyright.data),
                form.copyright_other.data
            )
            bibjson.set_author_copyright(form.copyright_url.data, holds_copyright=holds_copyright)

        if form.publishing_rights.data and form.publishing_rights.data != 'None':
            publishing_rights = interpret_other(
                interpret_special(form.publishing_rights.data),
                form.publishing_rights_other.data
            )
            bibjson.set_author_publishing_rights(form.publishing_rights_url.data, holds_rights=publishing_rights)

        if getattr(form, "suggester_name", None) or getattr(form, "suggester_email", None):
            name = None
            email = None
            if getattr(form, "suggester_name", None):
                name = form.suggester_name.data
            if getattr(form, "suggester_email", None):
                email = form.suggester_email.data
            suggestion.set_suggester(name, email)

        # admin stuff
        if getattr(form, 'application_status', None):
            suggestion.set_application_status(form.application_status.data)

        if getattr(form, 'notes', None):
            for formnote in form.notes.data:
                if formnote["note"]:
                    suggestion.add_note(formnote["note"])

        if getattr(form, 'subject', None):
            new_subjects = []
            for code in form.subject.data:
                sobj = {"scheme": 'LCC', "term": lcc.lookup_code(code), "code": code}
                new_subjects.append(sobj)
            bibjson.set_subjects(new_subjects)

        if getattr(form, 'owner', None):
            owns = form.owner.data.strip()
            if owns:
                suggestion.set_owner(form.owner.data.strip())

        if getattr(form, 'editor_group', None):
            editor_group = form.editor_group.data.strip()
            if editor_group:
                suggestion.set_editor_group(editor_group)

        if getattr(form, "editor", None):
            editor = form.editor.data.strip()
            if editor:
                suggestion.set_editor(editor)

        return suggestion