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
98 lines (84 loc) · 2.54 KB
/
models.py
File metadata and controls
98 lines (84 loc) · 2.54 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
from django.db import models
from django.utils.translation import gettext_lazy as _
from core.models import CommonControlField
from collection.models import Collection
class Journal(CommonControlField):
collection = models.ForeignKey(
Collection,
verbose_name=_('Collection'),
on_delete=models.CASCADE,
blank=False,
null=False,
)
scielo_issn = models.CharField(
verbose_name=_('SciELO ISSN'),
max_length=9,
blank=False,
null=False,
)
issns = models.JSONField(
verbose_name=_('ISSNs'),
null=True,
blank=True,
default=dict,
)
acronym = models.CharField(
verbose_name=_('Journal Acronym'),
max_length=32,
blank=True,
null=True,
default='',
)
title = models.CharField(
verbose_name=_('Journal Title'),
max_length=255,
blank=False,
null=False,
)
publisher_name = models.JSONField(
verbose_name=_('Publisher Name'),
blank=True,
null=True,
default=list,
)
subject_areas = models.JSONField(
verbose_name=_('Subject Areas (CAPES)'),
null=False,
blank=False,
default=list,
)
wos_subject_areas = models.JSONField(
verbose_name=_('Subject Areas (WoS)'),
null=False,
blank=False,
default=list,
)
def __str__(self):
return f'{self.collection.acron2} - {self.scielo_issn} - {self.acronym}'
@classmethod
def metadata(cls, collection=None):
queryset = cls.objects.all()
if collection:
queryset = queryset.filter(collection=collection)
for journal in queryset.only(
'acronym', 'collection__acron3', 'issns', 'publisher_name',
'scielo_issn', 'subject_areas', 'title', 'wos_subject_areas'
):
yield {
'acronym': journal.acronym,
'collection': journal.collection.acron3,
'issns': set([v for v in journal.issns.values() if v]),
'publisher_name': journal.publisher_name,
'scielo_issn': journal.scielo_issn,
'subject_areas': journal.subject_areas,
'title': journal.title,
'wos_subject_areas': journal.wos_subject_areas,
}
class Meta:
verbose_name = _('Journal')
verbose_name_plural = _('Journals')
unique_together = (
'collection',
'scielo_issn',
'acronym',
)