From 55585b6864e128dfd4fae5ae391373abf96c5ce5 Mon Sep 17 00:00:00 2001
From: Akshen Doke
Date: Thu, 30 Mar 2017 10:54:05 +0530
Subject: Recurrence done Booking ToDo
---
workshop_app/forms.py | 11 ++-
workshop_app/models.py | 40 +++++++---
workshop_app/templates/workshop_app/base.html | 1 +
workshop_app/templates/workshop_app/booking.html | 57 ++++++++++++++
.../templates/workshop_app/create_workshop.html | 4 +
workshop_app/templates/workshop_app/manage.html | 73 ++++++++++++++---
workshop_app/views.py | 91 +++++++++++++++++++---
7 files changed, 243 insertions(+), 34 deletions(-)
(limited to 'workshop_app')
diff --git a/workshop_app/forms.py b/workshop_app/forms.py
index a7f3fa1..eb74a99 100644
--- a/workshop_app/forms.py
+++ b/workshop_app/forms.py
@@ -1,6 +1,11 @@
from django import forms
from .models import Profile, Course, Workshop
-from string import punctuation, digits, letters
+from string import punctuation, digits
+try:
+ from string import letters
+except:
+ from string import ascii_letters as letters
+
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
@@ -129,6 +134,6 @@ class CreateWorkshop(forms.ModelForm):
class Meta:
model = Workshop
- fields = ['workshop_title', 'date', 'start_time', 'end_time']
-
+ fields = ['workshop_title', 'recurrences']
+
diff --git a/workshop_app/models.py b/workshop_app/models.py
index 8fe7d3a..a16c6a3 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -2,14 +2,17 @@
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import RegexValidator
-
+from recurrence.fields import RecurrenceField
position_choices = (
("coordinator", "Coordinator"),
("instructor", "Instructor")
)
-
+status_choices = (
+ ("pending", "Pending"),
+ ("confirm", "Confirm")
+ )
def has_profile(user):
""" check if user has profile """
@@ -41,7 +44,8 @@ class Profile(models.Model):
class Course(models.Model):
- """"Admin creates courses which can be used by the instructor to create workshops.
+ """"Admin creates courses which can be used by the instructor
+ to create workshops.
"""
course_name = models.CharField(max_length=120)
@@ -56,13 +60,29 @@ class Workshop(models.Model):
"""Instructor Creates workshop based on
Courses available"""
- workshop_creator = models.ForeignKey(User, on_delete=models.CASCADE)
- workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE,\
- help_text='Select the course you would like to create a workshop for')
- date = models.DateField()
- start_time = models.TimeField()
- end_time = models.TimeField()
+ workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE)
+ workshop_title = models.ForeignKey(
+ Course, on_delete=models.CASCADE,\
+ help_text='Select the course you \
+ would like to create a workshop for'
+ )
+
+ recurrences = RecurrenceField()
#status = models.BooleanField() Book, Pending, Booked
def __str__(self):
- return u"{0} | {1}".format(self.workshop_title, self.date)
+ return u"{0} | {1} ".format(self.workshop_title, self.workshop_instructor)
+
+
+# class completed_Workshop(models.Model):
+# """
+# Contains Data of Booked/Completed Workshops
+# """
+
+# workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE)
+# workshop_coordinator = models.ForeignKey(User)
+# status = models.CharField(max_length=32, choices=status_choices)
+# workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE)
+
+
+
diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html
index cebab31..9971dd4 100644
--- a/workshop_app/templates/workshop_app/base.html
+++ b/workshop_app/templates/workshop_app/base.html
@@ -17,6 +17,7 @@
+
{% block extra %}
{% endblock %}
diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html
index 01cd609..4657b4a 100644
--- a/workshop_app/templates/workshop_app/booking.html
+++ b/workshop_app/templates/workshop_app/booking.html
@@ -4,6 +4,10 @@
Booking
{% endblock %}
+{% block extra %}
+
+{% endblock %}
+
{% block header %}
+{% endblock %}
+
+{% block content %}
+
+
+
+
+ Instructor Name |
+ Course Name |
+ Course Day |
+ Booking |
+
+
+ {% csrf_token %}
+ {% for workshop in workshop_details %}
+
+
+ {{ workshop.1.0 }} |
+ {{ workshop.1.1 }} |
+ {{ workshop.0 }} |
+ |
+
+
+ {% endfor %}
+
+
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html
index 93de011..e643594 100644
--- a/workshop_app/templates/workshop_app/create_workshop.html
+++ b/workshop_app/templates/workshop_app/create_workshop.html
@@ -40,7 +40,11 @@
diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html
index b2404ed..3afca6b 100644
--- a/workshop_app/templates/workshop_app/manage.html
+++ b/workshop_app/templates/workshop_app/manage.html
@@ -20,15 +20,68 @@
{% block content %}
-
- {% csrf_token %}
- {% for w in workshop_details %}
- {{ w.date }}
- {{ w.start_time }}
- {{ w.end_time }}
- {{ w.workshop_creator }}
- {{ w.workshop_title }}
- {% endfor %}
-
+ {% if workshop_occurence_list %}
+
+
+
+
+ Instructor Name |
+ Course Name |
+ Course Day |
+ Booking |
+
+
+ {% csrf_token %}
+ {% for workshop in workshop_occurence_list %}
+ {% for w in workshop %}
+
+
+ {{ w.user }} |
+ {{ w.workshop }} |
+ {{ w.date }} |
+
+
+ {% endfor %}
+ {% endfor %}
+
+
+
+
+
+ {% else %}
+
+
+
Welcome Instructor
+
Please navigate to View Course list and depending upon
+ your expertise and availability create a workshop by going to
+ Create Event.
+
+
+
+ {% endif %}
{% endblock %}
\ No newline at end of file
diff --git a/workshop_app/views.py b/workshop_app/views.py
index e20a742..1fe5084 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -5,6 +5,7 @@ from .forms import (
)
from .models import Profile, User, has_profile, Workshop, Course
from django.template import RequestContext
+from datetime import datetime, date
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.decorators import login_required
from django.contrib import messages
@@ -12,6 +13,8 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.mail import send_mail
from django.shortcuts import render, redirect
from django.db import IntegrityError
+from collections import OrderedDict
+from dateutil.parser import parse
from workshop_portal.settings import (
EMAIL_HOST,
EMAIL_PORT,
@@ -99,7 +102,44 @@ def book(request):
if user.is_authenticated():
if user.groups.filter(name='instructor').count() > 0:
return redirect('/manage/')
- return render(request, "workshop_app/booking.html")
+ workshop_details = Workshop.objects.all()
+ workshop_occurence = {}
+ for workshops in workshop_details:
+ dates = workshops.recurrences.between(
+ datetime(2017, 3, 12, 0, 0, 0),
+ datetime(2017, 12, 31, 0, 0, 0), #Needs to be changed
+ inc=True
+ )
+
+ for d in range(len(dates)):
+ workshop_occurence[dates[d].strftime("%d-%m-%Y")] = [
+ workshops.workshop_instructor,
+ workshops.workshop_title
+ ]
+
+ # workshop_occurence = OrderedDict(sorted(workshop_occurence.items()))
+ workshop_occurence = list(workshop_occurence.items())
+
+
+
+
+ #Show upto 3 Workshops per page
+ paginator = Paginator(workshop_occurence, 6)
+ page = request.GET.get('page')
+ try:
+ workshop_occurences = paginator.page(page)
+ except PageNotAnInteger:
+ #If page is not an integer, deliver first page.
+ workshop_occurences = paginator.page(1)
+ except EmptyPage:
+ #If page is out of range(e.g 999999), deliver last page.
+ workshop_occurences = paginator.page(paginator.num_pages)
+
+ return render(
+ request, "workshop_app/booking.html",
+ {"workshop_details": workshop_occurences}
+ )
+
else:
return redirect('/login/')
@@ -107,13 +147,42 @@ def book(request):
def manage(request):
user = request.user
if user.is_authenticated():
- #print user.id, user
- if user.groups.filter(name='instructor').count() > 0: #Move user to the group via admin
- workshop_details = Workshop.objects.all()
+ #Move user to the group via admin
+ if user.groups.filter(name='instructor').count() > 0:
+ try:
+ workshop_details = Workshop.objects.get(workshop_instructor=user)
+ workshop_occurence_list = workshop_details.recurrences.between(
+ datetime(2017, 3, 12, 0, 0, 0),
+ datetime(2017, 12, 31, 0, 0, 0),
+ inc=True
+ )
+ for i in range(len(workshop_occurence_list)):
+ workshop_occurence_list[i] = [{
+ "user": str(user),
+ "workshop": workshop_details,
+ "date": workshop_occurence_list[i].date
+ }]
+
+
+ #Show upto 3 Workshops per page
+ paginator = Paginator(workshop_occurence_list, 3)
+ page = request.GET.get('page')
+ try:
+ workshops = paginator.page(page)
+ except PageNotAnInteger:
+ #If page is not an integer, deliver first page.
+ workshops = paginator.page(1)
+ except EmptyPage:
+ #If page is out of range(e.g 999999), deliver last page.
+ workshops = paginator.page(paginator.num_pages)
+
+ except:
+ workshops = None
return render(
- request, "workshop_app/manage.html",
- {"workshop_details": workshop_details}
- )
+ request, "workshop_app/manage.html",
+ {"workshop_occurence_list": workshops}
+ )
+
return redirect('/book/')
else:
return redirect('/login/')
@@ -165,16 +234,16 @@ def create_workshop(request):
'''Instructor creates workshops'''
user = request.user
- #profile = User.objects.get(user_id=user.id)
- print user.id
+
+
if is_instructor(user):
if request.method == 'POST':
form = CreateWorkshop(request.POST)
if form.is_valid():
form_data = form.save(commit=False)
#form_data.profile_id = profile.id
- form_data.workshop_creator = user
- form_data.workshop_creator.save()
+ form_data.workshop_instructor = user
+ form_data.workshop_instructor.save()
form_data.save()
return redirect('/manage/')
else:
--
cgit