forked from scieloorg/usage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
143 lines (124 loc) · 3.5 KB
/
models.py
File metadata and controls
143 lines (124 loc) · 3.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from django.db import models
from django.utils.translation import gettext_lazy as _
from core.models import CommonControlField
from collection.models import Collection
class Article(CommonControlField):
collection = models.ForeignKey(
Collection,
verbose_name=_('Collection'),
on_delete=models.CASCADE,
blank=False,
null=False,
db_index=True,
)
scielo_issn = models.CharField(
verbose_name=_('SciELO ISSN'),
max_length=9,
blank=False,
null=False,
db_index=True,
)
pid_v2 = models.CharField(
verbose_name=_('PID V2'),
max_length=23,
blank=False,
null=False,
db_index=True,
)
pid_v3 = models.CharField(
verbose_name=_('PID V3'),
max_length=23,
blank=True,
null=True,
db_index=True,
)
pid_generic = models.CharField(
verbose_name=_('PID Generic'),
max_length=50,
blank=True,
null=True,
db_index=True,
)
files = models.JSONField(
verbose_name=_('Files'),
null=True,
blank=True,
default=dict,
)
default_lang = models.CharField(
verbose_name=_('Default Language'),
max_length=2,
blank=False,
null=False,
)
text_langs = models.JSONField(
verbose_name=_('Text Languages'),
null=True,
blank=True,
default=dict,
)
processing_date = models.CharField(
verbose_name=_('Processing Date'),
max_length=32,
null=False,
blank=False,
)
publication_date = models.CharField(
verbose_name=_('Publication Date'),
max_length=32,
null=False,
blank=False,
)
publication_year = models.CharField(
verbose_name=_('Publication Year'),
max_length=4,
null=False,
blank=False,
db_index=True,
)
def __str__(self):
return f'{self.collection.acron3} - {self.scielo_issn} - {self.pid_v2 or self.pid_v3 or self.pid_generic}'
@classmethod
def metadata(cls, collection=None):
qs = cls.objects.select_related('collection').only(
'collection__acron3',
'default_lang',
'files',
'pid_v2',
'pid_v3',
'pid_generic',
'processing_date',
'publication_date',
'publication_year',
'scielo_issn',
'text_langs',
)
if collection:
qs = qs.filter(collection=collection)
for a in qs.iterator():
yield {
'collection': a.collection.acron3,
'default_lang': a.default_lang,
'files': a.files,
'pid_v2': a.pid_v2,
'pid_v3': a.pid_v3,
'pid_generic': a.pid_generic,
'processing_date': a.processing_date,
'publication_date': a.publication_date,
'publication_year': a.publication_year,
'scielo_issn': a.scielo_issn,
'text_langs': a.text_langs,
}
class Meta:
verbose_name = _('Article')
verbose_name_plural = _('Articles')
unique_together = (
'collection',
'scielo_issn',
'pid_v2',
'pid_v3',
'pid_generic',
)
indexes = [
models.Index(fields=['collection', 'scielo_issn'], name='collection_scielo_issn_idx'),
]