-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
57 lines (46 loc) · 1.55 KB
/
forms.py
File metadata and controls
57 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django import forms
from plugins.datacite import models
from identifiers import models as im
from submission import models as sm
class DOIForm(forms.ModelForm):
findable = forms.BooleanField(
required=False,
initial=True,
help_text="Marks the DOI as findable. Uncheck to register a draft DOI."
)
class Meta:
model = im.Identifier
fields = ('identifier',)
def __init__(self, *args, **kwargs):
self.article = kwargs.pop('article')
self.id_type = 'doi'
super(DOIForm, self).__init__(*args, **kwargs)
def save(self, commit=True):
identifier = super(DOIForm, self).save(commit=False)
identifier.article = self.article
identifier.id_type = self.id_type
if commit:
identifier.save()
return identifier
class SectionMintForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.journal = kwargs.pop('request_journal', None)
super().__init__(*args, **kwargs)
if self.journal:
self.fields['sections'].queryset = sm.Section.objects.filter(
journal=self.journal,
)
def save(self, commit=True):
instance = super().save(commit=False)
if self.journal:
instance.journal = self.journal
if commit:
instance.save()
self.save_m2m()
return instance
class Meta:
model = models.SectionMint
fields = ['sections']
widgets = {
'sections': forms.CheckboxSelectMultiple,
}