-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.py
More file actions
175 lines (163 loc) · 5.88 KB
/
article.py
File metadata and controls
175 lines (163 loc) · 5.88 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import logging
from django.db import models
from model_utils import FieldTracker
logger = logging.getLogger(__name__)
class Article(models.Model):
"""
Represents an article in the Journal of Digital History.
Attributes:
abstract (OneToOneField): A one-to-one relationship with the Abstract model.
status (CharField): The current status of the article, with choices defined in the Status inner class.
tracker (FieldTracker): Tracks changes to the status field.
issue (ForeignKey): A foreign key relationship to the Issue model.
repository_url (URLField): The URL of the article's repository (e.g., GitHub).
repository_type (CharField): The type of repository, with choices defined in the RepositoryType inner class.
notebook_url (CharField): The URL of the article's preview.
notebook_ipython_url (URLField): The URL of the raw GitHub ipynb file.
notebook_commit_hash (CharField): The git commit hash of the notebook.
notebook_path (CharField): The file name of the notebook with .ipynb extension.
binder_url (URLField): The URL for Binder.
doi (CharField): The DOI received from ScholarOne.
dataverse_url (URLField): The URL for Dataverse.
publication_date (DateTimeField): The publication date of the article.
copyright_type (CharField): The type of copyright, with choices defined in the CopyrightType inner class.
data (JSONField): JSON data contents of the article.
fingerprint (JSONField): JSON fingerprint contents of the article.
citation (JSONField): JSON citation contents of the article.
tags (ManyToManyField): Tags associated with the article.
authors (ManyToManyField): Authors of the article, through the Role model.
Methods:
get_kernel_language(): Returns the kernel language based on the 'tool' tag.
__str__(): Returns the title of the abstract.
"""
class Status(models.TextChoices):
DRAFT = (
"DRAFT",
"Draft",
)
TECHNICAL_REVIEW = (
"TECHNICAL_REVIEW",
"Technical review",
)
PEER_REVIEW = (
"PEER_REVIEW",
"Peer review",
)
DESIGN_REVIEW = (
"DESIGN_REVIEW",
"Design review",
)
COPY_EDITING = (
"COPY_EDITING",
"Copy editing",
)
PUBLISHED = (
"PUBLISHED",
"Published",
)
class CopyrightType(models.TextChoices):
DRAFT = (
"DRAFT",
"Draft",
)
CC_BY = (
"CC_BY",
"CC-BY",
)
CC_BY_NC_ND = "CC_BY_NC_ND", "CC-BY-NC-ND"
class RepositoryType(models.TextChoices):
GITHUB = (
"GITHUB",
"Github",
)
GITLAB = (
"GITLAB",
"Gitlab",
)
abstract = models.OneToOneField(
"jdhapi.Abstract",
on_delete=models.CASCADE,
primary_key=True,
)
status = models.CharField(
max_length=25,
choices=Status.choices,
default=Status.DRAFT,
)
tracker = FieldTracker(fields=["status"])
issue = models.ForeignKey("jdhapi.Issue", on_delete=models.CASCADE)
repository_url = models.URLField(
max_length=254, null=True, blank=True, help_text="GitHub's repository URL "
)
repository_type = models.CharField(
max_length=15,
choices=RepositoryType.choices,
default=RepositoryType.GITHUB,
)
# Url of the article in the front
notebook_url = models.CharField(
max_length=254,
null=True,
blank=True,
help_text="Article's preview URL - All the caracters after the url : https://journalofdigitalhistory.org/en/notebook-viewer/",
)
# Json source from raw.github
notebook_ipython_url = models.URLField(
max_length=254, null=True, blank=True, help_text="Raw GitHub ipynb URL"
)
notebook_commit_hash = models.CharField(
max_length=22, default="", help_text="store the git hash", blank=True
)
notebook_path = models.CharField(
max_length=254,
null=True,
blank=True,
help_text="Notebook file name with .ipynb",
)
binder_url = models.URLField(max_length=254, null=True, blank=True)
doi = models.CharField(
max_length=254,
null=True,
blank=True,
help_text="Doi received from ScholarOne - 10.1515/JDH.YYYY.XXXX.RX",
)
dataverse_url = models.URLField(
max_length=200,
blank=True,
null=True,
help_text="Url to find here https://data.journalofdigitalhistory.org/",
)
publication_date = models.DateTimeField(blank=True, null=True)
copyright_type = models.CharField(
max_length=15,
choices=CopyrightType.choices,
default=CopyrightType.DRAFT,
)
data = models.JSONField(
verbose_name="data contents", help_text="JSON format", default=dict, blank=True
)
fingerprint = models.JSONField(
verbose_name="fingerprint contents",
help_text="JSON format",
default=dict,
blank=True,
)
citation = models.JSONField(
verbose_name="citation contents",
help_text="JSON format",
default=dict,
blank=True,
)
tags = models.ManyToManyField("jdhapi.Tag", blank=True)
authors = models.ManyToManyField("jdhapi.Author", through="Role")
ojs_submission_id = models.IntegerField(null=True, blank=True, default=None)
def get_kernel_language(self):
tool_tags = self.tags.filter(category="tool")
if tool_tags.exists():
first_tool_tag = tool_tags.first()
return first_tool_tag.data.get("language", "")
# Default language if no 'tool' tag or
# language field present
return ""
def __str__(self):
return self.abstract.title