diff options
author | ankitjavalkar | 2020-05-21 13:51:15 +0530 |
---|---|---|
committer | GitHub | 2020-05-21 13:51:15 +0530 |
commit | 8396869fd7750742e4910b9fe0f8a7683a6769ab (patch) | |
tree | 545ba2b1aaf436066313d801cedfee5d14a25772 /workshop_app/views.py | |
parent | 9487f85e6731147c4580c53383c24faae35ebd72 (diff) | |
parent | d26c6509865c38c9fcffff404786d381c97e8b0d (diff) | |
download | workshop_booking-8396869fd7750742e4910b9fe0f8a7683a6769ab.tar.gz workshop_booking-8396869fd7750742e4910b9fe0f8a7683a6769ab.tar.bz2 workshop_booking-8396869fd7750742e4910b9fe0f8a7683a6769ab.zip |
Merge pull request #131 from pnshiralkar/workshop-comments
Workshop comments
Diffstat (limited to 'workshop_app/views.py')
-rw-r--r-- | workshop_app/views.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/workshop_app/views.py b/workshop_app/views.py index 05ebf94..3f24a2f 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -17,11 +17,11 @@ from django.utils import timezone from .forms import ( UserRegistrationForm, UserLoginForm, - ProfileForm, WorkshopForm, WorkshopTypeForm + ProfileForm, WorkshopForm, CommentsForm, WorkshopTypeForm ) from .models import ( Profile, User, - Workshop, + Workshop, Comment, WorkshopType, AttachmentFile ) from .send_mails import send_email @@ -416,6 +416,33 @@ def workshop_type_list(request): @login_required +def workshop_details(request, workshop_id): + workshop = Workshop.objects.filter(id=workshop_id) + if not workshop.exists(): + raise Http404 + workshop = workshop.first() + if request.method == 'POST': + form = CommentsForm(request.POST) + if form.is_valid(): + form_data = form.save(commit=False) + if not is_instructor(request.user): + form_data.public = True + form_data.author = request.user + form_data.created_date = timezone.now() + form_data.workshop = workshop + form.save() + else: + print(form.errors) + if is_instructor(request.user): + workshop_comments = Comment.objects.filter(workshop=workshop) + else: + workshop_comments = Comment.objects.filter(workshop=workshop, public=True) + return render(request, 'workshop_app/workshop_details.html', + {'workshop': workshop, 'workshop_comments': workshop_comments, + 'form': CommentsForm(initial={'public': True})}) + + +@login_required def add_workshop_type(request): if not is_instructor(request.user): return redirect(get_landing_page(request.user)) |