summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2020-05-14 10:55:59 +0530
committerGitHub2020-05-14 10:55:59 +0530
commitc1b55f7a9a3e11ce4363206e86b6be3dfec90dd6 (patch)
treee563f9ab28c98544f0a0b08cbb273e04629b1677
parent83be359156350d851950f090dea9906d022e478b (diff)
parent2b38584ce8534c573fad2d3546acd4afbdd1521e (diff)
downloadworkshop_booking-c1b55f7a9a3e11ce4363206e86b6be3dfec90dd6.tar.gz
workshop_booking-c1b55f7a9a3e11ce4363206e86b6be3dfec90dd6.tar.bz2
workshop_booking-c1b55f7a9a3e11ce4363206e86b6be3dfec90dd6.zip
Merge pull request #130 from pnshiralkar/split-workshops-view
Split my_workshops view
-rw-r--r--workshop_app/static/workshop_app/js/datepicker.js50
-rw-r--r--workshop_app/templates/workshop_app/my_workshops.html234
-rw-r--r--workshop_app/templates/workshop_app/workshop_status_coordinator.html88
-rw-r--r--workshop_app/templates/workshop_app/workshop_status_instructor.html139
-rw-r--r--workshop_app/urls.py15
-rw-r--r--workshop_app/views.py189
6 files changed, 377 insertions, 338 deletions
diff --git a/workshop_app/static/workshop_app/js/datepicker.js b/workshop_app/static/workshop_app/js/datepicker.js
new file mode 100644
index 0000000..19f91d6
--- /dev/null
+++ b/workshop_app/static/workshop_app/js/datepicker.js
@@ -0,0 +1,50 @@
+//ToolTip popup function on-hover
+$(document).ready(function () {
+ $('[data-toggle="popover"]').popover({
+ placement: 'top',
+ trigger: 'hover'
+ });
+
+ $('[data-toggle="popinfo"]').popover({
+ placement: 'top',
+ trigger: 'hover'
+ });
+});
+
+// Change date modal
+function changeDate(date) {
+ let previous_date = new Date(date);
+ let dateToday = new Date();
+ let upto = new Date();
+
+ previous_date.setDate(previous_date.getDate() + 1);
+ upto.setFullYear(dateToday.getFullYear() + 1);
+
+ let counter = date.split(" ");
+ const id = counter.slice(-1).pop();
+ if (date[0] === 'P') {
+ counter = '.pDate' + id
+ $(counter).datepicker({
+ changeMonth: true,
+ changeYear: true,
+ minDate: dateToday,
+ maxDate: upto,
+ dateFormat: "yy-mm-dd",
+ });
+ $(".ui-dialog-content").dialog("close");
+ $('.myDialogP' + id).dialog();
+
+ } else {
+ counter = '.rDate' + id;
+ $(counter).datepicker({
+ changeMonth: true,
+ changeYear: true,
+ minDate: dateToday,
+ maxDate: upto,
+ dateFormat: "yy-mm-dd",
+ });
+ $(".ui-dialog-content").dialog("close");
+ $('.myDialogR' + id).dialog();
+
+ }
+}; \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/my_workshops.html b/workshop_app/templates/workshop_app/my_workshops.html
deleted file mode 100644
index b6e3731..0000000
--- a/workshop_app/templates/workshop_app/my_workshops.html
+++ /dev/null
@@ -1,234 +0,0 @@
-{% extends "workshop_app/base.html" %}
-
-{% block title %}
- Workshop Status
-{% endblock %}
-
-{% block extra-dependencies %}
- <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
- <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
-{% endblock %}
-{% block extra-custom-scripts %}
- <script>
- //ToolTip popup function on-hover
- $(document).ready(function () {
- $('[data-toggle="popover"]').popover({
- placement: 'top',
- trigger: 'hover'
- });
- });
-
- //ToolTip popup function on-hover
- $(document).ready(function () {
- $('[data-toggle="popinfo"]').popover({
- placement: 'top',
- trigger: 'hover'
- });
- });
-
- // Change date modal
- function changeDate(date) {
- var previous_date = new Date(date);
- var dateToday = new Date();
- var upto = new Date();
-
- previous_date.setDate(previous_date.getDate() + 1);
- upto.setFullYear(dateToday.getFullYear() + 1);
-
- if (date[0] == 'P') {
- var counter = date.split(" ");
- var id = counter.slice(-1).pop();
- counter = '.pDate' + id
- $(counter).datepicker({
- changeMonth: true,
- changeYear: true,
- minDate: dateToday,
- maxDate: upto,
- dateFormat: "yy-mm-dd",
- });
- $(".ui-dialog-content").dialog("close");
- $('.myDialogP' + id).dialog();
-
- } else {
- var counter = date.split(" ");
- var id = counter.slice(-1).pop();
- counter = '.rDate' + id;
- $(counter).datepicker({
- changeMonth: true,
- changeYear: true,
- minDate: dateToday,
- maxDate: upto,
- dateFormat: "yy-mm-dd",
- });
- $(".ui-dialog-content").dialog("close");
- $('.myDialogR' + id).dialog();
-
- }
- };
-
- </script>
-{% endblock %}
-
-
-{% block content %}
- {% if workshops %}
- <h3 align="center" style="color:#2952a2;">The status of your workshops </h3>
- <br>
-
- <!-- Accepted View -->
- <br>
- <div class="container">
- <h3 align="center" style="color: #04a9cf;"><strong>Workshops Accepted</strong></h3>
- <table class="table table-striped">
- <thead>
- <tr>
- {% if request.user.profile.position == 'instructor' %}
- <th>Coordinator Name</th>
- <th>Institute</th>
- {% else %}
- <th>Instructor Name</th>
- {% endif %}
- <th>Workshop Name</th>
- <th>Workshop Day</th>
- <th>Status</th>
- </tr>
- </thead>
- {% csrf_token %}
- {% for workshop in workshops %}
- <tbody>
- <tr>
- {% if workshop.status == 1 and workshop.workshop_type %}
- {% if request.user.profile.position == 'instructor' %}
- <td>
- <a href="{{ URL_ROOT }}/view_profile/{{ workshop.coordinator.profile.user.id }}">
- {{ workshop.coordinator.get_full_name }}</a></td>
- <td>{{ workshop.coordinator.profile.institute }}</td>
- {% else %}
- <td>{{ workshop.instructor.get_full_name }}</td>
- {% endif %}
- <td>{{ workshop.workshop_type |capfirst }}</td>
- {% if workshop.date > today %}
- <td>{{ workshop.date | date }}
- <span class="material-icons" style="cursor:pointer;" data-toggle="popinfo"
- title="Note"
- data-content="Click here to change date"
- class="datepicker"
- onclick="changeDate('R,{{ workshop.date| safe }}, {{ forloop.counter }}')">event</span>
- <div class="myDialogR{{ forloop.counter }}" style="display: none;"
- title="Select New Date">
- <form method="post">
- <input type="text" name="new_date" class="rDate{{ forloop.counter }}"/><br>
- <input type="hidden" name="action" value="change_date">
- <input type="hidden" name="workshop_id" value="{{ workshop.id }}">
- <input type="hidden" name="cid" value="{{ workshop.coordinator.id }}">
- {% csrf_token %}
- <button class="btn btn-primary btn-xs" type="submit">Save</button>
- </form>
- </div>
- </td>
- {% else %}
- <td>{{ workshop.date | date }}</td>
- {% endif %}
- <td><span class="badge badge-success">{{ workshop.get_status }}</span></td>
- {% endif %}
- </tr>
- </tbody>
-
- {% endfor %}
-
- </table>
- </div>
-
-
- <!-- Proposed View -->
- <br>
- <div class="container">
-
- {% if request.user.profile.position == 'instructor' %}
- <h3 align="center" style="color: #04a9cf;"><strong>Workshops Proposed By Coordinators</strong>
- </h3>
- {% else %}
- <h3 align="center" style="color: #04a9cf;"><strong>Workshops Proposed By Me</strong></h3>
- {% endif %}
- <table class="table table-striped">
- <thead>
- <tr>
- {% if request.user.profile.position == 'instructor' %}
- <th>Coordinator Name</th>
- <th>Institute</th>
- {% else %}
-
- {% endif %}
- <th>Workshop Name</th>
- <th>Workshop Day</th>
- <th>Status</th>
- {% if request.user.profile.position == 'instructor' %}
- <th>Action</th>
- {% endif %}
- </tr>
- </thead>
- {% csrf_token %}
- {% for workshop in workshops %}
- <tbody>
- <tr>
- {% if workshop.status == 0 and workshop.tnc_accepted %}
- {% if request.user.profile.position == 'instructor' %}
-
- <td>
- <a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.coordinator.profile.user.id }}">
- {{ workshop.coordinator.get_full_name }}</a></td>
- <td>{{ workshop.coordinator.profile.institute }}</td>
- {% endif %}
- <td>{{ workshop.workshop_type }}</td>
- <td>{{ workshop.date | date }}</td>
-
- <td><span class="badge badge-warning">{{ workshop.get_status }}</span></td>
- {% if request.user.profile.position == 'instructor' and workshop.status == 0 %}
- <td>
- <form method="post">
- <input type="hidden" name="action" value="accept">
- <input type="hidden" name="workshop_id" value="{{ workshop.id }}">
- {% csrf_token %}
- <button class="btn btn-primary btn-sm" id="book-btn" data-toggle="popover"
- title="Please Note"
- data-content="Once Accepted you can't Reject, you have to personally contact the Coordinator if the workshop is to be cancelled">
- Accept
- </button>
- </form>
- </td>
- {% endif %}
- {% endif %}
- </tr>
- </tbody>
-
- {% endfor %}
- </table>
- </div>
-
-
-
- {% else %}
- {% if request.user.profile.position == 'instructor' %}
- <div class="container">
- <div class="jumbotron">
- <h1>Welcome {{ user.first_name }}</h1>
- <p>Your workshop related information will be shown here, Please navigate to <b>Workshop list</b> and
- depending upon
- your expertise and availability create a workshop by going to
- <b>Create Workshop</b>.</p>
- </div>
- </div>
- {% else %}
- <div class="container">
- <div class="jumbotron">
- <h1>Welcome {{ user.first_name }}</h1>
- <p>Information Related to your workshops will be shown here, you can also
- propose a Workshop as per your available date in <strong>Workshops > Propose a Workshop
- tab</strong> .</p>
- </div>
- </div>
- {% endif %}
- {% endif %}
-
-{% endblock %}
diff --git a/workshop_app/templates/workshop_app/workshop_status_coordinator.html b/workshop_app/templates/workshop_app/workshop_status_coordinator.html
new file mode 100644
index 0000000..00e28b3
--- /dev/null
+++ b/workshop_app/templates/workshop_app/workshop_status_coordinator.html
@@ -0,0 +1,88 @@
+{% extends "workshop_app/base.html" %}
+
+{% block title %}
+ My Workshops
+{% endblock %}
+
+{% block extra-custom-scripts %}
+<style >
+ .table-heading{
+ color: #04a9cf;
+ }
+ </style>
+{% endblock %}
+
+{% block content %}
+ {% if not workshops %}
+ <div class="container">
+ <div class="jumbotron">
+ <h1>Welcome {{ user.first_name }}</h1>
+ <p>Information Related to your workshops will be shown here, you can also
+ propose a Workshop as per your available date in <strong>Propose Workshop tab</strong> .</p>
+ </div>
+ </div>
+ {% else %}
+ <h3 class="text-center">The status of your workshops </h3>
+ <br>
+
+ <!-- Accepted View -->
+
+ <br>
+ <div class="container">
+ <h3 class="text-center table-heading"><strong>Workshops Accepted</strong></h3>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Instructor Name</th>
+ <th>Workshop Name</th>
+ <th>Workshop Day</th>
+ <th>Status</th>
+ </tr>
+ </thead>
+
+ {% for workshop in workshops %}
+ <tbody>
+ <tr>
+ {% if workshop.status %}
+ <td>{{ workshop.instructor.get_full_name }}</td>
+ <td>{{ workshop.workshop_type |capfirst }}</td>
+ <td>{{ workshop.date | date }}</td>
+ <td><span class="badge badge-success">{{ workshop.get_status }}</span></td>
+ {% endif %}
+ </tr>
+ </tbody>
+ {% endfor %}
+
+ </table>
+ </div>
+
+ <!-- Proposed View -->
+
+ <br>
+ <div class="container">
+ <h3 class="text-center table-heading"><strong>Workshops Proposed By Me</strong></h3>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Workshop Name</th>
+ <th>Workshop Day</th>
+ <th>Status</th>
+ </tr>
+ </thead>
+ {% for workshop in workshops %}
+ <tbody>
+ <tr>
+ {% if not workshop.status and workshop.tnc_accepted %}
+ <td>{{ workshop.workshop_type }}</td>
+ <td>{{ workshop.date | date }}</td>
+ <td><span class="badge badge-warning">{{ workshop.get_status }}</span></td>
+ {% endif %}
+ </tr>
+ </tbody>
+
+ {% endfor %}
+ </table>
+ </div>
+ {% endif %}
+
+{% endblock %}
diff --git a/workshop_app/templates/workshop_app/workshop_status_instructor.html b/workshop_app/templates/workshop_app/workshop_status_instructor.html
new file mode 100644
index 0000000..ef64a70
--- /dev/null
+++ b/workshop_app/templates/workshop_app/workshop_status_instructor.html
@@ -0,0 +1,139 @@
+{% extends "workshop_app/base.html" %}
+
+{% block title %}
+ Workshop Status
+{% endblock %}
+
+{% block extra-dependencies %}
+ <style >
+ .table-heading{
+ color: #04a9cf;
+ }
+ </style>
+ <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
+ <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
+{% endblock %}
+{% block extra-custom-scripts %}
+ {% load static %}
+ <script src="{% static 'workshop_app/js/datepicker.js' %}"></script>
+{% endblock %}
+
+
+{% block content %}
+ {% if not workshops %}
+ <div class="container">
+ <div class="jumbotron">
+ <h1>Welcome {{ user.first_name }}</h1>
+ <p>Your workshop related information will be shown here, Please navigate to <b>Workshop list</b> and
+ depending upon
+ your expertise and availability create a workshop by going to
+ <b>Create Workshop</b>.</p>
+ </div>
+ </div>
+ {% else %}
+ <h3 class="text-center">The status of your workshops </h3>
+ <br>
+
+ <!-- Accepted View -->
+ <br>
+ <div class="container">
+ <h3 align="center" class="table-heading"><strong>Workshops Accepted</strong></h3>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Coordinator Name</th>
+ <th>Institute</th>
+ <th>Workshop Name</th>
+ <th>Workshop Day</th>
+ <th>Status</th>
+ </tr>
+ </thead>
+ {% for workshop in workshops %}
+ <tbody>
+ <tr>
+ {% if workshop.status %}
+ <td>
+ <a href="{% url 'view_profile' workshop.coordinator.profile.user.id %}">
+ {{ workshop.coordinator.get_full_name }}</a>
+ </td>
+ <td>{{ workshop.coordinator.profile.institute }}</td>
+ <td>{{ workshop.workshop_type |capfirst }}</td>
+ <td>{{ workshop.date | date }}
+
+ {% if workshop.date > today %}
+ <span class="material-icons datepicker btn"
+ data-toggle="popinfo"
+ title="Note"
+ data-content="Click here to change date"
+ onclick="changeDate('R,{{ workshop.date| safe }}, {{ forloop.counter }}')">event</span>
+ <div class="myDialogR{{ forloop.counter }}" style="display: none;"
+ title="Select New Date">
+ <form method="post" action="{% url 'change_workshop_date' workshop.id %}">
+ <input type="text" placeholder="New date" name="new_date"
+ class="rDate{{ forloop.counter }}"/><br>
+ {% csrf_token %}
+ <button class="btn btn-primary btn-xs" type="submit">Save</button>
+ </form>
+ </div>
+ {% endif %}
+ </td>
+ <td><span class="badge badge-success">{{ workshop.get_status }}</span></td>
+ {% endif %}
+ </tr>
+ </tbody>
+
+ {% endfor %}
+
+ </table>
+ </div>
+
+
+ <!-- Proposed View -->
+ <br>
+ <div class="container">
+ <h3 class="text-center table-heading"><strong>Workshops Proposed By Coordinators</strong>
+ </h3>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Coordinator Name</th>
+ <th>Institute</th>
+ <th>Workshop Name</th>
+ <th>Workshop Day</th>
+ <th>Status</th>
+ <th>Action</th>
+ </tr>
+ </thead>
+ {% csrf_token %}
+ {% for workshop in workshops %}
+ <tbody>
+ <tr>
+ {% if not workshop.status and workshop.tnc_accepted %}
+ <td>
+ <a href="{% url 'view_profile' workshop.coordinator.profile.user.id %}">
+ {{ workshop.coordinator.get_full_name }}</a>
+ </td>
+ <td>{{ workshop.coordinator.profile.institute }}</td>
+ <td>{{ workshop.workshop_type }}</td>
+ <td>{{ workshop.date | date }}</td>
+ <td><span class="badge badge-warning">{{ workshop.get_status }}</span></td>
+ <td>
+ <a href="{% url 'accept_workshop' workshop.id %}">
+ <button class="btn btn-primary btn-sm" id="book-btn" data-toggle="popover"
+ title="Please Note"
+ data-content="Once Accepted you can't Reject, you have to personally contact the Coordinator if the workshop is to be cancelled">
+ Accept
+ </button>
+ </a>
+ </td>
+ {% endif %}
+ </tr>
+ </tbody>
+
+ {% endfor %}
+ </table>
+ </div>
+ {% endif %}
+
+{% endblock %}
diff --git a/workshop_app/urls.py b/workshop_app/urls.py
index 4bb140c..5faf3ab 100644
--- a/workshop_app/urls.py
+++ b/workshop_app/urls.py
@@ -16,10 +16,6 @@ Including another URLconf
from django.conf.urls import url
from workshop_app import views
-js_info_dict = {
- 'packages': ('recurrence', ),
-}
-
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^register/$', views.user_register),
@@ -29,9 +25,12 @@ urlpatterns = [
url(r'^logout/$', views.user_logout),
url(r'^view_profile/$', views.view_profile),
url(r'^edit_profile/$', views.edit_profile),
- url(r'^my_workshops/$', views.my_workshops),
+ url(r'^workshop_status$', views.workshop_status_coordinator, name='workshop_status_coordinator'),
+ url(r'^dashboard$', views.workshop_status_instructor, name='workshop_status_instructor'),
+ url(r'^accept_workshop/(?P<workshop_id>\d+)', views.accept_workshop, name='accept_workshop'),
+ url(r'^change_workshop_date/(?P<workshop_id>\d+)$', views.change_workshop_date, name='change_workshop_date'),
url(r'^propose_workshop/$', views.propose_workshop),
url(r'^workshop_types/$', views.workshop_type_list),
- url(r'^workshop_type_details/([1-9][0-9]*)$', views.workshop_type_details),
- url(r'^view_profile/([1-9][0-9]*)$', views.view_comment_profile),
- ]
+ url(r'^workshop_type_details/(?P<workshop_type_id>\d+)$', views.workshop_type_details),
+ url(r'^view_profile/(?P<workshop_type_id>\d+)$', views.view_comment_profile, name='view_profile'),
+]
diff --git a/workshop_app/views.py b/workshop_app/views.py
index 5d0525c..5b88d90 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -1,3 +1,6 @@
+from django.db.models import Q
+from django.urls import reverse
+
try:
from StringIO import StringIO as string_io
except ImportError:
@@ -6,7 +9,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 +45,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_instructor')
+ return reverse('workshop_status_coordinator')
# View functions
@@ -150,7 +153,7 @@ def user_register(request):
)
else:
if request.user.is_authenticated and is_email_checked(request.user):
- return redirect('/my_workshops/')
+ return redirect(get_landing_page(request.user))
elif request.user.is_authenticated:
return render(request, 'workshop_app/activation.html')
form = UserRegistrationForm()
@@ -195,102 +198,96 @@ def edit_profile(request):
# Workshop views
@login_required
-def my_workshops(request):
+def workshop_status_coordinator(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/workshop_status_coordinator.html',
+ {"workshops": workshops})
- 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
- )
+@login_required
+def workshop_status_instructor(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()
+ workshops = Workshop.objects.filter(Q(
+ instructor=user.id,
+ date__gte=today,
+ ) | Q(status=0)).order_by('-date')
- today = timezone.now()
- proposed_workshop = Workshop.objects.filter(
- instructor=user.id,
- date__gte=today,
- ).order_by('-date')
+ return render(request, 'workshop_app/workshop_status_instructor.html',
+ {"workshops": workshops,
+ "today": today})
- proposed_workshop_pending = Workshop.objects.filter(
- status=0
- ).order_by('-date')
- workshops = list(proposed_workshop) + list(proposed_workshop_pending)
+@login_required
+def accept_workshop(request, workshop_id):
+ user = request.user
+ if not is_instructor(user):
+ return redirect(get_landing_page(user))
+ workshop = Workshop.objects.get(id=workshop_id)
+ # Change Status of the selected workshop
+ workshop.status = 1
+ workshop.instructor = user
+ workshop.save()
+
+ coordinator_profile = workshop.coordinator.profile
+
+ # For Instructor
+ send_email(request, call_on='Booking Confirmed',
+ user_position='instructor',
+ workshop_date=str(workshop.date),
+ workshop_title=workshop.workshop_type.name,
+ user_name=str(coordinator_profile.user.get_full_name()),
+ other_email=workshop.coordinator.email,
+ phone_number=coordinator_profile.phone_number,
+ institute=coordinator_profile.institute
+ )
+
+ # For Coordinator
+ send_email(request, call_on='Booking Confirmed',
+ workshop_date=str(workshop.date),
+ workshop_title=workshop.workshop_type.name,
+ other_email=workshop.coordinator.email,
+ phone_number=request.user.profile.phone_number
+ )
+ return redirect(reverse('workshop_status_instructor'))
- return render(request, 'workshop_app/my_workshops.html',
- {"workshops": workshops,
- "today": today})
- # 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/')
+@login_required
+def change_workshop_date(request, workshop_id):
+ user = request.user
+ if not is_instructor(user):
+ return redirect(get_landing_page(user))
+ if request.method == 'POST':
+ new_workshop_date = datetime.strptime(request.POST.get('new_date'), "%Y-%m-%d")
+ today = datetime.today()
+ if today <= new_workshop_date:
+ workshop = Workshop.objects.filter(id=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=workshop.first().coordinator.email
+ )
+ return redirect(reverse('workshop_status_instructor'))
# TODO: Show terms n conditions of selected ws type
@@ -316,7 +313,7 @@ def propose_workshop(request):
workshop_type=form_data.workshop_type,
coordinator=form_data.coordinator
).exists():
- return redirect('/my_workshops/')
+ return redirect(get_landing_page(user))
else:
form_data.save()
instructors = Profile.objects.filter(position='instructor')
@@ -330,7 +327,7 @@ def propose_workshop(request):
phone_number=user.profile.phone_number,
institute=user.profile.institute
)
- return redirect('/my_workshops/')
+ return redirect(get_landing_page(user))
# GET request
return render(
request, 'workshop_app/propose_workshop.html',
@@ -362,14 +359,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)