diff options
author | adityacp | 2020-07-01 17:24:43 +0530 |
---|---|---|
committer | adityacp | 2020-07-01 17:24:43 +0530 |
commit | e9dd8590696a6bd2f4c71f20a797953a12ee1774 (patch) | |
tree | 21a2498bb5bcba69934f262af356f3b29d2ccf3d | |
parent | d22be9a00da34a2c0d605482d3aaf91371efc2db (diff) | |
download | workshop_booking-e9dd8590696a6bd2f4c71f20a797953a12ee1774.tar.gz workshop_booking-e9dd8590696a6bd2f4c71f20a797953a12ee1774.tar.bz2 workshop_booking-e9dd8590696a6bd2f4c71f20a797953a12ee1774.zip |
Change views, models, settings, urls
- Fix pep8 in app urls
- Add default django forgot password url in project url
- Add uuid field in workshop model
- fix few pep8 in the models.py
- Add template directory in settings
- Update requirements.txt
-rw-r--r-- | requirements.txt | 6 | ||||
-rw-r--r-- | workshop_app/models.py | 86 | ||||
-rw-r--r-- | workshop_app/urls.py | 41 | ||||
-rw-r--r-- | workshop_app/views.py | 5 | ||||
-rw-r--r-- | workshop_portal/settings.py | 2 | ||||
-rw-r--r-- | workshop_portal/urls.py | 2 |
6 files changed, 73 insertions, 69 deletions
diff --git a/requirements.txt b/requirements.txt index a0f66a1..b020c4f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,3 @@ -Django==3.0.5 -packaging==16.8 -python-dateutil==2.6.0 -pytz==2016.10 -six==1.10.0 +Django==3.0.7 coverage pyaml diff --git a/workshop_app/models.py b/workshop_app/models.py index d690a7e..62d10b5 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -1,9 +1,11 @@ import os +import uuid from django.contrib.auth.models import User from django.core.validators import RegexValidator from django.db import models from django.utils import timezone +from django.core.validators import MinValueValidator position_choices = ( ("coordinator", "Coordinator"), @@ -105,25 +107,25 @@ class Profile(models.Model): 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\ + 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.') - 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) 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 - ) + return f"Profile for {self.user.get_full_name()}" class WorkshopType(models.Model): @@ -133,23 +135,23 @@ class WorkshopType(models.Model): 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') + duration = models.PositiveIntegerField( + help_text='Please enter duration in days', + validators=[MinValueValidator(1)] + ) terms_and_conditions = models.TextField() def __str__(self): - return u"{0} {1}".format(self.name, - self.duration - ) + return f"{self.name} for {self.duration} day(s)" class AttachmentFile(models.Model): - attachments = models.FileField(upload_to=attachments, blank=False, - 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') + attachments = models.FileField( + upload_to=attachments, blank=False, + 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') workshop_type = models.ForeignKey(WorkshopType, on_delete=models.CASCADE) @@ -157,29 +159,32 @@ class Workshop(models.Model): """ Contains details of workshops """ + uid = models.UUIDField(default=uuid.uuid4, unique=True, editable=False) coordinator = models.ForeignKey(User, on_delete=models.CASCADE) - instructor = models.ForeignKey(User, null=True, related_name="%(app_label)s_%(class)s_related", - on_delete=models.CASCADE) - workshop_type = models.ForeignKey(WorkshopType, on_delete=models.CASCADE, help_text='Select the type of workshop.') + instructor = models.ForeignKey( + User, null=True, related_name="%(app_label)s_%(class)s_related", + on_delete=models.CASCADE + ) + workshop_type = models.ForeignKey( + WorkshopType, on_delete=models.CASCADE, + help_text='Select the type of workshop.' + ) date = models.DateField() STATUS_CHOICES = [(0, 'Pending'), (1, 'Accepted'), (2, 'Deleted')] status = models.IntegerField(choices=STATUS_CHOICES, default=0) - tnc_accepted = models.BooleanField(help_text="I accept the terms and conditions") + tnc_accepted = models.BooleanField( + help_text="I accept the terms and conditions" + ) def __str__(self): - return u"{0} | {1} | {2} | {3} | {4}".format( - self.date, - self.workshop_type, - self.coordinator, - self.instructor, - self.STATUS_CHOICES[self.status][1] - ) + return f"{self.workshop_type} on {self.date} by {self.coordinator}" def get_status(self): - return str(self.STATUS_CHOICES[self.status][1]) + choice = dict(self.STATUS_CHOICES) + return choice.get(self.status) class Testimonial(models.Model): @@ -193,11 +198,7 @@ class Testimonial(models.Model): message = models.TextField() def __str__(self): - return u"{0} | {1} ".format( - self.name, - self.institute, - self.department - ) + return f"Testimonial by {self.name}" class Comment(models.Model): @@ -212,12 +213,7 @@ class Comment(models.Model): workshop = models.ForeignKey(Workshop, on_delete=models.CASCADE) def __str__(self): - return u"{0} | {1} | {2}".format( - self.comment, - self.created_date, - self.author, - ) - + return f"Comment by {self.author.get_full_name()}" class Banner(models.Model): diff --git a/workshop_app/urls.py b/workshop_app/urls.py index 0acdf90..9ace4ab 100644 --- a/workshop_app/urls.py +++ b/workshop_app/urls.py @@ -18,23 +18,36 @@ from workshop_app import views urlpatterns = [ url(r'^$', views.index, name='index'), - url(r'^register/$', views.user_register), + url(r'^register/$', views.user_register, name="register"), url(r'^activate_user/(?P<key>.+)$', views.activate_user), url(r'^activate_user/$', views.activate_user), url(r'^login/$', views.user_login), url(r'^logout/$', views.user_logout), url(r'^edit_profile/$', views.edit_profile), - url(r'^workshop_status$', views.workshop_status_coordinator, name='workshop_status_coordinator'), - url(r'^dashboard$', views.workshop_status_instructor, name='workshop_status_instructor'), - url(r'^accept_workshop/(?P<workshop_id>\d+)', views.accept_workshop, name='accept_workshop'), - url(r'^change_workshop_date/(?P<workshop_id>\d+)$', views.change_workshop_date, name='change_workshop_date'), - url(r'^workshops/(?P<workshop_id>\d+)$', views.workshop_details, name='workshop_details'), - url(r'^workshop_type_details/(?P<workshop_type_id>\d+)$', views.workshop_type_details, name='workshop_type_details'), - url(r'^workshop_type_tnc/(?P<workshop_type_id>\d+)$', views.workshop_type_tnc, name='workshop_type_tnc'), - url(r'^propose_workshop/$', views.propose_workshop, name='propose_workshop'), - url(r'^add_workshop_type$', views.add_workshop_type, name='add_workshop_type'), - url(r'^delete_attachment_file/(?P<file_id>\d+)$', views.delete_attachment_file, name='delete_attachment_file'), - url(r'^workshop_types/$', views.workshop_type_list, name='workshop_type_list'), - url(r'^view_profile/$', views.view_own_profile, name='view_own_profile'), - url(r'^view_profile/(?P<user_id>\d+)$', views.view_profile, name='view_profile'), + url(r'^workshop_status$', views.workshop_status_coordinator, + name='workshop_status_coordinator'), + url(r'^dashboard$', views.workshop_status_instructor, + name='workshop_status_instructor'), + url(r'^accept_workshop/(?P<workshop_id>\d+)', views.accept_workshop, + name='accept_workshop'), + url(r'^change_workshop_date/(?P<workshop_id>\d+)$', + views.change_workshop_date, name='change_workshop_date'), + url(r'^workshops/(?P<workshop_id>\d+)$', views.workshop_details, + name='workshop_details'), + url(r'^workshop_type_details/(?P<workshop_type_id>\d+)$', + views.workshop_type_details, name='workshop_type_details'), + url(r'^workshop_type_tnc/(?P<workshop_type_id>\d+)$', + views.workshop_type_tnc, name='workshop_type_tnc'), + url(r'^propose_workshop/$', views.propose_workshop, + name='propose_workshop'), + url(r'^add_workshop_type$', views.add_workshop_type, + name='add_workshop_type'), + url(r'^delete_attachment_file/(?P<file_id>\d+)$', + views.delete_attachment_file, name='delete_attachment_file'), + url(r'^workshop_types/$', views.workshop_type_list, + name='workshop_type_list'), + url(r'^view_profile/$', views.view_own_profile, + name='view_own_profile'), + url(r'^view_profile/(?P<user_id>\d+)$', views.view_profile, + name='view_profile'), ] diff --git a/workshop_app/views.py b/workshop_app/views.py index a1a6a28..90495a5 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -151,7 +151,7 @@ def user_register(request): if request.user.is_authenticated: return redirect('/view_profile/') return render( - request, "workshop_app/registration/register.html", + request, "workshop_app/register.html", {"form": form} ) else: @@ -160,7 +160,7 @@ def user_register(request): elif request.user.is_authenticated: return render(request, 'workshop_app/activation.html') form = UserRegistrationForm() - return render(request, "workshop_app/registration/register.html", {"form": form}) + return render(request, "workshop_app/register.html", {"form": form}) @login_required @@ -441,7 +441,6 @@ def workshop_details(request, workshop_id): form.save() messages.add_message(request, messages.SUCCESS, "Comment posted") else: - print(form.errors) messages.add_message(request, messages.ERROR, "Error posting comment") if is_instructor(request.user): workshop_comments = Comment.objects.filter(workshop=workshop) diff --git a/workshop_portal/settings.py b/workshop_portal/settings.py index 23f9f1a..abf58f5 100644 --- a/workshop_portal/settings.py +++ b/workshop_portal/settings.py @@ -63,7 +63,7 @@ ROOT_URLCONF = 'workshop_portal.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': ['workshop_app/templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/workshop_portal/urls.py b/workshop_portal/urls.py index 16bdfb3..464b98c 100644 --- a/workshop_portal/urls.py +++ b/workshop_portal/urls.py @@ -20,5 +20,5 @@ from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^', include('workshop_app.urls')), - + url(r'^reset/', include('django.contrib.auth.urls')), ] |