Fakultas Ilmu Komputer UI

accounts.py 8.77 KB
Newer Older
1
2
import os
import uuid
INDRA SEPTAMA's avatar
INDRA SEPTAMA committed
3
from datetime import date
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
4

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

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
9
10
from core.lib.validators import validate_document_file_extension, validate_image_file_extension, validate_npm, \
    validate_student_gpa
11

12
13

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


19
20
21
22
23
24
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)


25
26
27
28
29
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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
30

INDRA SEPTAMA's avatar
INDRA SEPTAMA committed
31
32
33
def get_current_age(born):
    today = date.today()
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
34
35


36
37
38
39
40
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)

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()

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
61

Yumna Pratista Tastaftian's avatar
Yumna Pratista Tastaftian committed
62
63
64
65
66
def get_student_sertifikat_file_path(instance, filename):
    extension = filename.split('.')[-1].lower()
    filename = "%s.%s" % (uuid.uuid4(), extension)
    return os.path.join("student-sertifikat/", filename)

Fannyah Dita Cahya's avatar
Fannyah Dita Cahya committed
67
68
69
70
71
def get_student_toefl_file_path(instance, filename):
    extension = filename.split('.')[-1].lower()
    filename = "%s.%s" % (uuid.uuid4(), extension)
    return os.path.join("student-toefl-file/", filename)

72
73
74
75
76
77
78

class Student(models.Model):
    """
    A user subclass
    """
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
79
    user = models.OneToOneField(User, on_delete=models.CASCADE)
80
    npm = models.IntegerField(validators=[validate_npm], unique=True)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
81
82
83
84
85
86
    resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True,
                              validators=[FileExtensionValidator(['pdf'])])
    sertifikat = models.FileField(upload_to=get_student_sertifikat_file_path, null=True, blank=True,
                                  validators=[validate_document_file_extension])
    phone_number = models.CharField(max_length=100, blank=True, db_index=True, null=True,
                                    validators=[RegexValidator(r'^0\d{1,11}$')])
Fannyah Dita Cahya's avatar
Fannyah Dita Cahya committed
87
    gender = models.CharField(max_length=30, blank=True, null=True)
88
    bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True)
89
90
    applied_vacancies = models.ManyToManyField('core.Vacancy', related_name="applied_vacancies",
                                               blank=True, through='core.Application')
91
92
93
94
    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)
95
    show_transcript = models.BooleanField(default=False)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
96
97
    photo = models.FileField(upload_to=get_student_photo_file_path, null=True, blank=True,
                             validators=[FileExtensionValidator(['jpg', 'jpeg', 'png'])])
98
    self_description = models.CharField(max_length=500, blank=True, db_index=True, null=True)
Metta Anantha Pindika's avatar
Metta Anantha Pindika committed
99
    portfolio_link = models.URLField(blank=True, null=True)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
100
101
102
    linkedin_url = models.URLField(max_length=200, blank=True, null=True)
    hackerrank_url = models.URLField(max_length=200, blank=True, null=True)
    website_url = models.URLField(max_length=200, blank=True, null=True)
103
    work_experience = models.CharField(max_length=500, blank=True, null=True)
PRIAMBUDI LINTANG BAGASKARA's avatar
PRIAMBUDI LINTANG BAGASKARA committed
104
    region = models.CharField(max_length=30, blank=True, null=True)
105
    alamat = models.CharField(max_length=50, blank=True, null=True)
Tyagita Larasati's avatar
Tyagita Larasati committed
106
    skills = models.CharField(max_length=50, blank=True, null=True)
107
    recommendations = models.ManyToManyField('core.Recommendation', related_name="recommendations", blank=True)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
108
109
    ui_ux_portofolio = models.FileField(upload_to=get_student_ui_ux_portofolio_file_path, null=True, blank=True,
                                        validators=[validate_document_file_extension])
110
111
    latest_work = models.CharField(max_length=100, blank=True, null=True)
    latest_work_desc = models.TextField(blank=True, null=True)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
112
113
    github_url = models.URLField(max_length=200, blank=True, null=True)
    gitlab_url = models.URLField(max_length=200, blank=True, null=True)
HANIF AGUNG PRAYOGA's avatar
HANIF AGUNG PRAYOGA committed
114
    intro = models.CharField(max_length=50, blank=True, null=True)
JONATHAN EDWIN's avatar
JONATHAN EDWIN committed
115
    expected_salary = models.CharField(max_length=10, blank=True, null=True, validators=[RegexValidator(r'^\d{0,10}$')])
