Coverage for portality/crosswalks/application_form.py: 61%

56 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-22 15:59 +0100

1from portality import models, lcc 

2from portality.crosswalks.journal_form import JournalGenericXWalk, JournalFormXWalk 

3 

4 

5class ApplicationFormXWalk(JournalGenericXWalk): 

6 """ 

7 ~~ApplicationForm:Crosswalk->Application:Model~~ 

8 ~~->Application:Form~~ 

9 """ 

10 _formFields2objectFields = { 

11 "alternative_title" : "bibjson.alternative_title", 

12 "apc_charges.apc_max" : "bibjson.apc.max.price", 

13 "apc_charges.apc_currency" : "bibjson.apc.max.currency", 

14 "apc_url" : "bibjson.apc.url", 

15 "preservation_service" : "bibjson.preservation.service", 

16 "preservation_service_other" : "bibjson.preservation.service", 

17 "preservation_service_library" : "bibjson.preservation.national_library", 

18 "preservation_service_url" : "bibjson.preservation.url", 

19 "copyright_author_retains" : "bibjson.copyright.author_retains", 

20 "copyright_url" : "bibjson.copyright.url", 

21 "publisher.publisher_country" : "bibjson.publisher.country", 

22 "deposit_policy" : "bibjson.deposit_policy.service", 

23 "deposit_policy_other" : "bibjson.deposit_policy.service", 

24 "review_process" : "bibjson.editorial.review_process", 

25 "review_process_other" : "bibjson.editorial.review_process", 

26 "review_url" : "bibjson.editorial.review_url", 

27 "pissn" : "bibjson.pissn", 

28 "eissn" : "bibjson.eissn", 

29 "institution.institution_name" : "bibjson.institution.name", 

30 "keywords" : "bibjson.keywords", 

31 "language" : "bibjson.language", 

32 "license_attributes" : (["bibjson.license.BY", "bibjson.license.NC", "bibjson.license.ND", "bibjson.license.SA"], 

33 "bibjson.license[].BY, NC, ND and SA"), 

34 "license_display" : "bibjson.article.license_display", 

35 "license_display_example_url" : "bibjson.article.license_display_example_url", 

36 "boai" : "bibjson.boai", 

37 "license" : "bibjson.license.type", 

38 "license_terms_url" : "bibjson.license.url", 

39 "oa_start": "bibjson.oa_start", 

40 "oa_statement_url" : "bibjson.ref.oa_statement", 

41 "journal_url" : "bibjson.ref.journal", 

42 "aims_scope_url" : "bibjson.ref.aims_scope", 

43 "editorial_board_url" : "bibjon.editorial.board_url", 

44 "author_instructions_url" : "bibjson.ref.author_instructions", 

45 "waiver_url" : "bibjson.waiver.url", 

46 "persistent_identifiers" : "bibjson.pid_scheme.scheme", 

47 "persistent_identifiers_other" : "bibjson.pid_scheme.scheme", 

48 "plagiarism_detection" : "bibjson.plagiarism.detection", 

49 "plagiarism_url" : "bibjson.plagiarism.url", 

50 "publication_time_weeks" : "bibjson.publication_time_weeks", 

51 "other_charges_url" : "bibjson.other_charges_url", 

52 "title" : "bibjson.title", 

53 "institution.institution_country" : "bibjson.institution.country", 

54 "apc" : "bibjson.apc.has_apc", 

55 "has_other_charges" : "bibjson.other_charges.has_other_charges", 

56 "has_waiver" : "bibjson.waiver.has_waiver", 

57 "orcid_ids" : "bibjson.article.orcid", 

58 "open_citations" : "bibjson.article.i4oc_open_citations", 

59 "deposit_policy_url" : "bibjson.deposit_policy.url" 

60 } 

61 

62 @classmethod 

63 def formField2objectField(cls, field): 

64 data = cls._formFields2objectFields.get(field, field) 

65 if isinstance(data, str): 

66 return data 

67 return data[1] 

68 

69 @classmethod 

70 def formField2objectFields(cls, field): 

71 data = cls._formFields2objectFields.get(field, field) 

72 if isinstance(data, str): 

73 return [data] 

74 fields = data[0] 

75 if not isinstance(fields, list): 

76 return [fields] 

77 return fields 

78 

79 @classmethod 

80 def form2obj(cls, form): 

81 application = models.Application() 

82 bibjson = application.bibjson() 

83 

84 cls.form2bibjson(form, bibjson) 

85 cls.form2admin(form, application) 

86 

87 # admin stuff 

88 if getattr(form, 'application_status', None): 

89 application.set_application_status(form.application_status.data) 

90 

91 return application 

92 

93 @classmethod 

94 def obj2formdata(cls, obj): 

95 forminfo = cls.obj2form(obj) 

96 return cls.forminfo2multidict(forminfo) 

97 

98 @classmethod 

99 def obj2form(cls, obj): 

100 forminfo = {} 

101 bibjson = obj.bibjson() 

102 

103 cls.bibjson2form(bibjson, forminfo) 

104 cls.admin2form(obj, forminfo) 

105 

106 forminfo['application_status'] = obj.application_status 

107 

108 return forminfo 

109 

110 @classmethod 

111 def update_request_diff(cls, source): 

112 """ 

113 ~~->Journal:Model~~ 

114 ~~->JournalForm:Crosswalk~~ 

115 ~~->UpdateRequest:Feature~~ 

116 :param source: 

117 :return: 

118 """ 

119 diff = None 

120 cj = None 

121 

122 current_journal = source.current_journal 

123 if current_journal is not None: 

124 cj = models.Journal.pull(current_journal) 

125 if cj is not None: 

126 jform = JournalFormXWalk.obj2form(cj) 

127 if "notes" in jform: 

128 del jform["notes"] 

129 aform = ApplicationFormXWalk.obj2form(source) 

130 if "notes" in aform: 

131 del aform["notes"] 

132 diff = cls.form_diff(jform, aform) 

133 

134 return diff, cj