diff options
author | pnshiralkar | 2020-05-05 12:11:12 +0530 |
---|---|---|
committer | pnshiralkar | 2020-05-05 12:11:12 +0530 |
commit | 0fd8703ca8e0b4caf02df30d6e63320fe6f98338 (patch) | |
tree | 4203677d5afaff90b48edffc3863b2d6d9fda958 /workshop_app/views.py | |
parent | ae1b1252f203b9c02139f4fe4d1f097af7952a44 (diff) | |
download | workshop_booking-0fd8703ca8e0b4caf02df30d6e63320fe6f98338.tar.gz workshop_booking-0fd8703ca8e0b4caf02df30d6e63320fe6f98338.tar.bz2 workshop_booking-0fd8703ca8e0b4caf02df30d6e63320fe6f98338.zip |
My workshops view for coordinator done
Diffstat (limited to 'workshop_app/views.py')
-rw-r--r-- | workshop_app/views.py | 129 |
1 files changed, 34 insertions, 95 deletions
diff --git a/workshop_app/views.py b/workshop_app/views.py index 5d0525c..cd58326 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,3 +1,5 @@ +from django.urls import reverse + try: from StringIO import StringIO as string_io except ImportError: @@ -6,7 +8,7 @@ from datetime import datetime from django.contrib.auth import login, logout, authenticate from django.contrib.auth.decorators import login_required -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.core.paginator import Paginator from django.shortcuts import render, redirect from django.utils import timezone @@ -42,8 +44,8 @@ def is_instructor(user): def get_landing_page(user): # For now, landing pages of both instructor and coordinator are same if is_instructor(user): - return '/my_workshops/' - return '/my_workshops/' + return reverse('workshop_status') + return reverse('my_workshops') # View functions @@ -194,103 +196,40 @@ def edit_profile(request): # Workshop views -@login_required -def my_workshops(request): - user = request.user - if user.is_authenticated: - # View for instructor - if is_instructor(user): - if request.method == 'POST': - client_data = request.POST - action = request.POST.get('action') - if action == 'accept': - workshop = Workshop.objects.get(id=client_data.get('workshop_id')) - # Change Status of the selected workshop - workshop.status = 1 - workshop.instructor = user - workshop.save() - # Parameters for emails - coordinator_email = workshop.coordinator.email - coordinator_name = workshop.coordinator.profile.user.get_full_name() - coordinator_phone = workshop.coordinator.profile.phone_number - coordinator_institute = workshop.coordinator.profile.institute - instructor_phone = request.user.profile.phone_number - workshop_title = workshop.workshop_type.name - workshop_date = str(workshop.date) - - # For Instructor - send_email(request, call_on='Booking Confirmed', - user_position='instructor', - workshop_date=workshop_date, - workshop_title=workshop_title, - user_name=str(coordinator_name), - other_email=coordinator_email, - phone_number=coordinator_phone, - institute=coordinator_institute - ) - - # For Coordinator - send_email(request, call_on='Booking Confirmed', - workshop_date=workshop_date, - workshop_title=workshop_title, - other_email=coordinator_email, - phone_number=instructor_phone - ) - - elif action == 'change_date': - cid = client_data.get('cid') - new_workshop_date = datetime.strptime(client_data.get('new_date'), "%Y-%m-%d") - coordinator_email = User.objects.get(id=cid) - today = datetime.today() - if today > new_workshop_date: - # Invalid date - pass - else: - workshop = Workshop.objects.filter(id=client_data.get('workshop_id')) - workshop_date = workshop.first().date - workshop.update(date=new_workshop_date) - - # For Instructor - send_email(request, call_on='Change Date', - user_position='instructor', - workshop_date=str(workshop_date), - new_workshop_date=str(new_workshop_date.date()) - ) - # For Coordinator - send_email(request, call_on='Change Date', - new_workshop_date=str(new_workshop_date.date()), - workshop_date=str(workshop_date), - other_email=coordinator_email.email - ) - today = timezone.now() - proposed_workshop = Workshop.objects.filter( - instructor=user.id, - date__gte=today, - ).order_by('-date') +def my_workshops(request): + """ Workshops proposed by Coordinator """ + user = request.user + if is_instructor(user): + return redirect(get_landing_page(user)) + workshops = Workshop.objects.filter( + coordinator=user.id + ).order_by('-date') + return render(request, 'workshop_app/my_workshops.html', + {"workshops": workshops}) - proposed_workshop_pending = Workshop.objects.filter( - status=0 - ).order_by('-date') - workshops = list(proposed_workshop) + list(proposed_workshop_pending) +def workshop_status(request): + """ Workshops to accept and accepted by Instructor """ + user = request.user + if not is_instructor(user): + return redirect(get_landing_page(user)) + today = timezone.now().date() + proposed_workshop = Workshop.objects.filter( + instructor=user.id, + date__gte=today, + ).order_by('-date') - return render(request, 'workshop_app/my_workshops.html', - {"workshops": workshops, - "today": today}) + proposed_workshop_pending = Workshop.objects.filter( + status=0 + ).order_by('-date') - # Coordinator view - else: - workshops = Workshop.objects.filter( - coordinator=user.id - ).order_by('-date') - return render(request, 'workshop_app/my_workshops.html', - {"workshops": workshops}) - # Not logged in view - else: - return redirect('/login/') + workshops = list(proposed_workshop) + list(proposed_workshop_pending) + return render(request, 'workshop_app/workshop_status.html', + {"workshops": workshops, + "today": today}) # TODO: Show terms n conditions of selected ws type @@ -362,14 +301,14 @@ def workshop_type_list(request): paginator = Paginator(workshop_types, 12) # Show upto 12 workshops per page page = request.GET.get('page') - workshop_type = paginator.get_page(paginator.num_pages) + workshop_type = paginator.get_page(page) return render(request, 'workshop_app/workshop_type_list.html', {'workshop_type': workshop_type}) @login_required def view_comment_profile(request, user_id): - """instructor can view/post comments on coordinator profile """ + """Instructor can view coordinator profile """ user = request.user if is_instructor(user) and is_email_checked(user): coordinator_profile = Profile.objects.get(user_id=user_id) |