diff options
author | Akshen | 2018-08-03 16:15:37 +0530 |
---|---|---|
committer | Akshen | 2018-08-03 16:15:37 +0530 |
commit | 802ab05a0cd4fbf197b014664d5bb70907862aef (patch) | |
tree | 2934378ef57fb473168747b49d603b863d426f90 /workshop_app/views.py | |
parent | c7a9b030449408efda3cd554aaa9138ebbcf8ae3 (diff) | |
download | workshop_booking-802ab05a0cd4fbf197b014664d5bb70907862aef.tar.gz workshop_booking-802ab05a0cd4fbf197b014664d5bb70907862aef.tar.bz2 workshop_booking-802ab05a0cd4fbf197b014664d5bb70907862aef.zip |
Allow instructors to post comments on coordinator's profile
This commit will allow instructors to view and post comments on coordinators profile
Auto-logout time increased
Diffstat (limited to 'workshop_app/views.py')
-rw-r--r-- | workshop_app/views.py | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/workshop_app/views.py b/workshop_app/views.py index 699c4d9..76edc95 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,14 +1,14 @@ from .forms import ( UserRegistrationForm, UserLoginForm, ProfileForm, CreateWorkshop, - ProposeWorkshopDateForm + ProposeWorkshopDateForm, ProfileCommentsForm ) from .models import ( Profile, User, has_profile, Workshop, WorkshopType, RequestedWorkshop, BookedWorkshop, ProposeWorkshopDate, - Testimonial + Testimonial, ProfileComments ) from datetime import datetime, date from django.contrib.auth import login, logout, authenticate @@ -1180,3 +1180,50 @@ def workshop_stats(request): def self_workshop(request): return render(request, "workshop_app/self_workshop.html") + + + +@login_required +def view_comment_profile(request, user_id): + '''instructor can view/post comments on coordinator profile ''' + user = request.user + if is_instructor(user) and is_email_checked(user): + comment_form = ProfileCommentsForm() + coordinator_profile = Profile.objects.get(user_id=user_id) + try: + comments = ProfileComments.objects.filter(coordinator_profile_id=user_id).order_by('-created_date') + except: + comments = None + if request.method == 'POST': + comment_formpost = ProfileCommentsForm(request.POST) + if comment_formpost.is_valid(): + form_data = comment_formpost.save(commit=False) + form_data.coordinator_profile_id = user_id + form_data.instructor_profile_id = user.id + form_data.save() + + return render(request, "workshop_app/view_comment_profile.html", + {"coordinator_profile": coordinator_profile, + "comments": comments, + "comment_form": comment_form + }) + else: + if comments is not None: + #Show upto 12 Workshops per page + paginator = Paginator(comments, 12) + page = request.GET.get('page') + try: + comments = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + comments = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + comments = paginator.page(paginator.num_pages) + + return render(request, "workshop_app/view_comment_profile.html", + {"coordinator_profile": coordinator_profile, + "comments": comments, + "comment_form": comment_form}) + return redirect('/book/') + |