models.py 4.53 KB
Newer Older
Jan's avatar
Jan committed
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
from django.conf import settings
from django.db import models
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from utils.snippets import datetime_to_lectureyear
from utils.translation import MultilingualField, ModelTranslateMeta


class Category(models.Model, metaclass=ModelTranslateMeta):
    name = MultilingualField(
        models.CharField,
        max_length=64,
    )

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('education:category', args=[str(self.pk)])

    class Meta:
        verbose_name = _('category')
        verbose_name_plural = _('categories')


class Course(models.Model, metaclass=ModelTranslateMeta):
    name = MultilingualField(
        models.CharField,
        max_length=255
    )

    categories = models.ManyToManyField(
        Category,
        verbose_name=_("categories"),
        blank=True
    )

    old_courses = models.ManyToManyField(
        'self',
        symmetrical=False,
        verbose_name=_("old courses"),
        blank=True
    )

    shorthand = MultilingualField(
        models.CharField,
        max_length=10
    )

    course_code = models.CharField(
        max_length=16
    )

    ec = models.IntegerField(
        verbose_name=_('EC')
    )

    since = models.IntegerField()
    until = models.IntegerField(
        blank=True
    )

    period = models.CharField(
        max_length=64,
        verbose_name=_('period'),
    )

    def __str__(self):
        return "{} ({})".format(self.name, self.course_code)

    def get_absolute_url(self):
        return reverse('education:course', args=[str(self.pk)])

    class Meta:
        verbose_name = _('course')
        verbose_name_plural = _('courses')


class Exam(models.Model):
    EXAM_TYPES = (
        ('document', _('Document')),
        ('exam', _('Exam')),
        ('partial', _('Partial Exam')),
        ('resit', _('Resit')),
        ('practice', _('Practice Exam')))

    type = models.CharField(
        max_length=40,
        choices=EXAM_TYPES,
        verbose_name=_('exam type'),
    )

    name = models.CharField(
        max_length=255,
        verbose_name=_('exam name'),
        blank=True
    )

    uploader = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name=_('uploader'),
Wietse Kuipers's avatar
Wietse Kuipers committed
103
        on_delete=models.CASCADE,
Jan's avatar
Jan committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    )

    uploader_date = models.DateField(
        default=timezone.now,
    )

    accepted = models.BooleanField(
        verbose_name=_('accepted'),
        default=False,
    )

    exam_date = models.DateField(
        verbose_name=_('exam date'),
    )

    file = models.FileField(
        upload_to="education/files/exams/"
    )

    course = models.ForeignKey(
        Course,
        verbose_name=_("course"),
Wietse Kuipers's avatar
Wietse Kuipers committed
126
        on_delete=models.CASCADE,
Jan's avatar
Jan committed
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
    )

    def __str__(self):
        return "{} {} ({}, {}, {})".format(self.name.capitalize(),
                                           self.type.capitalize(),
                                           self.course.name,
                                           self.course.course_code,
                                           self.exam_date)

    def get_absolute_url(self):
        return reverse('education:exam', args=[str(self.pk)])

    @property
    def year(self):
        return datetime_to_lectureyear(self.exam_date)

    class Meta:
        verbose_name = _('exam')
        verbose_name_plural = _('exams')


class Summary(models.Model):
    name = models.CharField(
        max_length=255,
        verbose_name=_('summary name'),
    )

    uploader = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name=_('uploader'),
Wietse Kuipers's avatar
Wietse Kuipers committed
157
        on_delete=models.CASCADE,
Jan's avatar
Jan committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    )

    uploader_date = models.DateField(
        default=timezone.now,
    )

    year = models.IntegerField()

    author = models.CharField(
        max_length=64,
        verbose_name=_("author"),
    )

    course = models.ForeignKey(
        Course,
        verbose_name=_("course"),
Wietse Kuipers's avatar
Wietse Kuipers committed
174
        on_delete=models.CASCADE,
Jan's avatar
Jan committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
    )

    accepted = models.BooleanField(
        verbose_name=_('accepted'),
        default=False,
    )

    file = models.FileField(
        upload_to="education/files/summary/"
    )

    def __str__(self):
        return "{} ({}, {}, {})".format(self.name, self.course.name,
                                        self.course.course_code, self.year)

    def get_absolute_url(self):
        return reverse('education:suma', args=[str(self.pk)])

    class Meta:
        verbose_name = _('summary')
        verbose_name_plural = _('summaries')