class ApplicationSubject(Form): """ Subject classification entry - with workflow validation""" subject = DOAJSelectMultipleField('Subjects', [ OptionalIf('application_status', optvals=Choices.application_status_subject_optional()) ], choices=Choices.subjects())
def __init__(self, *args, **kwargs): super(ArticleForm, self).__init__(*args, **kwargs) try: self.pissn.choices = Choices.choices_for_article_issns(current_user) self.eissn.choices = Choices.choices_for_article_issns(current_user) except: # not logged in, and current_user is broken # probably you are loading the class from the command line pass
def reverse_interpret_special(val, field=''): # if you modify this, make sure to modify interpret_special as well if val is None: return Choices.NONE elif val is True: return Choices.TRUE elif val is False: return Choices.FALSE # no need to handle digital archiving policy or other list # fields here - empty lists handled below if isinstance(val, list): if len(val) == 1: reverse_actual_val = reverse_interpret_special(val[0], field=field) return [reverse_actual_val] elif len(val) == 0: # mostly it'll just be a None val if field == 'digital_archiving_policy': return [Choices.digital_archiving_policy_val("none")] return [Choices.NONE] return val return val
class ManEdBulkEditJournalForm(Form): publisher = StringField('Publisher', [validators.Optional()]) doaj_seal = DOAJSelectField( 'Qualifies for Seal', [validators.Optional()], description='How should we change the DOAJ Seal on these journals?', choices=[("", "Leave unchanged"), ("True", "Yes"), ("False", "No")], ) country = DOAJSelectField( 'Country', [validators.Optional()], description= 'Select the country where the publisher carries out its business activities.', choices=Choices.country(), ) owner = StringField( 'Owner', [ReservedUsernames(), validators.Optional()], description='DOAJ account to which the application belongs.') platform = StringField( 'Platform, Host or Aggregator', [validators.Optional()], description= 'The name of the platform, host or aggregator of the journal content, e.g. OJS, HighWire Press, EBSCO etc.' ) contact_name = StringField('Contact Name', [validators.Optional()]) contact_email = StringField('Contact\'s email address', [ validators.Optional(), validators.Email(message='Invalid email address.') ])
def change_status(ids, new_status): statuses = [x[0] for x in Choices.application_status("admin") if x[0] != ""] if new_status not in statuses: raise Exception("Must use an allowed status: " + ", ".join(statuses)) for id in ids: a = Suggestion.pull(id) a.set_application_status(new_status) a.save()
class ApplicationOwner(Form): """ An Owner field which is optional under certain conditions. For use in some admin forms """ owner = StringField('Owner', [ReservedUsernames(), OptionalIf('application_status', optvals=Choices.application_status_optional())], description='DOAJ account to which the application belongs.' '<br><br>' 'This field is optional unless the application status is set to Accepted.' '<br><br>' 'Entering a non-existent account and setting the application status to Accepted will automatically create the account using the Contact information in Questions 9 & 10, and send an email containing the Contact\'s username + password.' )
def change_status(ids, new_status): statuses = [ x[0] for x in Choices.application_status("admin") if x[0] != "" ] if new_status not in statuses: raise Exception("Must use an allowed status: " + ", ".join(statuses)) for id in ids: a = Suggestion.pull(id) a.set_application_status(new_status) a.save()
class JournalLegacy(Form): """ Legacy information required by some journals that are already in the DOAJ """ author_pays = RadioField('Author pays to publish', [validators.Optional()], choices=Choices.author_pays()) author_pays_url = StringField( 'Author pays - guide link', [validators.Optional(), validators.URL()]) oa_end_year = IntegerField( 'Year in which the journal stopped publishing OA content', [ validators.Optional(), validators.NumberRange(max=datetime.now().year) ])
class Suggestion(Form): """ Additional bibliographic metadata required when suggesting a journal to the DOAJ """ articles_last_year = IntegerField('How many research and review articles did the journal publish in the last calendar year?', [validators.DataRequired(), validators.NumberRange(min=0)], description='A journal must publish at least 5 articles per year to stay in the DOAJ.', ) articles_last_year_url = URLField('Enter the URL where this information can be found', [validators.DataRequired(), URLOptionalScheme()] ) metadata_provision = RadioField('Does the journal provide, or intend to provide, article level metadata to DOAJ?', [validators.DataRequired()], description='If yes, metadata must be provided within 3 months of acceptance into DOAJ.', choices=Choices.metadata_provision() )
def interpret_special(val): # if you modify this, make sure to modify reverse_interpret_special as well if isinstance(val, basestring): if val.lower() == Choices.TRUE.lower(): return True elif val.lower() == Choices.FALSE.lower(): return False elif val.lower() == Choices.NONE.lower(): return None elif val == Choices.digital_archiving_policy_val("none"): return None if isinstance(val, list): if len(val) == 1: actual_val = interpret_special(val[0]) if not actual_val: return [] return val return val return val
class JournalSubject(Form): """ Subject classification entry - optional""" subject = DOAJSelectMultipleField('Subjects', [validators.Optional()], choices=Choices.subjects())
class Subject(Form): """ Subject classification entry """ subject = SelectMultipleField('Subjects', [validators.Optional()], choices=Choices.subjects())
class JournalInformation(Form): """All the bibliographic metadata associated with a journal in the DOAJ""" title = StringField('Journal Title', [validators.DataRequired()]) url = URLField('URL', [validators.DataRequired(), URLOptionalScheme()]) alternative_title = StringField('Alternative Title', [validators.Optional()]) pissn = StringField( 'Journal ISSN (print version)', [ OptionalIf('eissn'), validators.Regexp(regex=ISSN_REGEX, message=ISSN_ERROR) ], description= 'Only provide the print ISSN if your journal has one, otherwise leave this field blank. Write the ISSN with the hyphen "-" e.g. 1234-4321.', ) eissn = StringField( 'Journal ISSN (online version)', [ OptionalIf('pissn'), validators.Regexp(regex=ISSN_REGEX, message=ISSN_ERROR) ], description= 'Cannot be the same as the P-ISSN. Write the EISSN with the hyphen "-" e.g. 1234-4321.', ) publisher = StringField('Publisher', [validators.DataRequired()]) society_institution = StringField( 'Society or Institution', [validators.Optional()], description= 'The name of the Society or Institution that the journal belongs to', ) platform = StringField( 'Platform, Host or Aggregator', [validators.Optional()], description= 'The name of the platform, host or aggregator of the journal content, e.g. OJS, HighWire Press, EBSCO etc.' ) contact_name = StringField( 'Name of contact for this journal', [validators.DataRequired()], description='Somebody who DOAJ can contact about this journal', ) contact_email = StringField('Contact\'s email address', [ validators.DataRequired(), validators.Email(message='Invalid email address.') ]) confirm_contact_email = StringField('Confirm contact\'s email address', [ validators.DataRequired(), validators.Email(message='Invalid email address.'), validators.EqualTo('contact_email', EMAIL_CONFIRM_ERROR) ]) country = SelectField( 'In which country is the publisher of the journal based?', [validators.DataRequired()], description= 'Select the country where the publishing company is legally registered', choices=Choices.country(), ) processing_charges = RadioField( 'Does the journal have article processing charges (APCs)?', [validators.DataRequired()], # description = 'If "No" proceed to question below', choices=Choices.processing_charges()) processing_charges_url = URLField( 'Enter the URL where this information can be found', [validators.DataRequired(), URLOptionalScheme()], # description='This field is optional if you have selected "No" above' ) processing_charges_amount = IntegerField( 'Amount', [ OptionalIf('processing_charges', optvals=Choices.processing_charges_amount_optional()) ], ) processing_charges_currency = SelectField( 'Currency', [ OptionalIf('processing_charges', optvals=Choices.processing_charges_currency_optional()) ], choices=Choices.currency(), ) submission_charges = RadioField( 'Does the journal have article submission charges?', [validators.DataRequired()], # description = 'If "No" proceed to question below', choices=Choices.submission_charges()) submission_charges_url = URLField( 'Enter the URL where this information can be found', [validators.DataRequired(), URLOptionalScheme()], # description='This field is optional if you have selected "No" above' ) submission_charges_amount = IntegerField( 'Amount', [ OptionalIf('submission_charges', optvals=Choices.submission_charges_amount_optional()) ], ) submission_charges_currency = SelectField( 'Currency', [ OptionalIf('submission_charges', optvals=Choices.submission_charges_amount_optional()) ], choices=Choices.currency(), ) waiver_policy = RadioField( 'Does the journal have a waiver policy (for developing country authors etc)?', [validators.DataRequired()], choices=Choices.waiver_policy()) waiver_policy_url = URLField( 'Enter the URL where this information can be found', [ OptionalIf('waiver_policy', optvals=Choices.waiver_policy_url_optional()), URLOptionalScheme() ]) digital_archiving_policy = SelectMultipleField( 'What digital archiving policy does the journal use?', [ validators.DataRequired(), ExclusiveCheckbox(Choices.digital_archiving_policy_val("none")), ExtraFieldRequiredIf( 'digital_archiving_policy_library', reqval=Choices.digital_archiving_policy_val("library")), ExtraFieldRequiredIf( 'digital_archiving_policy_other', reqval=Choices.digital_archiving_policy_val("other")), ], description= "Select all that apply. Institutional archives and publishers' own online archives are not valid", choices=Choices.digital_archiving_policy(), option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False)) digital_archiving_policy_other = StringField('', ) digital_archiving_policy_library = StringField('', ) digital_archiving_policy_url = URLField( 'Enter the URL where this information can be found', [ OptionalIf( 'digital_archiving_policy', optvals=Choices.digital_archiving_policy_url_optional()), URLOptionalScheme() ], description= 'This field is optional if you have only selected "No policy in place" above', ) crawl_permission = RadioField( 'Does the journal allow anyone to crawl the full-text of the journal?', [validators.DataRequired()], choices=Choices.crawl_permission()) article_identifiers = SelectMultipleField( 'Which article identifiers does the journal use?', [ validators.DataRequired(), ExtraFieldRequiredIf( 'article_identifiers_other', reqval=Choices.article_identifiers_val("other")), ExclusiveCheckbox() ], choices=Choices.article_identifiers(), option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False), ) article_identifiers_other = StringField('', ) download_statistics = RadioField( 'Does the journal provide article download statistics?', [validators.DataRequired()], description='If "No" proceed to question 32', choices=Choices.download_statistics()) download_statistics_url = StringField( 'Enter the URL where this information can be found', [validators.Optional()], ) first_fulltext_oa_year = IntegerField( 'What was the first calendar year in which a complete volume of the journal provided online Open Access content to the Full Text of all articles? (Full Text may be provided as PDFs. Does not apply for new journals.)', [ validators.DataRequired(), validators.NumberRange(min=1600, max=(datetime.now().year)) ], description='Use 4 digits for the year, i.e. YYYY format') fulltext_format = SelectMultipleField( 'Please indicate which formats of full text are available', [ validators.DataRequired(), ExtraFieldRequiredIf('fulltext_format_other', reqval=Choices.fulltext_format_val("other")) ], description='Tick all that apply', choices=Choices.fulltext_format(), option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False)) fulltext_format_other = StringField('', ) keywords = TagListField( 'Add keyword(s) that best describe the journal (comma delimited)', [ validators.DataRequired(), MaxLen(6, message='You can only enter up to {max_len} keywords.') ], description='Maximum 6. Keywords must be in English.') languages = SelectMultipleField( 'Select the language(s) that the Full Text of the articles is published in', [validators.DataRequired()], choices=Choices.language(), description="You can select multiple languages") editorial_board_url = URLField( 'What is the URL for the Editorial Board page?', [validators.DataRequired(), URLOptionalScheme()], description= 'The journal must have either an editor or an editorial board with at least 5 clearly identifiable members and affiliation information. We may ask for affiliation information and email addresses as part of our checks.' ) review_process = SelectField( 'Please select the review process for papers', [validators.DataRequired()], choices=Choices.review_process(), default=Choices.review_process_default(), ) review_process_url = URLField( 'Enter the URL where this information can be found', [ OptionalIf('review_process', optvals=Choices.review_process_url_optional()), URLOptionalScheme() ], description='This field is optional if you have selected "None" above.' ) aims_scope_url = URLField("What is the URL for the journal's Aims & Scope", [validators.DataRequired(), URLOptionalScheme()]) instructions_authors_url = URLField( "What is the URL for the journal's instructions for authors?", [validators.DataRequired(), URLOptionalScheme()]) plagiarism_screening = RadioField( 'Does the journal have a policy of screening for plagiarism?', [validators.DataRequired()], description='If "No" proceed to question 43', choices=Choices.plagiarism_screening()) plagiarism_screening_url = URLField( "Enter the URL where this information can be found", [ OptionalIf('plagiarism_screening', optvals=Choices.plagiarism_screening_url_optional()), URLOptionalScheme() ]) publication_time = IntegerField( 'What is the average number of weeks between submission and publication?', [validators.DataRequired(), validators.NumberRange(min=0, max=53)]) oa_statement_url = URLField( "What is the URL for the journal's Open Access statement?", [validators.DataRequired(), URLOptionalScheme()]) license_embedded = RadioField( 'Does the journal embed or display simple machine-readable CC licensing information in its articles?', [validators.DataRequired()], choices=Choices.licence_embedded(), description= 'For more information go to <a target="_blank" href="http://wiki.creativecommons.org/CC_REL">http://wiki.creativecommons.org/CC_REL</a><br><br>If "No" proceed to question 47.', ) license_embedded_url = URLField( "Please provide a URL to an example page with embedded licensing information", [ OptionalIf('license_embedded', optvals=Choices.licence_embedded_url_optional()), URLOptionalScheme() ]) license = RadioField( 'Does the journal allow reuse and remixing of its content, in accordance with a CC license?', [ validators.DataRequired(), ExtraFieldRequiredIf('license_other', reqval=Choices.licence_val("other")) ], choices=Choices._licence, description= 'For more information go to <a href="http://creativecommons.org/licenses/" target="_blank">http://creativecommons.org/licenses/</a>' ) license_other = StringField('', ) license_checkbox = SelectMultipleField( 'Which of the following does the content require? (Tick all that apply.)', choices=Choices.licence_checkbox(), option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False), ) license_url = URLField( "Enter the URL on your site where your license terms are stated", [validators.Optional(), URLOptionalScheme()]) open_access = RadioField( "Does the journal allow readers to 'read, download, copy, distribute, print, search, or link to the full texts' of its articles?", [validators.DataRequired()], choices=Choices.open_access(), description= 'From the <a href="http://www.budapestopenaccessinitiative.org/read" target="_blank">Budapest Open Access Initiative\'s definition of Open Access</a>', ) deposit_policy = SelectMultipleField( 'With which deposit policy directory does the journal have a registered deposit policy?', [ validators.DataRequired(), ExtraFieldRequiredIf( 'deposit_policy_other', reqval=Choices.deposit_policy_other_val("other")), ExclusiveCheckbox() ], description='Select all that apply.', choices=Choices.deposit_policy(), option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False)) deposit_policy_other = StringField('', ) copyright = RadioField( 'Does the journal allow the author(s) to hold the copyright without restrictions?', [ validators.DataRequired(), ExtraFieldRequiredIf('copyright_other', reqval=Choices.copyright_other_val("other")) ], choices=Choices.copyright()) copyright_other = StringField('', ) copyright_url = URLField( 'Enter the URL where this information can be found', [ OptionalIf('copyright', optvals=Choices.copyright_url_optional()), URLOptionalScheme() ]) publishing_rights = RadioField( 'Will the journal allow the author(s) to retain publishing rights without restrictions?', [ validators.Required(), ExtraFieldRequiredIf( 'publishing_rights_other', reqval=Choices.publishing_rights_other_val("other")) ], choices=Choices.publishing_rights()) publishing_rights_other = StringField('', ) publishing_rights_url = URLField( 'Enter the URL where this information can be found', [ OptionalIf('publishing_rights', optvals=Choices.publishing_rights_url_optional()), URLOptionalScheme() ])
def obj2form(cls, obj): forminfo = {} bibjson = obj.bibjson() forminfo['title'] = bibjson.title forminfo['url'] = bibjson.get_single_url(urltype='homepage') forminfo['alternative_title'] = bibjson.alternative_title forminfo['pissn'] = listpop( bibjson.get_identifiers(idtype=bibjson.P_ISSN)) forminfo['eissn'] = listpop( bibjson.get_identifiers(idtype=bibjson.E_ISSN)) forminfo['publisher'] = bibjson.publisher forminfo['society_institution'] = bibjson.institution forminfo['platform'] = bibjson.provider forminfo['contact_name'] = listpop(obj.contacts(), {}).get('name') forminfo['contact_email'] = listpop(obj.contacts(), {}).get('email') forminfo['confirm_contact_email'] = forminfo['contact_email'] forminfo['country'] = bibjson.country apc = bibjson.apc if apc: forminfo['processing_charges'] = reverse_interpret_special(True) forminfo['processing_charges_currency'] = apc.get('currency') forminfo['processing_charges_amount'] = apc.get('average_price') else: forminfo['processing_charges'] = reverse_interpret_special(False) forminfo['processing_charges_url'] = bibjson.apc_url submission_charges = bibjson.submission_charges if submission_charges: forminfo['submission_charges'] = reverse_interpret_special(True) forminfo['submission_charges_currency'] = submission_charges.get( 'currency') forminfo['submission_charges_amount'] = submission_charges.get( 'average_price') else: forminfo['submission_charges'] = reverse_interpret_special(False) forminfo['submission_charges_url'] = bibjson.submission_charges_url forminfo['waiver_policy_url'] = bibjson.get_single_url( urltype='waiver_policy') forminfo['waiver_policy'] = reverse_interpret_special( forminfo['waiver_policy_url'] is not None and forminfo['waiver_policy_url'] != '') #archiving_policies = reverse_interpret_special(bibjson.archiving_policy.get('policy', []), field='digital_archiving_policy') #substitutions = [ # {"default": Choices.digital_archiving_policy_val("library"), "field" : "digital_archiving_policy_library" }, # {"default": Choices.digital_archiving_policy_val("other"), "field" : "digital_archiving_policy_other"} #] #archiving_policies, special_fields = interpret_list( # archiving_policies, # current values # Choices.digital_archiving_policy_list(), # allowed values # substitutions # substitution instructions #) #forminfo.update(special_fields) # checkboxes archiving_policies = reverse_interpret_special( bibjson.archiving_policy.get('policy', []), field='digital_archiving_policy') # for backwards compatibility we keep the "Other" field first in the reverse xwalk # previously we didn't store which free text value was which (Other, or specific national library) # so in those cases, just put it in "Other", it'll be correct most of the time archiving_policies, forminfo['digital_archiving_policy_other'] = \ reverse_interpret_other(archiving_policies, Choices.digital_archiving_policy_list()) archiving_policies, forminfo['digital_archiving_policy_library'] = \ reverse_interpret_other( archiving_policies, Choices.digital_archiving_policy_list(), other_value=Choices.digital_archiving_policy_val("library"), replace_label=Choices.digital_archiving_policy_label("library") ) forminfo['digital_archiving_policy'] = archiving_policies forminfo[ 'digital_archiving_policy_url'] = bibjson.archiving_policy.get( 'url') forminfo['crawl_permission'] = reverse_interpret_special( bibjson.allows_fulltext_indexing) # checkboxes article_ids = reverse_interpret_special( bibjson.persistent_identifier_scheme) article_ids, forminfo['article_identifiers_other'] = \ reverse_interpret_other(article_ids, Choices.article_identifiers_list()) forminfo['article_identifiers'] = article_ids forminfo['download_statistics'] = reverse_interpret_special( bibjson.article_statistics.get('statistics')) forminfo['download_statistics_url'] = bibjson.article_statistics.get( 'url') forminfo['first_fulltext_oa_year'] = bibjson.oa_start.get('year') # checkboxes forminfo['fulltext_format'], forminfo['fulltext_format_other'] = \ reverse_interpret_other(bibjson.format, Choices.fulltext_format_list()) forminfo['keywords'] = bibjson.keywords forminfo['languages'] = bibjson.language forminfo['editorial_board_url'] = bibjson.get_single_url( 'editorial_board') forminfo['review_process'] = bibjson.editorial_review.get( 'process', '') forminfo['review_process_url'] = bibjson.editorial_review.get('url') forminfo['aims_scope_url'] = bibjson.get_single_url('aims_scope') forminfo['instructions_authors_url'] = bibjson.get_single_url( 'author_instructions') forminfo['plagiarism_screening'] = reverse_interpret_special( bibjson.plagiarism_detection.get('detection')) forminfo[ 'plagiarism_screening_url'] = bibjson.plagiarism_detection.get( 'url') forminfo['publication_time'] = bibjson.publication_time forminfo['oa_statement_url'] = bibjson.get_single_url('oa_statement') license = bibjson.get_license() license = license if license else {} # reinterpret the None val forminfo['license'], forminfo[ 'license_other'] = reverse_interpret_other(license.get('type'), Choices.licence_list()) if forminfo['license_other']: forminfo['license_checkbox'] = [] if license.get('BY'): forminfo['license_checkbox'].append('BY') if license.get('SA'): forminfo['license_checkbox'].append('SA') if license.get('NC'): forminfo['license_checkbox'].append('NC') if license.get('ND'): forminfo['license_checkbox'].append('ND') forminfo['license_url'] = license.get('url') forminfo['open_access'] = reverse_interpret_special( license.get('open_access')) forminfo['license_embedded'] = reverse_interpret_special( license.get('embedded')) forminfo['license_embedded_url'] = license.get('embedded_example_url') # checkboxes forminfo['deposit_policy'], forminfo['deposit_policy_other'] = \ reverse_interpret_other(reverse_interpret_special(bibjson.deposit_policy), Choices.deposit_policy_list()) forminfo['copyright'], forminfo['copyright_other'] = \ reverse_interpret_other( reverse_interpret_special(bibjson.author_copyright.get('copyright', '')), Choices.ternary_list() ) forminfo['copyright_url'] = bibjson.author_copyright.get('url') forminfo['publishing_rights'], forminfo['publishing_rights_other'] = \ reverse_interpret_other( reverse_interpret_special(bibjson.author_publishing_rights.get('publishing_rights', '')), Choices.ternary_list() ) forminfo[ 'publishing_rights_url'] = bibjson.author_publishing_rights.get( 'url') forminfo['notes'] = obj.notes() forminfo['subject'] = [] for s in bibjson.subjects(): forminfo['subject'].append(s['code']) forminfo['owner'] = obj.owner if obj.editor_group is not None: forminfo['editor_group'] = obj.editor_group if obj.editor is not None: forminfo['editor'] = obj.editor # old fields - only show them if the values actually exist in the journal record if bibjson.author_pays: forminfo['author_pays'] = bibjson.author_pays if bibjson.author_pays_url: forminfo['author_pays_url'] = bibjson.author_pays_url if bibjson.oa_end: forminfo['oa_end_year'] = bibjson.oa_end.get('year') return forminfo
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
def __init__(self): super(BasicJournalInformationRenderer, self).__init__() # allow the subclass to define the order the groups should be considered in. This is useful for # numbering questions and determining first errors self.NUMBERING_ORDER = ["basic_info", "editorial_process", "openness", "content_licensing", "copyright"] self.ERROR_CHECK_ORDER = deepcopy(self.NUMBERING_ORDER) # define the basic field groups self.FIELD_GROUPS = { "basic_info" : [ {"title" : {"class": "input-xlarge"}}, {"url" : {"class": "input-xlarge"}}, {"alternative_title" : {"class": "input-xlarge"}}, {"pissn" : {"class": "input-small", "size": "9", "maxlength": "9"}}, {"eissn" : {"class": "input-small", "size": "9", "maxlength": "9"}}, {"publisher" : {"class": "input-xlarge"}}, {"society_institution" : {"class": "input-xlarge"}}, {"platform" : {"class": "input-xlarge"}}, {"contact_name" : {}}, {"contact_email" : {}}, {"confirm_contact_email" : {}}, {"country" : {"class": "input-large"}}, {"processing_charges" : {}}, {"processing_charges_url" : {"class": "input-xlarge"}}, {"processing_charges_amount" : {"class": "input-mini"}}, {"processing_charges_currency" : {"class": "input-large"}}, {"submission_charges" : {}}, {"submission_charges_url" : {"class": "input-xlarge"}}, {"submission_charges_amount" : {"class": "input-mini"}}, {"submission_charges_currency" : {"class": "input-large"}}, {"waiver_policy" : {}}, {"waiver_policy_url" : {"class": "input-xlarge"}}, { "digital_archiving_policy" : { "extra_input_fields" : { Choices.digital_archiving_policy_val("other") : "digital_archiving_policy_other", Choices.digital_archiving_policy_val("library") : "digital_archiving_policy_library" } } }, {"digital_archiving_policy_url" : {"class": "input-xlarge"}}, {"crawl_permission" : {}}, { "article_identifiers" : { "extra_input_fields": { Choices.article_identifiers_val("other") : "article_identifiers_other" } } }, {"download_statistics" : {}}, {"download_statistics_url" : {"class": "input-xlarge"}}, {"first_fulltext_oa_year" : {"class": "input-mini"}}, { "fulltext_format" : { "extra_input_fields": { Choices.fulltext_format_val("other") : "fulltext_format_other" } } }, {"keywords" : {"class": "input-xlarge"}}, {"languages" : {"class": "input-xlarge"}} ], "editorial_process" : [ {"editorial_board_url" : {"class": "input-xlarge"}}, {"review_process" : {}}, {"review_process_url" : {"class": "input-xlarge"}}, {"aims_scope_url" : {"class": "input-xlarge"}}, {"instructions_authors_url" : {"class": "input-xlarge"}}, {"plagiarism_screening" : {}}, {"plagiarism_screening_url" : {"class": "input-xlarge"}}, {"publication_time" : {"class": "input-tiny"}} ], "openness" : [ {"oa_statement_url" : {"class": "input-xlarge"}} ], "content_licensing" : [ {"license_embedded" : {}}, {"license_embedded_url" : {"class": "input-xlarge"}}, { "license" : { "extra_input_fields": { Choices.licence_val("other") : "license_other" } } }, {"license_checkbox" : {}}, {"license_url" : {"class": "input-xlarge"}}, {"open_access" : {}}, { "deposit_policy" : { "extra_input_fields": { Choices.open_access_val("other") : "deposit_policy_other" } } } ], "copyright" : [ { "copyright" : {} }, {"copyright_url" : {"class": "input-xlarge"}}, { "publishing_rights" : {} }, {"publishing_rights_url" : {"class": "input-xlarge"}} ] }
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
def __init__(self): super(BasicJournalInformationRenderer, self).__init__() # allow the subclass to define the order the groups should be considered in. This is useful for # numbering questions and determining first errors self.NUMBERING_ORDER = [ "basic_info", "editorial_process", "openness", "content_licensing", "copyright" ] self.ERROR_CHECK_ORDER = deepcopy(self.NUMBERING_ORDER) # define the basic field groups self.FIELD_GROUPS = { "basic_info": [{ "title": { "class": "input-xlarge" } }, { "url": { "class": "input-xlarge" } }, { "alternative_title": { "class": "input-xlarge" } }, { "pissn": { "class": "input-small", "size": "9", "maxlength": "9" } }, { "eissn": { "class": "input-small", "size": "9", "maxlength": "9" } }, { "publisher": { "class": "input-xlarge" } }, { "society_institution": { "class": "input-xlarge" } }, { "platform": { "class": "input-xlarge" } }, { "contact_name": {} }, { "contact_email": {} }, { "confirm_contact_email": {} }, { "country": { "class": "input-large" } }, { "processing_charges": {} }, { "processing_charges_url": { "class": "input-xlarge" } }, { "processing_charges_amount": { "class": "input-mini" } }, { "processing_charges_currency": { "class": "input-large" } }, { "submission_charges": {} }, { "submission_charges_url": { "class": "input-xlarge" } }, { "submission_charges_amount": { "class": "input-mini" } }, { "submission_charges_currency": { "class": "input-large" } }, { "waiver_policy": {} }, { "waiver_policy_url": { "class": "input-xlarge" } }, { "digital_archiving_policy": { "extra_input_fields": { Choices.digital_archiving_policy_val("other"): "digital_archiving_policy_other", Choices.digital_archiving_policy_val("library"): "digital_archiving_policy_library" } } }, { "digital_archiving_policy_url": { "class": "input-xlarge" } }, { "crawl_permission": {} }, { "article_identifiers": { "extra_input_fields": { Choices.article_identifiers_val("other"): "article_identifiers_other" } } }, { "download_statistics": {} }, { "download_statistics_url": { "class": "input-xlarge" } }, { "first_fulltext_oa_year": { "class": "input-mini" } }, { "fulltext_format": { "extra_input_fields": { Choices.fulltext_format_val("other"): "fulltext_format_other" } } }, { "keywords": { "class": "input-xlarge" } }, { "languages": { "class": "input-xlarge" } }], "editorial_process": [{ "editorial_board_url": { "class": "input-xlarge" } }, { "review_process": { "class": "form-control input-xlarge" } }, { "review_process_url": { "class": "input-xlarge" } }, { "aims_scope_url": { "class": "input-xlarge" } }, { "instructions_authors_url": { "class": "input-xlarge" } }, { "plagiarism_screening": {} }, { "plagiarism_screening_url": { "class": "input-xlarge" } }, { "publication_time": { "class": "input-tiny" } }], "openness": [{ "oa_statement_url": { "class": "input-xlarge" } }], "content_licensing": [{ "license_embedded": {} }, { "license_embedded_url": { "class": "input-xlarge" } }, { "license": { "extra_input_fields": { Choices.licence_val("other"): "license_other" } } }, { "license_checkbox": {} }, { "license_url": { "class": "input-xlarge" } }, { "open_access": {} }, { "deposit_policy": { "extra_input_fields": { Choices.open_access_val("other"): "deposit_policy_other" } } }], "copyright": [{ "copyright": {} }, { "copyright_url": { "class": "input-xlarge" } }, { "publishing_rights": {} }, { "publishing_rights_url": { "class": "input-xlarge" } }] }
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
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
def obj2form(cls, obj): forminfo = {} bibjson = obj.bibjson() forminfo['title'] = bibjson.title forminfo['url'] = bibjson.get_single_url(urltype='homepage') forminfo['alternative_title'] = bibjson.alternative_title forminfo['pissn'] = listpop(bibjson.get_identifiers(idtype=bibjson.P_ISSN)) forminfo['eissn'] = listpop(bibjson.get_identifiers(idtype=bibjson.E_ISSN)) forminfo['publisher'] = bibjson.publisher forminfo['society_institution'] = bibjson.institution forminfo['platform'] = bibjson.provider forminfo['contact_name'] = listpop(obj.contacts(), {}).get('name') forminfo['contact_email'] = listpop(obj.contacts(), {}).get('email') forminfo['confirm_contact_email'] = forminfo['contact_email'] forminfo['country'] = bibjson.country apc = bibjson.apc if apc: forminfo['processing_charges'] = reverse_interpret_special(True) forminfo['processing_charges_currency'] = apc.get('currency') forminfo['processing_charges_amount'] = apc.get('average_price') else: forminfo['processing_charges'] = reverse_interpret_special(False) forminfo['processing_charges_url'] = bibjson.apc_url submission_charges = bibjson.submission_charges if submission_charges: forminfo['submission_charges'] = reverse_interpret_special(True) forminfo['submission_charges_currency'] = submission_charges.get('currency') forminfo['submission_charges_amount'] = submission_charges.get('average_price') else: forminfo['submission_charges'] = reverse_interpret_special(False) forminfo['submission_charges_url'] = bibjson.submission_charges_url forminfo['waiver_policy_url'] = bibjson.get_single_url(urltype='waiver_policy') forminfo['waiver_policy'] = reverse_interpret_special(forminfo['waiver_policy_url'] is not None and forminfo['waiver_policy_url'] != '') #archiving_policies = reverse_interpret_special(bibjson.archiving_policy.get('policy', []), field='digital_archiving_policy') #substitutions = [ # {"default": Choices.digital_archiving_policy_val("library"), "field" : "digital_archiving_policy_library" }, # {"default": Choices.digital_archiving_policy_val("other"), "field" : "digital_archiving_policy_other"} #] #archiving_policies, special_fields = interpret_list( # archiving_policies, # current values # Choices.digital_archiving_policy_list(), # allowed values # substitutions # substitution instructions #) #forminfo.update(special_fields) # checkboxes archiving_policies = reverse_interpret_special(bibjson.archiving_policy.get('policy', []), field='digital_archiving_policy') # for backwards compatibility we keep the "Other" field first in the reverse xwalk # previously we didn't store which free text value was which (Other, or specific national library) # so in those cases, just put it in "Other", it'll be correct most of the time archiving_policies, forminfo['digital_archiving_policy_other'] = \ reverse_interpret_other(archiving_policies, Choices.digital_archiving_policy_list()) archiving_policies, forminfo['digital_archiving_policy_library'] = \ reverse_interpret_other( archiving_policies, Choices.digital_archiving_policy_list(), other_value=Choices.digital_archiving_policy_val("library"), replace_label=Choices.digital_archiving_policy_label("library") ) forminfo['digital_archiving_policy'] = archiving_policies forminfo['digital_archiving_policy_url'] = bibjson.archiving_policy.get('url') forminfo['crawl_permission'] = reverse_interpret_special(bibjson.allows_fulltext_indexing) # checkboxes article_ids = reverse_interpret_special(bibjson.persistent_identifier_scheme) article_ids, forminfo['article_identifiers_other'] = \ reverse_interpret_other(article_ids, Choices.article_identifiers_list()) forminfo['article_identifiers'] = article_ids forminfo['download_statistics'] = reverse_interpret_special(bibjson.article_statistics.get('statistics')) forminfo['download_statistics_url'] = bibjson.article_statistics.get('url') forminfo['first_fulltext_oa_year'] = bibjson.oa_start.get('year') # checkboxes forminfo['fulltext_format'], forminfo['fulltext_format_other'] = \ reverse_interpret_other(bibjson.format, Choices.fulltext_format_list()) forminfo['keywords'] = bibjson.keywords forminfo['languages'] = bibjson.language forminfo['editorial_board_url'] = bibjson.get_single_url('editorial_board') forminfo['review_process'] = bibjson.editorial_review.get('process', '') forminfo['review_process_url'] = bibjson.editorial_review.get('url') forminfo['aims_scope_url'] = bibjson.get_single_url('aims_scope') forminfo['instructions_authors_url'] = bibjson.get_single_url('author_instructions') forminfo['plagiarism_screening'] = reverse_interpret_special(bibjson.plagiarism_detection.get('detection')) forminfo['plagiarism_screening_url'] = bibjson.plagiarism_detection.get('url') forminfo['publication_time'] = bibjson.publication_time forminfo['oa_statement_url'] = bibjson.get_single_url('oa_statement') license = bibjson.get_license() license = license if license else {} # reinterpret the None val forminfo['license'], forminfo['license_other'] = reverse_interpret_other(license.get('type'), Choices.licence_list()) if forminfo['license_other']: forminfo['license_checkbox'] = [] if license.get('BY'): forminfo['license_checkbox'].append('BY') if license.get('SA'): forminfo['license_checkbox'].append('SA') if license.get('NC'): forminfo['license_checkbox'].append('NC') if license.get('ND'): forminfo['license_checkbox'].append('ND') forminfo['license_url'] = license.get('url') forminfo['open_access'] = reverse_interpret_special(license.get('open_access')) forminfo['license_embedded'] = reverse_interpret_special(license.get('embedded')) forminfo['license_embedded_url'] = license.get('embedded_example_url') # checkboxes forminfo['deposit_policy'], forminfo['deposit_policy_other'] = \ reverse_interpret_other(reverse_interpret_special(bibjson.deposit_policy), Choices.deposit_policy_list()) forminfo['copyright'], forminfo['copyright_other'] = \ reverse_interpret_other( reverse_interpret_special(bibjson.author_copyright.get('copyright', '')), Choices.ternary_list() ) forminfo['copyright_url'] = bibjson.author_copyright.get('url') forminfo['publishing_rights'], forminfo['publishing_rights_other'] = \ reverse_interpret_other( reverse_interpret_special(bibjson.author_publishing_rights.get('publishing_rights', '')), Choices.ternary_list() ) forminfo['publishing_rights_url'] = bibjson.author_publishing_rights.get('url') forminfo['notes'] = obj.notes() forminfo['subject'] = [] for s in bibjson.subjects(): forminfo['subject'].append(s['code']) forminfo['owner'] = obj.owner if obj.editor_group is not None: forminfo['editor_group'] = obj.editor_group if obj.editor is not None: forminfo['editor'] = obj.editor # old fields - only show them if the values actually exist in the journal record if bibjson.author_pays: forminfo['author_pays'] = bibjson.author_pays if bibjson.author_pays_url: forminfo['author_pays_url'] = bibjson.author_pays_url if bibjson.oa_end: forminfo['oa_end_year'] = bibjson.oa_end.get('year') return forminfo