Fakultas Ilmu Komputer UI

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

INDRA SEPTAMA's avatar
INDRA SEPTAMA committed
4
5
from datetime import date
from django.utils import timezone
6
from django.contrib.auth.models import User
7
from django.core.validators import MinValueValidator, MaxValueValidator, RegexValidator, FileExtensionValidator
8
from django.db import models
9

10
from core.lib.validators import validate_document_file_extension, validate_image_file_extension, validate_npm
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)

INDRA SEPTAMA's avatar
INDRA SEPTAMA committed
30
31
32
def get_current_age(born):
    today = date.today()
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
33
34
35
36
37
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)

38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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()

Yumna Pratista Tastaftian's avatar
Yumna Pratista Tastaftian committed
58
59
60
61
62
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)

63
64
65
66
67
68
69
70

class Student(models.Model):
    """
    A user subclass
    """
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user = models.OneToOneField(User)
71
    npm = models.IntegerField(validators=[validate_npm], unique=True)
72
    resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True, validators=[FileExtensionValidator(['pdf'])])
Yumna Pratista Tastaftian's avatar
Yumna Pratista Tastaftian committed
73
    sertifikat = models.FileField(upload_to=get_student_sertifikat_file_path, null=True, blank=True, validators=[validate_document_file_extension])
Fannyah Dita Cahya's avatar
Fannyah Dita Cahya committed
74
75
    phone_number = models.CharField(max_length=100, blank=True, db_index=True, null=True, validators=[RegexValidator(r'^0\d{1,11}$')])
    gender = models.CharField(max_length=30, blank=True, null=True)
76
    bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True)
77
78
    applied_vacancies = models.ManyToManyField('core.Vacancy', related_name="applied_vacancies",
                                               blank=True, through='core.Application')
79
80
81
82
    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)
83
    show_transcript = models.BooleanField(default=False)
84
    photo = models.FileField(upload_to=get_student_photo_file_path, null=True, blank=True, validators=[FileExtensionValidator(['jpg', 'jpeg', 'png'])]) 
85
    self_description = models.CharField(max_length=500, blank=True, db_index=True, null=True)
Metta Anantha Pindika's avatar
Metta Anantha Pindika committed
86
    portfolio_link = models.URLField(blank=True, null=True)
87
    linkedin_url = models.URLField(max_length=200,blank=True, null=True)
88
    hackerrank_url = models.URLField(max_length=200,blank=True, null=True)
Muhammad Fauzan Fikri's avatar
Muhammad Fauzan Fikri committed
89
    website_url = models.URLField(max_length=200,blank=True, null=True)
90
    work_experience = models.CharField(max_length=500, blank=True, null=True)
PRIAMBUDI LINTANG BAGASKARA's avatar
PRIAMBUDI LINTANG BAGASKARA committed
91
    region = models.CharField(max_length=30, blank=True, null=True)
92
    alamat = models.CharField(max_length=50, blank=True, null=True)
Tyagita Larasati's avatar
Tyagita Larasati committed
93
    skills = models.CharField(max_length=50, blank=True, null=True)
94
    recommendations = models.CharField(max_length=500, blank=True, null=True)
95
    ui_ux_portofolio = models.FileField(upload_to=get_student_ui_ux_portofolio_file_path, null=True, blank=True, validators=[validate_document_file_extension])
96
97
    latest_work = models.CharField(max_length=100, blank=True, null=True)
    latest_work_desc = models.TextField(blank=True, null=True)
98
    github_url = models.URLField(max_length=200,blank=True, null=True)
HANIF AGUNG PRAYOGA's avatar
HANIF AGUNG PRAYOGA committed
99
    intro = models.CharField(max_length=50, blank=True, null=True)
100
    expected_salary = models.CharField(max_length=10, blank=True, null=True)
Nixi Sendya Putri's avatar
Nixi Sendya Putri committed
101
    job_seeking_status = models.CharField(max_length=30, blank=True, null=True)
102
    student_gpa = models.FloatField(db_column='student_gpa', default=1.0, blank=True, null=True)
103
    volunteer = models.CharField(max_length=100, blank=True, null=True)
Farah Alhaniy Efendi's avatar
Farah Alhaniy Efendi committed
104
    awards = models.CharField(max_length=100, blank=True, null=True)
Fannyah Dita Cahya's avatar
Fannyah Dita Cahya committed
105
    certification = models.CharField(max_length=100, blank=True, null=True)
Tyagita Larasati's avatar
Tyagita Larasati committed
106
    languages = models.CharField(max_length= 100, blank=True, null=True)
Nixi Sendya Putri's avatar
Nixi Sendya Putri committed
107
    seminar = models.CharField(max_length=100, blank=True, null=True)
108

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

113
114
115
116
    @property
    def full_name(self):
        return get_display_name(self.user, full_name=True)

INDRA SEPTAMA's avatar
INDRA SEPTAMA committed
117
118
119
120
    @property
    def age(self):
        return get_current_age(self.birth_date)

121
122
123
    def __unicode__(self):
        return u"Student {}".format(get_display_name(self.user))

124
125
126
    class Meta:
        ordering = ['-updated']

127
128
129
130
131

class Company(models.Model):
    """
    A user subclass
    """
132
133
134
135
    NEW = 0
    UNVERIFIED = 1
    VERIFIED = 2

136
137
138
139
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    user = models.OneToOneField(User)
    description = models.TextField()
140
    status = models.IntegerField(default=NEW)
141
    logo = models.FileField(upload_to=get_company_logo_file_path, null=True, blank=True,  validators=[validate_image_file_extension])
142
    address = models.CharField(max_length=1000, blank=True, null=True)
143
    category = models.CharField(max_length=140, default="Belum ada kategori perusahaan")
144
    website = models.CharField(max_length=100, default="Belum ada link website")
145

Zamil Majdy's avatar
Zamil Majdy committed
146
147
148
149
    @property
    def name(self):
        return get_display_name(self.user)

150
151
152
    def __unicode__(self):
        return u"Company {}".format(get_display_name(self.user))

153
154
155
    class Meta:
        ordering = ['-updated']

156
157
158
159
160
161
162
163
164
165

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
166
167
168
169
    @property
    def name(self):
        return get_display_name(self.user)

170
171
    def __unicode__(self):
        return u"Supervisor {}".format(get_display_name(self.user))
172
173

    class Meta:
174
        ordering = ['-updated']