Fakultas Ilmu Komputer UI

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

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

8
from core.lib.validators import validate_document_file_extension, validate_image_file_extension, validate_npm
9

10
11

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


17
18
19
20
21
22
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)


23
24
25
26
27
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)

28
29
30
31
32
def get_student_ui_ux_portofolio_file_path(instance, filename):
    extension = filename.split('.')[-1].lower()
    filename = "%s.%s" % (uuid.uuid4(), extension)
    return os.path.join("student-ui-ux-portofolio/", filename)

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
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)
61
    npm = models.IntegerField(validators=[validate_npm], unique=True)
62
    resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True, validators=[validate_document_file_extension])
63
    phone_number = models.CharField(max_length=12, blank=True, db_index=True, null=True, validators=[RegexValidator(r'^0\d{1,11}$')])
64
    bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True)
65
66
    applied_vacancies = models.ManyToManyField('core.Vacancy', related_name="applied_vacancies",
                                               blank=True, through='core.Application')
67
68
69
70
    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)
71
    show_transcript = models.BooleanField(default=False)
72
    photo = models.FileField(upload_to=get_student_photo_file_path, null=True, blank=True, validators=[validate_image_file_extension])
73
    linkedin_url = models.URLField(max_length=200,blank=True, null=True)
PRIAMBUDI LINTANG BAGASKARA's avatar
PRIAMBUDI LINTANG BAGASKARA committed
74
    region = models.CharField(max_length=30, blank=True, null=True)
75
    recommendations = models.CharField(max_length=500, blank=True, null=True)
76
    ui_ux_portofolio = models.FileField(upload_to=get_student_ui_ux_portofolio_file_path, null=True, blank=True, validators=[validate_document_file_extension])
77
78
    latest_work = models.CharField(max_length=100, blank=True, null=True)
    latest_work_desc = models.TextField(blank=True, null=True)
HANIF AGUNG PRAYOGA's avatar
HANIF AGUNG PRAYOGA committed
79
    intro = models.CharField(max_length=50, blank=True, null=True)
80
    volunteer = models.CharField(max_length=100, blank=True, null=True)
81

Zamil Majdy's avatar
Zamil Majdy committed
82
83
84
85
    @property
    def name(self):
        return get_display_name(self.user)

86
87
88
89
    @property
    def full_name(self):
        return get_display_name(self.user, full_name=True)

90
91
92
    def __unicode__(self):
        return u"Student {}".format(get_display_name(self.user))

93
94
95
    class Meta:
        ordering = ['-updated']

96
97
98
99
100

class Company(models.Model):
    """
    A user subclass
    """
101
102
103
104
    NEW = 0
    UNVERIFIED = 1
    VERIFIED = 2

105
106
107
108
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user = models.OneToOneField(User)
    description = models.TextField()
109
    status = models.IntegerField(default=NEW)
110
    logo = models.FileField(upload_to=get_company_logo_file_path, null=True, blank=True,  validators=[validate_image_file_extension])
111
    address = models.CharField(max_length=1000, blank=True, null=True)
112
    category = models.CharField(max_length=140, default="Belum ada kategori perusahaan")
113
    website = models.CharField(max_length=100, default="Belum ada link website")
114

Zamil Majdy's avatar
Zamil Majdy committed
115
116
117
118
    @property
    def name(self):
        return get_display_name(self.user)

119
120
121
    def __unicode__(self):
        return u"Company {}".format(get_display_name(self.user))

122
123
124
    class Meta:
        ordering = ['-updated']

125
126
127
128
129
130
131
132
133
134

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
135
136
137
138
    @property
    def name(self):
        return get_display_name(self.user)

139
140
    def __unicode__(self):
        return u"Supervisor {}".format(get_display_name(self.user))
141
142
143

    class Meta:
        ordering = ['-updated']