Fakultas Ilmu Komputer UI

accounts.py 3.85 KB
Newer Older
1
2
3
4
5
import os
import uuid

from django.contrib.auth.models import User
from django.core.validators import MinValueValidator, MaxValueValidator
6
from django.db import models
7

8
9

def get_student_resume_file_path(instance, filename):
10
11
12
13
14
    extension = filename.split('.')[-1].lower()
    filename = "%s.%s" % (uuid.uuid4(), extension)
    return os.path.join("student-resume/", filename)


15
16
17
18
19
20
def get_student_photo_file_path(instance, filename):
    extension = filename.split('.')[-1].lower()
    filename = "%s.%s" % (uuid.uuid4(), extension)
    return os.path.join("student-photo/", filename)


21
22
23
24
25
26
def get_company_logo_file_path(instance, filename):
    extension = filename.split('.')[-1].lower()
    filename = "%s.%s" % (uuid.uuid4(), extension)
    return os.path.join("company-logo/", filename)


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
def get_display_name(user, full_name=False):
    """
    Return a display name that always works like "Benoit J."
    """
    if user.first_name and user.last_name:
        if full_name:
            last = user.last_name.title()
        else:
            last = user.last_name[:1].upper() + "."
        name = user.first_name.title() + " " + last
    elif user.first_name:
        name = user.first_name.title()
    elif user.last_name:
        name = user.last_name.title()
    else:
        name = user.username

    return name.strip()


class Student(models.Model):
    """
    A user subclass
    """
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user = models.OneToOneField(User)
    npm = models.IntegerField(validators=[MinValueValidator(100000000), MaxValueValidator(9999999999)], unique=True)
55
    resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True)
56
    phone_number = models.CharField(max_length=100, blank=True, db_index=True, null=True)
57
    bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True)
58
59
    applied_vacancies = models.ManyToManyField('core.Vacancy', related_name="applied_vacancies",
                                               blank=True, through='core.Application')
60
61
62
63
    birth_place = models.CharField(max_length=30, blank=True, null=True)
    birth_date = models.DateField(blank=True, null=True)
    major = models.CharField(max_length=30, blank=True, null=True)
    batch = models.CharField(max_length=4, blank=True, null=True)
64
    show_transcript = models.BooleanField(default=False)
65
    photo = models.FileField(upload_to=get_student_photo_file_path, null=True, blank=True)
66

Zamil Majdy's avatar
Zamil Majdy committed
67
68
69
70
    @property
    def name(self):
        return get_display_name(self.user)

71
72
73
74
    @property
    def full_name(self):
        return get_display_name(self.user, full_name=True)

75
76
77
78
79
80
81
82
83
84
85
86
87
    def __unicode__(self):
        return u"Student {}".format(get_display_name(self.user))


class Company(models.Model):
    """
    A user subclass
    """
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user = models.OneToOneField(User)
    description = models.TextField()
    verified = models.BooleanField(default=False)
88
    logo = models.FileField(upload_to=get_company_logo_file_path, null=True, blank=True)
89
    address = models.CharField(max_length=1000, blank=True, null=True)
90

Zamil Majdy's avatar
Zamil Majdy committed
91
92
93
94
    @property
    def name(self):
        return get_display_name(self.user)

95
96
97
98
99
100
101
102
103
104
105
106
107
    def __unicode__(self):
        return u"Company {}".format(get_display_name(self.user))


class Supervisor(models.Model):
    """
    A user subclass
    """
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user = models.OneToOneField(User)
    nip = models.IntegerField(validators=[MinValueValidator(100000000), MaxValueValidator(9999999999)], unique=True)

Zamil Majdy's avatar
Zamil Majdy committed
108
109
110
111
    @property
    def name(self):
        return get_display_name(self.user)

112
113
    def __unicode__(self):
        return u"Supervisor {}".format(get_display_name(self.user))