summaryrefslogtreecommitdiff
path: root/workshop_app/models.py
blob: 9745fd36b55c63901b175bb95c2d63705d382598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

from django.db import models
from django.contrib.auth.models import User
from django.core.validators import RegexValidator
from recurrence.fields import RecurrenceField

position_choices = (
    ("coordinator", "Coordinator"),
    ("instructor", "Instructor")
    )

department_choices = (
    ("computer", "Computer Science"),
    ("information technology", "Information Technology"),
    ("civil engineering", "Civil Engineering"),
    ("electrical engineering", "Electrical Engineering"),
    ("mechanical engineering", "Mechanical Engineering"),
    ("chemical engineering", "Chemical Engineering"),
    ("aerospace engineering", "Aerospace Engineering"),
    ("biosciences and bioengineering", "Biosciences and  BioEngineering"),
    ("electronics", "Electronics"),
    ("energy science and engineering", "Energy Science and Engineering"),
    ("others", "Others"),
    )

def has_profile(user):
    """ check if user has profile """
    return True if hasattr(user, 'profile') else False

class Profile(models.Model):
    """Profile for users(instructors and coordinators)"""

    user = models.OneToOneField(User)
    institute = models.CharField(max_length=150)
    department = models.CharField(max_length=150, choices=department_choices)
    phone_number = models.CharField(
                max_length=15,
                validators=[RegexValidator(
                                regex=r'^.{9}$', message=(
                                "Phone number must be entered \
                                in the format: '+99999999'.\
                                Up to 15 digits allowed.")
                            )]
                ,null=False)
    position = models.CharField(max_length=32, choices=position_choices,
                    default='coordinator',
                    help_text='Select Coordinator if you want to organise a workshop\
                            in your college/school. <br> Select Instructor if you want to conduct\
                            a workshop.')
    is_email_verified = models.BooleanField(default=False)
    activation_key = models.CharField(max_length=255, blank=True, null=True)
    key_expiry_time = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return u"id: {0}| {1} {2} | {3} ".format(
                                            self.user.id,
                                            self.user.first_name, 
                                            self.user.last_name, 
                                            self.user.email
                                            ) 


class WorkshopType(models.Model):
    """"Admin creates types of workshops which can be used by the instructor 
        to create workshops.
    """

    workshoptype_name = models.CharField(max_length=120)
    workshoptype_description = models.TextField()
    workshoptype_duration = models.CharField(max_length=32, 
                    help_text='Please write this in \
                    following format eg: 3days, 8hours a day')

    def __str__(self):
        return u"{0} {1}".format(self.workshoptype_name, 
                self.workshoptype_duration
                )


class Workshop(models.Model):
    """Instructor Creates workshop based on
    WorkshopTypes   available"""

    workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE)
    workshop_title = models.ForeignKey(
                                WorkshopType, on_delete=models.CASCADE,
                                help_text=' [Select the type of workshop.] '
                                )
    #For recurring workshops source: django-recurrence
    recurrences = RecurrenceField()

    def __str__(self):
        return u"{0} | {1} ".format(
                    self.workshop_title, 
                    self.workshop_instructor
                    )


class RequestedWorkshop(models.Model):
    """
    Contains Data of request for Workshops
    """

    requested_workshop_instructor = models.ForeignKey(
                                            User,
                                            on_delete=models.CASCADE
                                            )
    requested_workshop_coordinator = models.ForeignKey(
                                User, 
                                related_name="%(app_label)s_%(class)s_related"
                                )
    requested_workshop_date = models.DateField()
    status = models.CharField(
                    max_length=32, default="Pending"
                    )
    requested_workshop_title = models.ForeignKey(
                            WorkshopType, 
                            on_delete=models.CASCADE
                            )


class ProposeWorkshopDate(models.Model):
    """
        Contains details of proposed date and workshop from coordinator
    """

    condition_one = models.BooleanField(default=False, help_text='We assure to\
     give minimum 50 participants for the workshop.')
    condition_two = models.BooleanField(default=False, help_text='We agree \
                                that this booking won\'t be cancelled without \
                                2days of prior notice to the instructor and fossee.')
    condition_three = models.BooleanField(default=False, help_text='This \
                    proposal is subject to FOSSEE and instructor approval.')

    proposed_workshop_coordinator = models.ForeignKey(
                                        User, 
                                        on_delete=models.CASCADE
                                        )
    proposed_workshop_instructor = models.ForeignKey(User, null=True,
                                related_name="%(app_label)s_%(class)s_related")

    proposed_workshop_title = models.ForeignKey(
                                WorkshopType, on_delete=models.CASCADE,
                                help_text='Select the type of workshop.'
                                )

    proposed_workshop_date = models.DateField()

    status = models.CharField(
                    max_length=32, default="Pending"
                    )


class BookedWorkshop(models.Model):
    """
    Contains details about Confirmed Booked/Completed Workshops
    """

    booked_workshop_requested = models.ForeignKey(RequestedWorkshop, null=True) 
    booked_workshop_proposed = models.ForeignKey(ProposeWorkshopDate, null=True)

class Testimonial(models.Model):
    """
    Contains Testimonals of Workshops
    """

    name = models.CharField(max_length=150)
    institute = models.CharField(max_length=255)
    department = models.CharField(max_length=150)
    message = models.TextField()

    def __str__(self):
        return u"{0} | {1} ".format(
                    self.name, 
                    self.institute,
                    self.department
                    )