From 69dde4106648aca1ac3a203b6d03501b33eead29 Mon Sep 17 00:00:00 2001 From: pnshiralkar Date: Wed, 6 May 2020 16:12:42 +0530 Subject: Added workshop comments, linked it to workshop_status tables --- workshop_app/admin.py | 9 +-- workshop_app/forms.py | 27 +++---- workshop_app/models.py | 16 ++--- workshop_app/templates/workshop_app/base.html | 7 +- .../templates/workshop_app/workshop_details.html | 83 ++++++++++++++++++++++ .../workshop_app/workshop_status_coordinator.html | 6 +- .../workshop_app/workshop_status_instructor.html | 8 +-- workshop_app/urls.py | 3 +- workshop_app/views.py | 31 +++++++- 9 files changed, 153 insertions(+), 37 deletions(-) create mode 100644 workshop_app/templates/workshop_app/workshop_details.html diff --git a/workshop_app/admin.py b/workshop_app/admin.py index 4e3d333..5182776 100644 --- a/workshop_app/admin.py +++ b/workshop_app/admin.py @@ -6,7 +6,7 @@ from django.http import HttpResponse from .models import ( Profile, WorkshopType, Workshop, - Testimonial, ProfileComments, Banner, AttachmentFile + Testimonial, WorkshopComment, Banner, AttachmentFile ) try: @@ -117,8 +117,9 @@ class TestimonialAdmin(admin.ModelAdmin): download_csv.short_description = "Download CSV file for selected stats." -class ProfileCommentAdmin(admin.ModelAdmin): - list_display = ['comment', 'created_date', 'coordinator', 'instructor'] +class WorkshopCommentAdmin(admin.ModelAdmin): + list_display = ['workshop', 'comment', 'created_date', 'author', 'public'] + list_filter = ['workshop', 'author', 'created_date', 'public'] # Register your models here. @@ -126,6 +127,6 @@ admin.site.register(Profile, ProfileAdmin) admin.site.register(WorkshopType, WorkshopTypeAdmin) admin.site.register(Workshop, WorkshopAdmin) admin.site.register(Testimonial, TestimonialAdmin) -admin.site.register(ProfileComments, ProfileCommentAdmin) +admin.site.register(WorkshopComment, WorkshopCommentAdmin) admin.site.register(Banner) admin.site.register(AttachmentFile) diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 334bd4e..6099a76 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -3,7 +3,7 @@ from string import punctuation, digits from django import forms from django.utils import timezone -from .models import (Profile, Workshop, ProfileComments, department_choices, title, source, states) +from .models import (Profile, Workshop, department_choices, title, source, states, WorkshopComment) try: from string import letters @@ -170,22 +170,25 @@ class WorkshopForm(forms.ModelForm): } -class ProfileCommentsForm(forms.ModelForm): +class WorkshopCommentsForm(forms.ModelForm): """ - Instructors will post comments on Coordinators profile + Users will post comments on workshops """ def __init__(self, *args, **kwargs): - super(ProfileCommentsForm, self).__init__(*args, **kwargs) - self.fields['comment'].label = "" - self.fields['comment'].widget.attrs['rows'] = 5 - self.fields['comment'].widget.attrs['cols'] = 95 + kwargs.setdefault('label_suffix', '') + super(WorkshopCommentsForm, self).__init__(*args, **kwargs) + self.fields['comment'].required = True + self.fields['public'].label = "Public" class Meta: - model = ProfileComments - exclude = ['coordinator_profile', 'instructor_profile', - 'created_date' - ] + model = WorkshopComment + exclude = ['author', 'created_date', 'workshop'] widgets = { - 'comments': forms.CharField(), + 'comment': forms.Textarea(attrs={ + 'class': 'form-control', + }), + 'public': forms.CheckboxInput(attrs={ + 'class': 'form-check-input', + }) } diff --git a/workshop_app/models.py b/workshop_app/models.py index b35d9a7..616e3de 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -200,26 +200,26 @@ class Testimonial(models.Model): ) -class ProfileComments(models.Model): +class WorkshopComment(models.Model): """ - Contains comments posted by instructors on coordinator profile + Contains comments posted by users on workshop instances """ - coordinator = models.ForeignKey(User, - on_delete=models.CASCADE) + author = models.ForeignKey(User, on_delete=models.CASCADE) comment = models.TextField() - instructor = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_related", on_delete=models.CASCADE) + public = models.BooleanField(default=True) created_date = models.DateTimeField(default=timezone.now) + workshop = models.ForeignKey(Workshop, on_delete=models.CASCADE) def __str__(self): - return u"{0} | {1}".format( + return u"{0} | {1} | {2}".format( self.comment, self.created_date, - self.coordinator, - self.instructor + self.author, ) + class Banner(models.Model): """ Add HTML for banner display on homepage diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html index c7a454e..88ee1a1 100644 --- a/workshop_app/templates/workshop_app/base.html +++ b/workshop_app/templates/workshop_app/base.html @@ -43,7 +43,7 @@