-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
131 lines (108 loc) · 3.59 KB
/
models.py
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
from django.db import models
from django.utils import timezone
class WordPressImport(models.Model):
url = models.URLField(
help_text='Base URL eg. https://janeway.systems',
verbose_name='URL',
)
username = models.CharField(max_length=255)
password = models.CharField(max_length=255)
user = models.ForeignKey(
'core.Account',
on_delete=models.CASCADE,
help_text='News items will be '
'created with this user '
'as the owner.',
)
def __str__(self):
return 'Import from {url}'.format(url=self.url)
class ExportFile(models.Model):
article = models.ForeignKey(
'submission.Article',
on_delete=models.CASCADE,
)
file = models.ForeignKey(
'core.File',
on_delete=models.CASCADE,
)
journal = models.ForeignKey(
'journal.Journal',
on_delete=models.CASCADE,
)
class Meta:
unique_together = ('article', 'file', 'journal')
def __str__(self):
return '{} export file for {}'.format(
self.file,
self.article.title,
)
class CSVImport(models.Model):
filename = models.CharField(max_length=999)
created_articles = models.ManyToManyField(
to="submission.Article", blank=True,
through="imports.CSVImportUpdateArticle",
related_name="csv_import_creation",
)
updated_articles = models.ManyToManyField(
to="submission.Article", blank=True,
through="imports.CSVImportCreateArticle",
related_name="csv_import_updates",
)
def timestamp(self):
if self.created_articles.count() and self.csvimportcreatearticle_set.first():
return self.csvimportcreatearticle_set.first().imported
elif self.updated_articles.count() and self.csvimportupdatearticle_set.first():
return self.csvimportupdatearticle_set.first().imported
def __str__(self):
return f'{self.filename}'
class CSVImportCreateArticle(models.Model):
csv_import = models.ForeignKey(
"imports.CSVImport",
null=True,
on_delete=models.SET_NULL,
)
article = models.ForeignKey(
"submission.Article",
on_delete=models.CASCADE,
)
imported = models.DateTimeField(default=timezone.now)
file_id = models.CharField(max_length=999, blank=True, null=True)
class CSVImportUpdateArticle(CSVImportCreateArticle):
pass
class OJS3Section(models.Model):
"""Stores an ojs 3 section ID and maps it to the section in Janeway"""
ojs_id = models.IntegerField(
null=True,
blank=True,
)
ojs_ref = models.CharField(max_length=10, blank=True, null=True)
journal = models.ForeignKey('journal.Journal', on_delete=models.CASCADE)
section = models.ForeignKey(
'submission.Section', blank=True, null=True,
on_delete=models.CASCADE,
)
class Meta:
unique_together = (
('ojs_id', 'journal'),
('ojs_id', 'section'),
)
class OJSAccount(models.Model):
ojs_id = models.IntegerField()
journal = models.ForeignKey('journal.Journal', on_delete=models.CASCADE)
account = models.ForeignKey(
'core.Account',
blank=True,
null=True,
on_delete=models.SET_NULL,
)
class Meta:
unique_together = (
('ojs_id', 'journal', 'account'),
)
class OJSFile(models.Model):
ojs_id = models.IntegerField()
journal = models.ForeignKey('journal.Journal', on_delete=models.CASCADE)
file = models.ForeignKey(
'core.File',
on_delete=models.CASCADE,
)