Nixi Sendya Putri's avatar
Nixi Sendya Putri committed
116
    job_seeking_status = models.CharField(max_length=30, blank=True, null=True)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
117
118
    student_gpa = models.FloatField(db_column='student_gpa', default=1.0, blank=True, null=True,
                                    validators=[validate_student_gpa])
Muhammad Fauzan Fikri's avatar
Muhammad Fauzan Fikri committed
119
    student_toefl = models.IntegerField(db_column='toefl', default=0, blank=True, null=True)
Fannyah Dita Cahya's avatar
Fannyah Dita Cahya committed
120
121
    student_toefl_file = models.FileField(upload_to=get_student_toefl_file_path, null=True, blank=True,
                              validators=[FileExtensionValidator(['pdf'])])
122
    volunteer = models.CharField(max_length=100, blank=True, null=True)
Farah Alhaniy Efendi's avatar
Farah Alhaniy Efendi committed
123
    awards = models.CharField(max_length=100, blank=True, null=True)
Aviliani Pramestya's avatar
Aviliani Pramestya committed
124
    projects = models.CharField(max_length=100, blank=True, null=True)
Fannyah Dita Cahya's avatar
Fannyah Dita Cahya committed
125
    certification = models.CharField(max_length=100, blank=True, null=True)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
126
    languages = models.CharField(max_length=100, blank=True, null=True)
Nixi Sendya Putri's avatar
Nixi Sendya Putri committed
127
    seminar = models.CharField(max_length=100, blank=True, null=True)
Hema Mitta Kalyani's avatar
Hema Mitta Kalyani committed
128
    interests = models.CharField(max_length=100, blank=True, null=True)
Dwi Nanda Susanto's avatar
Dwi Nanda Susanto committed
129
    dependants = models.IntegerField(db_column='dependants', default=0, blank=True, null=True)
Farah Alhaniy Efendi's avatar
Farah Alhaniy Efendi committed
130
    related_course = models.CharField(max_length=200, blank=True, null=True)
Dwi Nanda Susanto's avatar
Dwi Nanda Susanto committed
131
132
    ielts = models.FloatField(db_column='ielts', default=1.0, blank=True, null=True)
    
Zamil Majdy's avatar
Zamil Majdy committed
133
134
135
136
    @property
    def name(self):
        return get_display_name(self.user)

137
138
139
140
    @property
    def full_name(self):
        return get_display_name(self.user, full_name=True)

INDRA SEPTAMA's avatar
INDRA SEPTAMA committed
141
142
143
144
    @property
    def age(self):
        return get_current_age(self.birth_date)

145
146
147
    def __unicode__(self):
        return u"Student {}".format(get_display_name(self.user))

148
149
150
    class Meta:
        ordering = ['-updated']

151
152
153
154
155

class Company(models.Model):
    """
    A user subclass
    """
156
157
158
159
    NEW = 0
    UNVERIFIED = 1
    VERIFIED = 2

160
161
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
162
    user = models.OneToOneField(User, on_delete=models.CASCADE)
163
    description = models.TextField()
Metta Anantha Pindika's avatar
Metta Anantha Pindika committed
164
    founded = models.DateField(blank=True, null=True)
165
    status = models.IntegerField(default=NEW, validators=[MaxValueValidator(2), MinValueValidator(0)])
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
166
167
    logo = models.FileField(upload_to=get_company_logo_file_path, null=True, blank=True,
                            validators=[validate_image_file_extension])
168
    address = models.CharField(max_length=1000, blank=True, null=True)
169
    category = models.CharField(max_length=140, default="Belum ada kategori perusahaan")
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
170
    size = models.CharField(max_length=10, default=0, null=True, blank=True)
171
    website = models.CharField(max_length=100, default="Belum ada link website")
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
172
    linkedin_url = models.URLField(max_length=200, blank=True, null=True)
173

Zamil Majdy's avatar
Zamil Majdy committed
174
175
176
177
    @property
    def name(self):
        return get_display_name(self.user)

178
179
180
    def __unicode__(self):
        return u"Company {}".format(get_display_name(self.user))

181
182
183
    class Meta:
        ordering = ['-updated']

184
185
186
187
188
189
190

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

Zamil Majdy's avatar
Zamil Majdy committed
194
195
196
197
    @property
    def name(self):
        return get_display_name(self.user)

198
199
    def __unicode__(self):
        return u"Supervisor {}".format(get_display_name(self.user))
200
201

    class Meta:
JONATHAN EDWIN's avatar
JONATHAN EDWIN committed
202
        ordering = ['-updated']