diff options
author | pnshiralkar | 2020-05-18 20:51:47 +0530 |
---|---|---|
committer | pnshiralkar | 2020-05-18 20:51:47 +0530 |
commit | 5d8b002b48da791b090314a2df3e500734b5b62f (patch) | |
tree | 6e037ca08fa4e8f9c57920562615a3f0b136c1ce | |
parent | a950ed30df4186cee4f08cbde8ad8a210d134e8b (diff) | |
download | workshop_booking-5d8b002b48da791b090314a2df3e500734b5b62f.tar.gz workshop_booking-5d8b002b48da791b090314a2df3e500734b5b62f.tar.bz2 workshop_booking-5d8b002b48da791b090314a2df3e500734b5b62f.zip |
Renamed model WorkshopComments to Comments and added hidden tag to the non-public comments
-rw-r--r-- | workshop_app/admin.py | 6 | ||||
-rw-r--r-- | workshop_app/forms.py | 8 | ||||
-rw-r--r-- | workshop_app/models.py | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/workshop_details.html | 7 | ||||
-rw-r--r-- | workshop_app/views.py | 12 |
5 files changed, 19 insertions, 16 deletions
diff --git a/workshop_app/admin.py b/workshop_app/admin.py index 5182776..988351f 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, WorkshopComment, Banner, AttachmentFile + Testimonial, Comment, Banner, AttachmentFile ) try: @@ -117,7 +117,7 @@ class TestimonialAdmin(admin.ModelAdmin): download_csv.short_description = "Download CSV file for selected stats." -class WorkshopCommentAdmin(admin.ModelAdmin): +class CommentAdmin(admin.ModelAdmin): list_display = ['workshop', 'comment', 'created_date', 'author', 'public'] list_filter = ['workshop', 'author', 'created_date', 'public'] @@ -127,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(WorkshopComment, WorkshopCommentAdmin) +admin.site.register(Comment, CommentAdmin) admin.site.register(Banner) admin.site.register(AttachmentFile) diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 6099a76..95b0ce1 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, department_choices, title, source, states, WorkshopComment) +from .models import (Profile, Workshop, department_choices, title, source, states, Comment) try: from string import letters @@ -170,19 +170,19 @@ class WorkshopForm(forms.ModelForm): } -class WorkshopCommentsForm(forms.ModelForm): +class CommentsForm(forms.ModelForm): """ Users will post comments on workshops """ def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') - super(WorkshopCommentsForm, self).__init__(*args, **kwargs) + super(CommentsForm, self).__init__(*args, **kwargs) self.fields['comment'].required = True self.fields['public'].label = "Public" class Meta: - model = WorkshopComment + model = Comment exclude = ['author', 'created_date', 'workshop'] widgets = { 'comment': forms.Textarea(attrs={ diff --git a/workshop_app/models.py b/workshop_app/models.py index 616e3de..37f3a31 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -200,7 +200,7 @@ class Testimonial(models.Model): ) -class WorkshopComment(models.Model): +class Comment(models.Model): """ Contains comments posted by users on workshop instances """ diff --git a/workshop_app/templates/workshop_app/workshop_details.html b/workshop_app/templates/workshop_app/workshop_details.html index 3ca5a50..388b204 100644 --- a/workshop_app/templates/workshop_app/workshop_details.html +++ b/workshop_app/templates/workshop_app/workshop_details.html @@ -49,9 +49,12 @@ <div class="card my-2"> <div class="card-header"> <div class="row"> - <div class="mx-3 font-weight-bold"><a + <div class="ml-3 font-weight-bold"><a href="{% url 'view_profile' comment.author_id %}">{{ comment.author }}</a></div> - <div class="text-muted">{{ comment.created_date }}</div> + {% if not comment.public %} + <div class="ml-1"><span class="badge badge-dark">Hidden</span></div> + {% endif %} + <div class="ml-3 text-muted">{{ comment.created_date }}</div> </div> </div> <div class="card-body"> diff --git a/workshop_app/views.py b/workshop_app/views.py index b2f56cc..eefb94e 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -16,12 +16,12 @@ from django.utils import timezone from .forms import ( UserRegistrationForm, UserLoginForm, - ProfileForm, WorkshopForm, WorkshopCommentsForm + ProfileForm, WorkshopForm, CommentsForm ) from .models import ( Profile, User, Workshop, - WorkshopType, WorkshopComment + WorkshopType, Comment ) from .send_mails import send_email @@ -382,7 +382,7 @@ def workshop_details(request, workshop_id): raise Http404 workshop = workshop.first() if request.method == 'POST': - form = WorkshopCommentsForm(request.POST) + form = CommentsForm(request.POST) if form.is_valid(): form_data = form.save(commit=False) if not is_instructor(request.user): @@ -394,12 +394,12 @@ def workshop_details(request, workshop_id): else: print(form.errors) if is_instructor(request.user): - workshop_comments = WorkshopComment.objects.filter(workshop=workshop) + workshop_comments = Comment.objects.filter(workshop=workshop) else: - workshop_comments = WorkshopComment.objects.filter(workshop=workshop, public=True) + workshop_comments = Comment.objects.filter(workshop=workshop, public=True) return render(request, 'workshop_app/workshop_details.html', {'workshop': workshop, 'workshop_comments': workshop_comments, - 'form': WorkshopCommentsForm(initial={'public': True})}) + 'form': CommentsForm(initial={'public': True})}) @login_required |