models.py 1.59 KB
Newer Older
1
2
3
4
5
6
7
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone

from os import path
from django.conf import settings

Odair M.'s avatar
Odair M. committed
8
from degree.models import Degree 
Jomaro Rodrigues's avatar
Jomaro Rodrigues committed
9

Jomaro Rodrigues's avatar
Jomaro Rodrigues committed
10

11
12
13
14
15
def get_path(instance, filename):
    return '{}/{}/{}'.format(instance.course, instance.id, filename)


class Submission(models.Model):
Jomaro Rodrigues's avatar
Jomaro Rodrigues committed
16
17
18
19
20
21
22
23
    STATUS_ONGOING = 0
    STATUS_FINISHED = 1

    STATUS = (
        (STATUS_ONGOING, 'Em andamento'),
        (STATUS_FINISHED, 'Terminado'),
    )

24
25
26
27
28
    author = models.ForeignKey(User)

    historico = models.FileField(upload_to=get_path)
    matricula = models.FileField(upload_to=get_path)

Odair M.'s avatar
Odair M. committed
29
    degree = models.ForeignKey(Degree)
30
31
32
33
34
35
36

    timestamp = models.DateTimeField(default=timezone.now)

    last = models.BooleanField(default=True)

    processed = models.BooleanField(default=False)

37
38
    process_time = models.IntegerField(null=True)

Jomaro Rodrigues's avatar
Jomaro Rodrigues committed
39
40
41
42
43
44
45
46
    relative_year = models.IntegerField(null=True)

    relative_semester = models.IntegerField(null=True)

    semester_status = models.IntegerField(null=True, choices=STATUS)

    done_in = models.DateTimeField(null=True)

47
    def path(self):
Odair M.'s avatar
Odair M. committed
48
        return path.join(settings.MEDIA_ROOT, self.degree.code, str(self.id))
49
50
51

    def __str__(self):
        return 'Submission (from: {}, to: {}, on: {})'.format(self.author.first_name,
Odair M.'s avatar
Odair M. committed
52
                                                              self.degree.name,
Jomaro Rodrigues's avatar
Jomaro Rodrigues committed
53
54
55
56
57
58
59
60
                                                              self.timestamp)

    def set_done(self, time):
        self.processed = True
        self.process_time = time
        self.done_in = timezone.now()

        self.save()