-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmodels.py
More file actions
310 lines (254 loc) · 8.72 KB
/
models.py
File metadata and controls
310 lines (254 loc) · 8.72 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
from django.core import exceptions
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
from model_utils import Choices
from model_utils.models import TimeStampedModel
from api.helpers.ids import encode_hashid
from i18n.fields import I18nCharField, I18nTextField
from .querysets import SubmissionQuerySet
class SubmissionTag(models.Model):
name = models.CharField(max_length=100, unique=True)
def __str__(self):
return self.name
class Submission(TimeStampedModel):
SPEAKER_LEVELS = Choices(
("new", _("New speaker")),
("intermediate", _("Intermediate experience")),
("experienced", _("Experienced")),
)
STATUS = Choices(
("proposed", _("Proposed")),
("accepted", _("Accepted")),
("waiting_list", _("Waiting list")),
("rejected", _("Rejected")),
("cancelled", _("Cancelled")),
)
NON_CANCELLED_STATUSES = [
STATUS.proposed,
STATUS.accepted,
STATUS.waiting_list,
STATUS.rejected,
]
conference = models.ForeignKey(
"conferences.Conference",
on_delete=models.CASCADE,
verbose_name=_("conference"),
related_name="submissions",
)
title = I18nCharField(_("title"))
abstract = I18nTextField(_("abstract"))
elevator_pitch = I18nTextField(_("elevator pitch"), default="", blank=True)
slug = models.SlugField(_("slug"), max_length=200)
notes = models.TextField(_("notes"), default="", blank=True, max_length=1000)
short_social_summary = models.TextField(
_("short social summary"), default="", blank=True, max_length=128
)
speaker_level = models.CharField(
_("speaker level"), choices=SPEAKER_LEVELS, max_length=20
)
previous_talk_video = models.URLField(
_("previous talk video"), blank=True, max_length=2049
)
speaker = models.ForeignKey(
"users.User",
on_delete=models.CASCADE,
null=False,
blank=False,
verbose_name=_("speaker"),
related_name="+",
)
topic = models.ForeignKey(
"conferences.Topic",
verbose_name=_("topic"),
null=True,
blank=True,
on_delete=models.PROTECT,
)
languages = models.ManyToManyField(
"languages.Language", verbose_name=_("languages")
)
type = models.ForeignKey(
"submissions.SubmissionType", verbose_name=_("type"), on_delete=models.PROTECT
)
duration = models.ForeignKey(
"conferences.Duration", verbose_name=_("duration"), on_delete=models.PROTECT
)
audience_level = models.ForeignKey(
"conferences.AudienceLevel",
verbose_name=_("audience level"),
on_delete=models.PROTECT,
)
tags = models.ManyToManyField("submissions.SubmissionTag", verbose_name=_("tags"))
status = models.CharField(
_("status"), choices=STATUS, max_length=20, default=STATUS.proposed
)
pending_status = models.CharField(
_("pending status"), choices=STATUS, max_length=20, null=True, blank=True
)
do_not_record = models.BooleanField(
_("do not record"),
default=False,
help_text=_("If true, the submission will not be recorded."),
)
objects = SubmissionQuerySet().as_manager()
@property
def hashid(self):
return encode_hashid(self.pk)
def can_edit(self, request):
return self.speaker_id == request.user.id
def clean(self):
if (
self.topic_id
and not self.conference.topics.filter(id=self.topic_id).exists()
):
raise exceptions.ValidationError(
{
"topic": _("%(topic)s is not a valid topic")
% {"topic": str(self.topic)}
}
)
if (
self.type_id
and not self.conference.submission_types.filter(id=self.type_id).exists()
):
raise exceptions.ValidationError(
{
"type": _("%(submission_type)s is not an allowed submission type")
% {"submission_type": str(self.type)}
}
)
if (
self.duration_id
and not self.conference.durations.filter(id=self.duration_id).exists()
):
raise exceptions.ValidationError(
{"duration": _(f"{str(self.duration)} is not an allowed duration type")}
)
if (
self.duration_id
and self.type_id
and not self.duration.allowed_submission_types.filter(
id=self.type_id
).exists()
):
raise exceptions.ValidationError(
{
"duration": _(
f"Duration {str(self.duration)} is not an allowed for "
f"the submission type {str(self.type)}"
)
}
)
if (
self.audience_level_id
and not self.conference.audience_levels.filter(
id=self.audience_level_id
).exists()
):
raise exceptions.ValidationError(
{
"audience_level": _(
"%(audience_level)s is not an allowed audience level"
)
% {"audience_level": str(self.audience_level)}
}
)
def get_admin_url(self):
return reverse(
"admin:%s_%s_change" % (self._meta.app_label, self._meta.model_name),
args=(self.pk,),
)
def save(self, *args, **kwargs):
update_fields = kwargs.get("update_fields", None)
if not self.slug:
self.slug = slugify(self.title.localize("en"))
if update_fields:
update_fields.append("slug")
super().save(*args, **kwargs)
@property
def current_or_pending_status(self):
return self.pending_status or self.status
def __str__(self):
return (
f"{self.title} at Conference {self.conference.name} "
f"<{self.conference.code}>"
)
class ProposalMaterial(TimeStampedModel):
proposal = models.ForeignKey(
"submissions.Submission",
on_delete=models.CASCADE,
verbose_name=_("proposal"),
related_name="materials",
)
name = models.CharField(_("name"), max_length=100)
url = models.URLField(_("url"), max_length=2049, blank=True, null=True)
file = models.ForeignKey(
"files_upload.File",
on_delete=models.CASCADE,
verbose_name=_("file"),
blank=True,
null=True,
)
def __str__(self):
return f"{self.name} for {self.proposal.title}"
class SubmissionType(models.Model):
name = models.CharField(max_length=100, unique=True)
is_recordable = models.BooleanField(
_("is recordable"),
default=True,
help_text=_("If true, the proposals of this type can be recorded."),
)
def __str__(self):
return self.name
class SubmissionComment(TimeStampedModel):
submission = models.ForeignKey(
"submissions.Submission",
on_delete=models.CASCADE,
verbose_name=_("submission"),
related_name="comments",
)
author = models.ForeignKey(
"users.User",
on_delete=models.CASCADE,
null=False,
blank=False,
verbose_name=_("author"),
related_name="+",
)
text = models.CharField(_("text"), max_length=500)
def get_admin_url(self):
return reverse(
"admin:%s_%s_change" % (self._meta.app_label, self._meta.model_name),
args=(self.pk,),
)
def __str__(self):
return f"{self.author_id} {self.submission.title}"
class Meta:
verbose_name = _("comment")
verbose_name_plural = _("comments")
class SubmissionConfirmPendingStatusProxy(Submission):
class Meta:
proxy = True
verbose_name = _("Submission Confirm Pending Status")
verbose_name_plural = _("Submissions Confirm Pending Status")
class CoSpeaker(TimeStampedModel):
submission = models.ForeignKey(
"submissions.Submission",
on_delete=models.CASCADE,
verbose_name=_("submission"),
related_name="co_speakers",
)
user = models.ForeignKey(
"users.User",
on_delete=models.CASCADE,
verbose_name=_("co-speaker"),
related_name="co_speaker_submissions",
)
def __str__(self):
return f"{self.user.email} as co-speaker for {self.submission.title}"
class Meta:
verbose_name = _("co-speaker")
verbose_name_plural = _("co-speakers")
unique_together = [["submission", "user"]]