summaryrefslogtreecommitdiff
path: root/workshop_app
diff options
context:
space:
mode:
authorAkshen2017-04-05 17:39:11 +0530
committerAkshen2017-05-19 15:30:31 +0530
commitee1df45a5ead61691175009d2f6a93c95f31f5ad (patch)
tree1485e528f2a7116c5d04a16f6269a2489a7948d4 /workshop_app
parentb4936905e74ab6c4ba5fdbd5c400dd2d15269ff0 (diff)
downloadworkshop_booking-ee1df45a5ead61691175009d2f6a93c95f31f5ad.tar.gz
workshop_booking-ee1df45a5ead61691175009d2f6a93c95f31f5ad.tar.bz2
workshop_booking-ee1df45a5ead61691175009d2f6a93c95f31f5ad.zip
Booking View Done
ToDo email sending for both users
Diffstat (limited to 'workshop_app')
-rw-r--r--workshop_app/models.py9
-rw-r--r--workshop_app/send_mails.py10
-rw-r--r--workshop_app/templates/workshop_app/booking.html12
-rw-r--r--workshop_app/templates/workshop_app/create_workshop.html6
-rw-r--r--workshop_app/templates/workshop_app/manage.html20
-rw-r--r--workshop_app/templates/workshop_app/my_workshops.html143
-rw-r--r--workshop_app/templates/workshop_app/view_course_list.html2
-rw-r--r--workshop_app/views.py121
8 files changed, 287 insertions, 36 deletions
diff --git a/workshop_app/models.py b/workshop_app/models.py
index 03be064..040cf35 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -9,15 +9,12 @@ position_choices = (
("instructor", "Instructor")
)
-status_choices = (
- ("pending", "Pending"),
- ("confirm", "Confirm")
- )
def has_profile(user):
""" check if user has profile """
return True if hasattr(user, 'profile') else False
+
class Profile(models.Model):
"""Profile for users(instructors and coordinators)"""
@@ -56,7 +53,6 @@ class Course(models.Model):
return u"{0} {1}".format(self.course_name, self.course_duration)
-
class Workshop(models.Model):
"""Instructor Creates workshop based on
Courses available"""
@@ -89,8 +85,7 @@ class RequestedWorkshop(models.Model):
)
requested_workshop_date = models.DateField()
status = models.CharField(
- max_length=32, default="Pending",
- choices=status_choices
+ max_length=32, default="Pending"
)
requested_workshop_title = models.ForeignKey(
Course,
diff --git a/workshop_app/send_mails.py b/workshop_app/send_mails.py
index 4eff778..0d4173b 100644
--- a/workshop_app/send_mails.py
+++ b/workshop_app/send_mails.py
@@ -7,7 +7,10 @@ from workshop_portal.settings import (
EMAIL_USE_TLS
)
-def send_email(request, call_on, user_position=None):
+def send_email(request, call_on,
+ user_position=None, workshop_date=None,
+ workshop_title=None, user_name=None
+ ):
'''
Email sending function while registration and
booking confirmation.
@@ -38,7 +41,8 @@ def send_email(request, call_on, user_position=None):
elif call_on == 'Booking':
if user_position == 'instructor':
message = 'You got a workshop booking request \
- from user name '
+ from ' + user_name + ' for \
+ ' + workshop_title + ' on ' + workshop_date + ' please respond.'
send_mail(
'Python Workshop Booking | FOSSEE', message, EMAIL_HOST_USER,
[request.user.email], fail_silently=False
@@ -46,7 +50,7 @@ def send_email(request, call_on, user_position=None):
else:
message = 'Thank You for Booking on this platform.\n \
- Rules to be added \
+ ' + user_name +' \
If you face any issue during your session please contact \
fossee.'
send_mail(
diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html
index 153374a..c998be4 100644
--- a/workshop_app/templates/workshop_app/booking.html
+++ b/workshop_app/templates/workshop_app/booking.html
@@ -4,11 +4,14 @@
Booking
{% endblock %}
+
{% block extra %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
+
<script>
+ // Button function
function sendData(d){
var $dialog = $('<div></div').html(
'<form id="myform" action="">\
@@ -22,7 +25,7 @@
buttons: {
"Confirm": function(){
if($('#one').is(":checked") && $('#two').is(":checked")){
- booking_confirmed(d)
+ booking_confirmed(d);
$(this).dialog("close");
} else {
alert("Please select both the checkboxes");
@@ -49,9 +52,10 @@ function booking_confirmed(d){
},
success:function(response){
+ window.location.reload();
alert("success: " + response);
- }
- });
+ }
+ });
}
</script>
{% endblock %}
@@ -64,7 +68,7 @@ function booking_confirmed(d){
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
- <li class="active"><a href="#">Home</a></li>
+ <li class="active"><a href="{{ URL_ROOT}}/my_workshops">My Workshops</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html
index e38bf1a..613cd06 100644
--- a/workshop_app/templates/workshop_app/create_workshop.html
+++ b/workshop_app/templates/workshop_app/create_workshop.html
@@ -21,7 +21,7 @@
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="{{ URL_ROOT }}/view_course_list">View Course List</a></li>
-
+ <li class="active"><a href="{{ URL_ROOT }}/my_workshops">My Workshops</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
@@ -38,9 +38,7 @@
<br/>
{{ form.media }}
{{ form.as_p }}
-
-
- <br>
+ <br><br>
<button class="btn btn-success" type="submit">Save</button>
</form>
</div>
diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html
index 3afca6b..eab3f52 100644
--- a/workshop_app/templates/workshop_app/manage.html
+++ b/workshop_app/templates/workshop_app/manage.html
@@ -9,6 +9,7 @@
<ul class="nav navbar-nav">
<li class="active"><a href="{{ URL_ROOT }}/create_workshop">Create Event</a></li>
<li class="active"><a href="{{ URL_ROOT }}/view_course_list">View Course List</a></li>
+ <li class="active"><a href="{{ URL_ROOT }}/my_workshops">My Workshops</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
@@ -28,24 +29,24 @@
<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>
+ <tbody>
+ <tr>
+ <td>{{ w.user }}</td>
+ <td>{{ w.workshop }}</td>
+ <td>{{ w.date | date}}</td>
+ </tr>
+ </tbody>
{% endfor %}
{% endfor %}
</table>
</div>
+<!-- Page Navigation -->
<div class="container">
<div class="Page-Nav" align="center">
<nav aria-label="Page navigation">
@@ -78,7 +79,8 @@
<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>
+ <b>Create Event</b>. you can also check any workshop
+ requests by going to <b>My Workshops</b></p>
</div>
</div>
diff --git a/workshop_app/templates/workshop_app/my_workshops.html b/workshop_app/templates/workshop_app/my_workshops.html
new file mode 100644
index 0000000..77cd561
--- /dev/null
+++ b/workshop_app/templates/workshop_app/my_workshops.html
@@ -0,0 +1,143 @@
+{% extends "workshop_app/base.html" %}
+
+{% block title %}
+ My Workshops
+{% endblock %}
+
+{% block extra %}
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
+ <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
+
+ <script>
+ function sendData(d){
+ console.log(d);
+ var URL = "{{ URL_ROOT }}/my_workshops/"
+
+ $.ajax({
+ url: URL,
+ type: "POST",
+ dataType: 'json',
+ data: {
+ d,
+ csrfmiddlewaretoken: $("input[name=csrfmiddlewaretoken]").val()
+ },
+ });
+
+ window.location.reload();
+ }
+ </script>
+{% endblock %}
+
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ {% if request.user.profile.position == 'instructor' %}
+ <a class="navbar-brand" href="{{ URL_ROOT}}/manage">WebSiteName</a>
+ {% endif %}
+ </div>
+ {% if request.user.profile.position == 'instructor' %}
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="{{ URL_ROOT }}/create_workshop">Create Event</a></li>
+ <li class="active"><a href="{{ URL_ROOT }}/view_course_list">View Course List</a></li>
+ </ul>
+ {% else %}
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="{{ URL_ROOT }}/book">Home</a></li>
+ </ul>
+ {% endif %}
+
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+
+{% block content %}
+{% if workshop_occurences %}
+ <div class="container">
+ <table class="table table-hover">
+ <thead>
+ <tr>
+ {% if request.user.profile.position == 'instructor' %}
+ <th>Coordinator Name</th>
+ {% else %}
+ <th>Instructor Name</th>
+ {% endif %}
+ <th>Course Name</th>
+ <th>Course Day</th>
+ <th>Status</th>
+ </tr>
+ </thead>
+ {% csrf_token %}
+ {% for workshop in workshop_occurences %}
+ <tbody>
+ <tr>
+ {% if request.user.profile.position == 'instructor' %}
+ <td>{{ workshop.requested_workshop_coordinator }}</td>
+ {% else %}
+ <td>{{ workshop.requested_workshop_instructor }}</td>
+ {% endif %}
+ <td>{{ workshop.requested_workshop_title }}</td>
+ <td>{{ workshop.requested_workshop_date }}</td>
+ {% if workshop.status == 'Pending' %}
+ <td><span class = "label label-warning">{{ workshop.status }}</span></td>
+ {% elif workshop.status == 'ACCEPTED' %}
+ <td><span class = "label label-success">{{ workshop.status }}</span></td>
+ {% else %}
+ <td><span class = "label label-danger">{{ workshop.status }}</span></td>
+ {% endif %}
+ {% if request.user.profile.position == 'instructor' %}
+ <td><button class="btn btn-primary btn-sm" id="book-btn" onClick="sendData('{{workshop.requested_workshop_coordinator}},{{workshop.requested_workshop_date| safe}},{{ workshop.requested_workshop_title }},ACCEPTED')" > Accept</button></td>
+ {% endif %}
+ </tr>
+ </tbody>
+
+ {% endfor %}
+ </table>
+ </div>
+
+<!-- Page Navigation -->
+ <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_occurences.has_previous %}
+ <a class="page-link" tabindex="-1"
+ href="?page={{ workshop_occurences.previous_page_number }}">Previous</a>
+ {% endif %}
+ </li>
+ <li class="page-item">
+ <span class="current">
+ Page {{ workshop_occurences.number }} of {{ workshop_occurences.paginator.num_pages }}
+ </span>
+ </li>
+ <li class="page-item">
+ {% if workshop_occurences.has_next %}
+ <a class="page-link" href="?page={{ workshop_occurences.next_page_number }}">Next
+ </a>
+ {% endif %}
+ </li>
+ </ul>
+ </nav>
+ </div>
+ </div>
+
+{% else %}
+ <div class="container">
+ <div class="jumbotron">
+ <h1>Welcome Instructor</h1>
+ <p>Your workshop related information will be shown here, 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/templates/workshop_app/view_course_list.html b/workshop_app/templates/workshop_app/view_course_list.html
index e5c10e6..d1fb343 100644
--- a/workshop_app/templates/workshop_app/view_course_list.html
+++ b/workshop_app/templates/workshop_app/view_course_list.html
@@ -13,7 +13,9 @@
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="{{ URL_ROOT }}/create_workshop">Create Workshop</a></li>
+ <li class="active"><a href="{{ URL_ROOT }}/my_workshops">My Workshops</a></li>
</ul>
+
<ul class="nav navbar-nav navbar-right">
<li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
<li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
diff --git a/workshop_app/views.py b/workshop_app/views.py
index 83c59dc..a603f6e 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -33,11 +33,13 @@ def index(request):
return render(request, "workshop_app/index.html")
+
def is_instructor(user):
'''Check if the user is having instructor rights'''
if user.groups.filter(name='instructor').exists():
return True
+
def user_login(request):
'''Login'''
user = request.user
@@ -60,11 +62,13 @@ def user_login(request):
form = UserLoginForm()
return render(request, 'workshop_app/login.html', {"form": form})
+
def user_logout(request):
'''Logout'''
logout(request)
return render(request, 'workshop_app/logout.html')
+
def user_register(request):
'''User Registeration form'''
if request.method == 'POST':
@@ -101,8 +105,8 @@ def book(request):
if user.is_authenticated():
if user.groups.filter(name='instructor').count() > 0:
return redirect('/manage/')
- workshop_details = Workshop.objects.all()
+ workshop_details = Workshop.objects.all()
workshop_occurence = {}
for workshops in workshop_details:
dates = workshops.recurrences.between(
@@ -122,6 +126,15 @@ def book(request):
# workshop_occurence = OrderedDict(sorted(workshop_occurence.items()))
workshop_occurence = list(workshop_occurence.items())
+ requested_workshop = RequestedWorkshop.objects.all()
+
+ for j in requested_workshop:
+
+ j = j.requested_workshop_date.strftime("%d-%m-%Y")
+ for i in workshop_occurence:
+ if i[0] == j:
+ workshop_occurence.remove(i)
+
#Show upto 6 Workshops per page
paginator = Paginator(workshop_occurence, 6)
@@ -143,6 +156,7 @@ def book(request):
else:
return redirect('/login/')
+
@login_required
def book_workshop(request):
'''
@@ -152,9 +166,20 @@ def book_workshop(request):
user_position = request.user.profile.position
client_data = request.body.decode("utf-8").split("&")
client_data = client_data[0].split("%2C")
-
+ workshop_date = client_data[0][2:]
+ print(workshop_date)
send_email(request, call_on='Booking',
- user_position=user_position)
+ user_position='instructor',
+ workshop_date=workshop_date,
+ workshop_title='ISCP',
+ user_name='mahesh'
+ )
+
+
+ send_email(request, call_on='Booking',
+ workshop_date=workshop_date,
+ workshop_title='ISCP',
+ user_name=str(request.user))
instructor_profile = Profile.objects.filter(user=client_data[1])
workshop_list = Workshop.objects.get(
@@ -166,7 +191,7 @@ def book_workshop(request):
inc=True
)
for d in workshop_recurrence_list:
- if client_data[0][2:] == (d.strftime("%d-%m-%Y")):
+ if workshop_date == (d.strftime("%d-%m-%Y")):
rW_obj = RequestedWorkshop()
workshop_obj = Workshop.objects.get(
@@ -187,7 +212,6 @@ def book_workshop(request):
return HttpResponse("Some Error Occurred.")
-
@login_required
def manage(request):
user = request.user
@@ -204,16 +228,28 @@ def manage(request):
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
+ "user": str(user),
+ "workshop": workshop_details.workshop_title,
+ "date": workshop_occurence_list[i].date()
}]
+ requested_workshop = RequestedWorkshop.objects.filter(
+ requested_workshop_instructor=user.id
+ )
+
+ #Need to recheck logic
+ for j in range(len(requested_workshop)):
+ for i in workshop_occurence_list:
+ if i[0]['date'] == requested_workshop[j].requested_workshop_date:
+ workshop_occurence_list.remove(i)
+
+
#Show upto 3 Workshops per page
- paginator = Paginator(workshop_occurence_list, 3)
+ paginator = Paginator(workshop_occurence_list, 3)
page = request.GET.get('page')
try:
workshops = paginator.page(page)
@@ -235,11 +271,75 @@ def manage(request):
else:
return redirect('/login/')
+
+@login_required
+def my_workshops(request):
+ user = request.user
+
+ if user.is_authenticated():
+ if is_instructor(user):
+ if request.method == 'POST':
+ user_position = request.user.profile.position
+ client_data = request.body.decode("utf-8").split("&")
+ client_data = client_data[0].split("%2C")
+ workshop_date = datetime.strptime(
+ client_data[1], "%Y-%m-%d"
+ )
+
+ workshop_status = RequestedWorkshop.objects.get(requested_workshop_instructor=user.id,
+ requested_workshop_date=workshop_date
+ )
+ workshop_status.status = client_data[-1]
+ workshop_status.save()
+
+ workshop_occurence_list = RequestedWorkshop.objects.filter(
+ requested_workshop_instructor=user.id
+ )
+
+ #Show upto 6 Workshops per page
+ paginator = Paginator(workshop_occurence_list, 3)
+ 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)
+ template = 'workshop_app/my_workshops.html'
+ else:
+ workshop_occurence_list = RequestedWorkshop.objects.filter(
+ requested_workshop_coordinator=user.id
+ )
+
+ #Show upto 6 Workshops per page
+ paginator = Paginator(workshop_occurence_list, 9)
+ print(paginator)
+ 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)
+ template = 'workshop_app/my_workshops.html'
+ else:
+ redirect('/login')
+
+ return render(request, template,
+ {"workshop_occurences": workshop_occurences}
+ )
+
+
@login_required
def view_profile(request):
""" view instructor and coordinator profile """
return render(request, "workshop_app/view_profile.html")
+
@login_required
def edit_profile(request):
""" edit profile details facility for instructor and coordinator """
@@ -277,6 +377,7 @@ def edit_profile(request):
context['form'] = form
return render(request, 'workshop_app/edit_profile.html', context)
+
@login_required
def create_workshop(request):
'''Instructor creates workshops'''
@@ -301,6 +402,7 @@ def create_workshop(request):
else:
return redirect('/book/')
+
@login_required
def view_course_list(request):
'''Gives the course details '''
@@ -327,6 +429,7 @@ def view_course_list(request):
else:
return redirect('/book/')
+
@login_required
def view_course_details(request):
'''Gives the course details '''