diff options
author | pnshiralkar | 2020-04-25 16:28:35 +0530 |
---|---|---|
committer | pnshiralkar | 2020-04-25 16:28:35 +0530 |
commit | 37f0afbf21fc6d4e9eb92433d666fccfd6654d53 (patch) | |
tree | 54fc46ee9ba1a14b93294be9e7b0e1a279efd7a8 /workshop_app/models.py | |
parent | ab64501d95655dbc19fd8d5bcc6c6c86c21ae34f (diff) | |
download | workshop_booking-37f0afbf21fc6d4e9eb92433d666fccfd6654d53.tar.gz workshop_booking-37f0afbf21fc6d4e9eb92433d666fccfd6654d53.tar.bz2 workshop_booking-37f0afbf21fc6d4e9eb92433d666fccfd6654d53.zip |
Refractored models in workshop_app
Diffstat (limited to 'workshop_app/models.py')
-rw-r--r-- | workshop_app/models.py | 276 |
1 files changed, 96 insertions, 180 deletions
diff --git a/workshop_app/models.py b/workshop_app/models.py index 4d589bf..46433b3 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -1,14 +1,14 @@ -from django.db import models +import os + from django.contrib.auth.models import User from django.core.validators import RegexValidator -from recurrence.fields import RecurrenceField +from django.db import models from django.utils import timezone -import os position_choices = ( ("coordinator", "Coordinator"), ("instructor", "Instructor") - ) +) department_choices = ( ("computer engineering", "Computer Science"), @@ -21,7 +21,7 @@ department_choices = ( ("biosciences and bioengineering", "Biosciences and BioEngineering"), ("electronics", "Electronics"), ("energy science and engineering", "Energy Science and Engineering"), - ) +) title = ( ("Professor", "Prof."), @@ -32,53 +32,55 @@ title = ( ("Mr", "Mr."), ("Mrs", "Mrs."), ("Miss", "Ms."), - ) +) source = ( ("FOSSEE website", "FOSSEE website"), ("Google", "Google"), ("Social Media", "Social Media"), ("From other College", "From other College"), - ) +) + +# TODO: states and dept_chocies var also exists in forms.py. Use only one. states = ( - ("IN-AP", "Andhra Pradesh"), - ("IN-AR", "Arunachal Pradesh"), - ("IN-AS", "Assam"), - ("IN-BR", "Bihar"), - ("IN-CT", "Chhattisgarh"), - ("IN-GA", "Goa"), - ("IN-GJ", "Gujarat"), - ("IN-HR", "Haryana"), - ("IN-HP", "Himachal Pradesh"), - ("IN-JK", "Jammu and Kashmir"), - ("IN-JH", "Jharkhand"), - ("IN-KA", "Karnataka"), - ("IN-KL", "Kerala"), - ("IN-MP", "Madhya Pradesh"), - ("IN-MH", "Maharashtra"), - ("IN-MN", "Manipur"), - ("IN-ML", "Meghalaya"), - ("IN-MZ", "Mizoram"), - ("IN-NL", "Nagaland"), - ("IN-OR", "Odisha"), - ("IN-PB", "Punjab"), - ("IN-RJ", "Rajasthan"), - ("IN-SK", "Sikkim"), - ("IN-TN", "Tamil Nadu"), - ("IN-TG", "Telangana"), - ("IN-TR", "Tripura"), - ("IN-UT", "Uttarakhand"), - ("IN-UP", "Uttar Pradesh"), - ("IN-WB", "West Bengal"), - ("IN-AN", "Andaman and Nicobar Islands"), - ("IN-CH", "Chandigarh"), - ("IN-DN", "Dadra and Nagar Haveli"), - ("IN-DD", "Daman and Diu"), - ("IN-DL", "Delhi"), - ("IN-LD", "Lakshadweep"), - ("IN-PY", "Puducherry") - ) + ("IN-AP", "Andhra Pradesh"), + ("IN-AR", "Arunachal Pradesh"), + ("IN-AS", "Assam"), + ("IN-BR", "Bihar"), + ("IN-CT", "Chhattisgarh"), + ("IN-GA", "Goa"), + ("IN-GJ", "Gujarat"), + ("IN-HR", "Haryana"), + ("IN-HP", "Himachal Pradesh"), + ("IN-JK", "Jammu and Kashmir"), + ("IN-JH", "Jharkhand"), + ("IN-KA", "Karnataka"), + ("IN-KL", "Kerala"), + ("IN-MP", "Madhya Pradesh"), + ("IN-MH", "Maharashtra"), + ("IN-MN", "Manipur"), + ("IN-ML", "Meghalaya"), + ("IN-MZ", "Mizoram"), + ("IN-NL", "Nagaland"), + ("IN-OR", "Odisha"), + ("IN-PB", "Punjab"), + ("IN-RJ", "Rajasthan"), + ("IN-SK", "Sikkim"), + ("IN-TN", "Tamil Nadu"), + ("IN-TG", "Telangana"), + ("IN-TR", "Tripura"), + ("IN-UT", "Uttarakhand"), + ("IN-UP", "Uttar Pradesh"), + ("IN-WB", "West Bengal"), + ("IN-AN", "Andaman and Nicobar Islands"), + ("IN-CH", "Chandigarh"), + ("IN-DN", "Dadra and Nagar Haveli"), + ("IN-DD", "Daman and Diu"), + ("IN-DL", "Delhi"), + ("IN-LD", "Lakshadweep"), + ("IN-PY", "Puducherry") +) def has_profile(user): @@ -94,25 +96,24 @@ class Profile(models.Model): """Profile for users(instructors and coordinators)""" user = models.OneToOneField(User) - title = models.CharField(max_length=32,blank=True, choices=title) + title = models.CharField(max_length=32, blank=True, choices=title) institute = models.CharField(max_length=150) department = models.CharField(max_length=150, choices=department_choices) phone_number = models.CharField( - max_length=10, - validators=[RegexValidator( - regex=r'^.{10}$', message=( - "Phone number must be entered \ - in the format: '9999999999'.\ - Up to 10 digits allowed.") - )] - ,null=False) + max_length=10, + validators=[RegexValidator( + regex=r'^.{10}$', message=( + "Phone number must be entered \ + in the format: '9999999999'.\ + Up to 10 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\ + 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.') - how_did_you_hear_about_us = models.CharField(max_length=255, blank=True,choices=source) - location = models.CharField(max_length=255,blank=True, help_text="Place/City") + how_did_you_hear_about_us = models.CharField(max_length=255, blank=True, choices=source) + location = models.CharField(max_length=255, blank=True, help_text="Place/City") state = models.CharField(max_length=255, choices=states, default="IN-MH") is_email_verified = models.BooleanField(default=False) activation_key = models.CharField(max_length=255, blank=True, null=True) @@ -120,11 +121,11 @@ class Profile(models.Model): 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 - ) + self.user.id, + self.user.first_name, + self.user.last_name, + self.user.email + ) class WorkshopType(models.Model): @@ -132,126 +133,42 @@ class WorkshopType(models.Model): 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 \ + name = models.CharField(max_length=120) + description = models.TextField() + duration = models.CharField(max_length=32, + help_text='Please write this in \ following format eg: 3days, 8hours a day') - workshoptype_attachments = models.FileField(upload_to=attachments, blank=True, - help_text='Please upload workshop documents one by one, \ + attachments = models.FileField(upload_to=attachments, blank=True, + help_text='Please upload workshop documents one by one, \ ie.workshop schedule, instructions etc. \ Please Note: Name of Schedule file should be similar to \ WorkshopType Name') + terms_and_conditions = models.TextField() def __str__(self): - return u"{0} {1}".format(self.workshoptype_name, - self.workshoptype_duration - ) + return u"{0} {1}".format(self.name, + self.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 - ) - - def __str__(self): - return u"{0} | {1} | {2}| {3}".format( - self.requested_workshop_date, - self.requested_workshop_title, - self.requested_workshop_coordinator, - self.status - ) - - -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 25 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" - ) - - def __str__(self): - return u"{0} | {1} | {2}| {3}".format( - self.proposed_workshop_date, - self.proposed_workshop_title, - self.proposed_workshop_coordinator, - self.status - ) - - -class BookedWorkshop(models.Model): """ - Contains details about Confirmed Booked/Completed Workshops + Contains details of workshops """ - - booked_workshop_requested = models.ForeignKey(RequestedWorkshop, null=True) - booked_workshop_proposed = models.ForeignKey(ProposeWorkshopDate,null=True) + coordinator = models.ForeignKey(User, on_delete=models.CASCADE) + instructor = models.ForeignKey(User, null=True, related_name="%(app_label)s_%(class)s_related") + title = models.ForeignKey(WorkshopType, on_delete=models.CASCADE, help_text='Select the type of workshop.') + date = models.DateField() + status = models.CharField(max_length=32, default="Pending") def __str__(self): - return u"{0} | {1} |".format( - self.booked_workshop_requested, - self.booked_workshop_proposed - ) + return u"{0} | {1} | {2} | {3} | {4}".format( + self.date, + self.title, + self.coordinator, + self.instructor, + self.status + ) class Testimonial(models.Model): @@ -266,11 +183,10 @@ class Testimonial(models.Model): def __str__(self): return u"{0} | {1} ".format( - self.name, - self.institute, - self.department - ) - + self.name, + self.institute, + self.department + ) class ProfileComments(models.Model): @@ -278,21 +194,21 @@ class ProfileComments(models.Model): Contains comments posted by instructors on coordinator profile """ - coordinator_profile = models.ForeignKey(User, - on_delete=models.CASCADE) + coordinator = models.ForeignKey(User, + on_delete=models.CASCADE) comment = models.TextField() - instructor_profile = models.ForeignKey(User, - related_name="%(app_label)s_%(class)s_related") + instructor = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_related") created_date = models.DateTimeField(default=timezone.now) def __str__(self): return u"{0} | {1}".format( self.comment, self.created_date, - self.coordinator_profile, - self.instructor_profile + self.coordinator, + self.instructor ) + class Banner(models.Model): """ Add HTML for banner display on homepage |