diff options
author | Akshen Doke | 2017-03-30 10:54:05 +0530 |
---|---|---|
committer | Akshen | 2017-05-19 15:30:31 +0530 |
commit | 55585b6864e128dfd4fae5ae391373abf96c5ce5 (patch) | |
tree | 4fe8d974fd3ffd35246c1c16a192eb6b82db5d23 /workshop_app | |
parent | f751cd3c07619d8ee1e5b96c23b19cfae2005c0f (diff) | |
download | workshop_booking-55585b6864e128dfd4fae5ae391373abf96c5ce5.tar.gz workshop_booking-55585b6864e128dfd4fae5ae391373abf96c5ce5.tar.bz2 workshop_booking-55585b6864e128dfd4fae5ae391373abf96c5ce5.zip |
Recurrence done
Booking ToDo
Diffstat (limited to 'workshop_app')
-rw-r--r-- | workshop_app/forms.py | 11 | ||||
-rw-r--r-- | workshop_app/models.py | 40 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/base.html | 1 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/booking.html | 57 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/create_workshop.html | 4 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/manage.html | 73 | ||||
-rw-r--r-- | workshop_app/views.py | 91 |
7 files changed, 243 insertions, 34 deletions
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 @@ <link rel="stylesheet" href="{{ URL_ROOT }}/static/workshop_app/css/sticky-footer.css" type="text/css" /> </head> + <!-- For js/ajax and other related scripts --> {% 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 %} <nav class="navbar navbar-inverse"> <div class="container-fluid"> @@ -19,4 +23,57 @@ </ul> </div> </nav> +{% endblock %} + +{% block content %} + <div class="container"> + <table class="table table-hover"> + <thead> + <tr> + <th>Instructor Name</th> + <th>Course Name</th> + <th>Course Day</th> + <th>Booking</th> + </tr> + </thead> + {% csrf_token %} + {% for workshop in workshop_details %} + <tbody> + <tr> + <td>{{ workshop.1.0 }}</td> + <td>{{ workshop.1.1 }}</td> + <td>{{ workshop.0 }}</td> + <td><button id="book-btn" class="btn btn-primary btn-sm">Book</button></td> + </tr> + </tbody> + {% endfor %} + </table> + </div> + + <div class="container"> + <div class="Page-Nav" align="center"> + <nav aria-label="Page navigation"> + <ul class="pagination pagination-sm"> + <li class="page-item"> + {% if workshop_details.has_previous %} + <a class="page-link" tabindex="-1" + href="?page={{ workshop_details.previous_page_number }}">Previous</a> + {% endif %} + </li> + <li class="page-item"> + <span class="current"> + Page {{ workshop_details.number }} of {{ workshop_details.paginator.num_pages }} + </span> + </li> + <li class="page-item"> + {% if workshop_details.has_next %} + <a class="page-link" href="?page={{ workshop_details.next_page_number }}">Next + </a> + {% endif %} + </li> + </ul> + </nav> + </div> + </div> + {% 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 @@ <div class="container"> <form method="post"> {% csrf_token %} + <br/> + {{ form.media }} {{ form.as_p }} + + <br> <button class="btn btn-success" type="submit">Save</button> </form> 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 %} -<div class="container"> - {% csrf_token %} - {% for w in workshop_details %} - {{ w.date }}<br> - {{ w.start_time }}<br> - {{ w.end_time }}<br> - {{ w.workshop_creator }}<br> - {{ w.workshop_title }} - {% endfor %} -</div> + {% if workshop_occurence_list %} + <div class="container"> + <table class="table table-hover"> + <thead> + <tr> + <th>Instructor Name</th> + <th>Course Name</th> + <th>Course Day</th> + <th>Booking</th> + </tr> + </thead> + {% csrf_token %} + {% for workshop in workshop_occurence_list %} + {% for w in workshop %} + <tbody> + <tr> + <td>{{ w.user }}</td> + <td>{{ w.workshop }}</td> + <td>{{ w.date }}</td> + </tr> + </tbody> + {% endfor %} + {% endfor %} + </table> + </div> + + <div class="container"> + <div class="Page-Nav" align="center"> + <nav aria-label="Page navigation"> + <ul class="pagination pagination-sm"> + <li class="page-item"> + {% if workshop_occurence_list.has_previous %} + <a class="page-link" tabindex="-1" + href="?page={{ workshop_occurence_list.previous_page_number }}">Previous</a> + {% endif %} + </li> + <li class="page-item"> + <span class="current"> + Page {{ workshop_occurence_list.number }} of {{ workshop_occurence_list.paginator.num_pages }} + </span> + </li> + <li class="page-item"> + {% if workshop_occurence_list.has_next %} + <a class="page-link" href="?page={{ workshop_occurence_list.next_page_number }}">Next + </a> + {% endif %} + </li> + </ul> + </nav> + </div> + </div> + + {% else %} + <div class="container"> + <div class="jumbotron"> + <h1>Welcome Instructor</h1> + <p>Please navigate to <b>View Course list</b> and depending upon + your expertise and availability create a workshop by going to + <b>Create Event</b>.</p> + + </div> + </div> + {% 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: |