diff options
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)) |