diff options
author | Akshen | 2017-09-14 14:52:20 +0530 |
---|---|---|
committer | GitHub | 2017-09-14 14:52:20 +0530 |
commit | de0d3b7d9792813d5436ce59eb501d8ad3865b32 (patch) | |
tree | 6abc534ab9f51a387245a6c2b49da25b3eb64c8e | |
parent | 9991c9343f157ac23cf87c4c1cd371b8b21865b7 (diff) | |
parent | 01eafa2acd049473bfb21a4db8793cfacc4d09b7 (diff) | |
download | workshop_booking-de0d3b7d9792813d5436ce59eb501d8ad3865b32.tar.gz workshop_booking-de0d3b7d9792813d5436ce59eb501d8ad3865b32.tar.bz2 workshop_booking-de0d3b7d9792813d5436ce59eb501d8ad3865b32.zip |
Merge pull request #21 from Akshen/develop
Adds India Map
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | workshop_app/forms.py | 42 | ||||
-rw-r--r-- | workshop_app/models.py | 47 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/view_faq.html | 5 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/workshop_stats.html | 180 | ||||
-rw-r--r-- | workshop_app/tests/test_models.py | 26 | ||||
-rw-r--r-- | workshop_app/tests/test_views.py | 31 | ||||
-rw-r--r-- | workshop_app/views.py | 1998 |
8 files changed, 1300 insertions, 1032 deletions
@@ -39,3 +39,6 @@ migrations/ .idea/workshop_portal.iml .idea/workspace.xml .idea/vcs.xml + +#Emacs +\#*# diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 81eef79..054dee8 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -58,6 +58,45 @@ source = ( ("Others", "Others"), ) +states = ( + ("IN-AP", "Andhra Pradesh"), + ("IN-AR", "Arunachal Pradesh"), + ("IN-AS", "Assam"), + ("IN-BR", "Bihar"), + ("IN-CT", "Chhattisgarh"), + ("IN-GA", "Goa"), + ("IN-GJ", "Gujarat"), + ("IN-HR", "Haryana"), + ("IN-HP", "Himachal Pradesh"), + ("IN-JK", "Jammu and Kashmir"), + ("IN-JH", "Jharkhand"), + ("IN-KA", "Karnataka"), + ("IN-KL", "Kerala"), + ("IN-MP", "Madhya Pradesh"), + ("IN-MH", "Maharashtra"), + ("IN-MN", "Manipur"), + ("IN-ML", "Meghalaya"), + ("IN-MZ", "Mizoram"), + ("IN-NL", "Nagaland"), + ("IN-OR", "Odisha"), + ("IN-PB", "Punjab"), + ("IN-RJ", "Rajasthan"), + ("IN-SK", "Sikkim"), + ("IN-TN", "Tamil Nadu"), + ("IN-TG", "Telangana"), + ("IN-TR", "Tripura"), + ("IN-UT", "Uttarakhand"), + ("IN-UP", "Uttar Pradesh"), + ("IN-WB", "West Bengal"), + ("IN-AN", "Andaman and Nicobar Islands"), + ("IN-CH", "Chandigarh"), + ("IN-DN", "Dadra and Nagar Haveli"), + ("IN-DD", "Daman and Diu"), + ("IN-DL", "Delhi"), + ("IN-LD", "Lakshadweep"), + ("IN-PY", "Puducherry") + ) + class UserRegistrationForm(forms.Form): """A Class to create new form for User's Registration. @@ -83,6 +122,7 @@ class UserRegistrationForm(forms.Form): department = forms.ChoiceField(help_text='Department you work/study', choices=department_choices) location = forms.CharField(max_length=255, help_text="Place/City") + state = forms.ChoiceField(choices=states) source = forms.ChoiceField(choices=source) def clean_username(self): @@ -224,4 +264,4 @@ class ProposeWorkshopDateForm(forms.ModelForm): widgets = { 'proposed_workshop_date': forms.DateInput(attrs={ 'class':'datepicker'}) - }
\ No newline at end of file + } diff --git a/workshop_app/models.py b/workshop_app/models.py index 408b36a..4bf4489 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -45,6 +45,44 @@ source = ( ("Others", "Others"), ) +states = ( + ("IN-AP", "Andhra Pradesh"), + ("IN-AR", "Arunachal Pradesh"), + ("IN-AS", "Assam"), + ("IN-BR", "Bihar"), + ("IN-CT", "Chhattisgarh"), + ("IN-GA", "Goa"), + ("IN-GJ", "Gujarat"), + ("IN-HR", "Haryana"), + ("IN-HP", "Himachal Pradesh"), + ("IN-JK", "Jammu and Kashmir"), + ("IN-JH", "Jharkhand"), + ("IN-KA", "Karnataka"), + ("IN-KL", "Kerala"), + ("IN-MP", "Madhya Pradesh"), + ("IN-MH", "Maharashtra"), + ("IN-MN", "Manipur"), + ("IN-ML", "Meghalaya"), + ("IN-MZ", "Mizoram"), + ("IN-NL", "Nagaland"), + ("IN-OR", "Odisha"), + ("IN-PB", "Punjab"), + ("IN-RJ", "Rajasthan"), + ("IN-SK", "Sikkim"), + ("IN-TN", "Tamil Nadu"), + ("IN-TG", "Telangana"), + ("IN-TR", "Tripura"), + ("IN-UT", "Uttarakhand"), + ("IN-UP", "Uttar Pradesh"), + ("IN-WB", "West Bengal"), + ("IN-AN", "Andaman and Nicobar Islands"), + ("IN-CH", "Chandigarh"), + ("IN-DN", "Dadra and Nagar Haveli"), + ("IN-DD", "Daman and Diu"), + ("IN-DL", "Delhi"), + ("IN-LD", "Lakshadweep"), + ("IN-PY", "Puducherry") + ) def has_profile(user): """ check if user has profile """ @@ -70,12 +108,13 @@ class Profile(models.Model): )] ,null=False) position = models.CharField(max_length=32, choices=position_choices, - default='coordinator', - help_text='Select Coordinator if you want to organise a workshop\ - in your college/school. <br> Select Instructor if you want to conduct\ - a workshop.') + default='coordinator', + help_text='Select Coordinator if you want to organise a workshop\ + in your college/school. <br> Select Instructor if you want to conduct\ + a workshop.') source = models.CharField(max_length=255, blank=True,choices=source) location = models.CharField(max_length=255,blank=True, help_text="Place/City") + state = models.CharField(max_length=255, choices=states, default="IN-MH") is_email_verified = models.BooleanField(default=False) activation_key = models.CharField(max_length=255, blank=True, null=True) key_expiry_time = models.DateTimeField(blank=True, null=True) diff --git a/workshop_app/templates/workshop_app/view_faq.html b/workshop_app/templates/workshop_app/view_faq.html index b3eb5f1..9298254 100644 --- a/workshop_app/templates/workshop_app/view_faq.html +++ b/workshop_app/templates/workshop_app/view_faq.html @@ -163,6 +163,7 @@ </li> </ul> </div> +<br> +<br> - -{% endblock %}
\ No newline at end of file +{% endblock %} diff --git a/workshop_app/templates/workshop_app/workshop_stats.html b/workshop_app/templates/workshop_app/workshop_stats.html index bc6387b..d923c92 100644 --- a/workshop_app/templates/workshop_app/workshop_stats.html +++ b/workshop_app/templates/workshop_app/workshop_stats.html @@ -23,16 +23,21 @@ {% block extra %} <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://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> - + + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <!-- For Charts --> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script> + <!-- For Google GeoChart India Map --> + <script type='text/javascript' src='https://www.google.com/jsapi'></script> + <script> - var dateToday = new Date(); + var dateToday = new Date(); var upto = new Date(); dateToday.setDate(dateToday.getDate() - 1); @@ -82,8 +87,21 @@ {% block content %} <div class="container"> + <div class="row"> + <div class="col-md-6" align="left" > + <fieldset data-mini="true"> + <label for="radio-1">Monthly Count </label> + <input type="radio" name="radio-1" id="radio-1" value="NWPM"> + <label for="radio-2">Overall Count</label> + <input type="radio" name="radio-1" id="radio-2" value="OWC"> + <label for="radio-3">India Map</label> + <input type="radio" name="radio-1" id="radio-3" value="MOIN"> + </fieldset> + </div> + + {% if show_workshop_stats %} - <div align="right"> + <div align="right" class="col-md-6"> <form method="POST" > {% csrf_token %} <div class="form-group"> @@ -91,8 +109,8 @@ <input type="text" id="from" name="from"> <label for="to">to</label> <input type="text" id="to" name="to"> - <button class="btn btn-warning" type="submit" name="Download" value="Download">Download</button> - <button class="btn btn-info" type="submit" name="View" value="View">View</button> + <button class="btn btn-warning btn-sm" type="submit" name="Download" value="Download">Download</button> + <button class="btn btn-info btn-sm" type="submit" name="View" value="View">View</button> </div> </form> @@ -125,23 +143,23 @@ {% if workshop.proposed_workshop_date %} <tbody> <tr> - <td>{{ workshop.proposed_workshop_coordinator.get_full_name | capfirst }}</td> - <td>{{ workshop.proposed_workshop_coordinator.profile.institute | capfirst }}</td> - <td>{{ workshop.proposed_workshop_instructor.get_full_name }}</td> - <td>{{ workshop.proposed_workshop_title.workshoptype_name }}</td> - <td>{{ workshop.proposed_workshop_date | date}}</td> - <td>Coordinator</td> + <td>{{ workshop.proposed_workshop_coordinator.get_full_name | capfirst }}</td> + <td>{{ workshop.proposed_workshop_coordinator.profile.institute | capfirst }}</td> + <td>{{ workshop.proposed_workshop_instructor.get_full_name }}</td> + <td>{{ workshop.proposed_workshop_title.workshoptype_name }}</td> + <td>{{ workshop.proposed_workshop_date | date}}</td> + <td>Coordinator</td> </tr> </tbody> {% else %} <tbody> <tr> - <td>{{ workshop.requested_workshop_coordinator.get_full_name | capfirst }}</td> - <td>{{ workshop.requested_workshop_coordinator.profile.institute | capfirst }}</td> - <td>{{ workshop.requested_workshop_instructor.get_full_name }}</td> - <td>{{ workshop.requested_workshop_title.workshoptype_name }}</td> - <td>{{ workshop.requested_workshop_date | date}}</td> - <td>Instructor</td> + <td>{{ workshop.requested_workshop_coordinator.get_full_name | capfirst }}</td> + <td>{{ workshop.requested_workshop_coordinator.profile.institute | capfirst }}</td> + <td>{{ workshop.requested_workshop_instructor.get_full_name }}</td> + <td>{{ workshop.requested_workshop_title.workshoptype_name }}</td> + <td>{{ workshop.requested_workshop_date | date}}</td> + <td>Instructor</td> </tr> </tbody> {% endif %} @@ -156,7 +174,7 @@ <li class="page-item"> {% if upcoming_workshops.has_previous %} <a class="page-link" tabindex="-1" - href="?page={{ upcoming_workshops.previous_page_number }}">Previous</a> + href="?page={{ upcoming_workshops.previous_page_number }}">Previous</a> {% endif %} </li> <li class="page-item"> @@ -176,38 +194,48 @@ </div> {% else %} <div class="jumbotron"> - <h2>Permission to View Upcoming Workshops is set to false, please set it to true in settings.py</h2> + <h2>Permission to View Upcoming Workshops is set to false, please set it to true in settings.py</h2> </div> {% endif %} -</div> + </div> + -<br> <div class="row"> <br> <div class="col-md-12 "> <br> - <div class="widget" style="padding-left: 22px;"> - <fieldset> - <label for="radio-1">Number of Workshops per Month</label> - <input type="radio" name="radio-1" id="radio-1" value="NWPM"> - <label for="radio-2">Overall Workshop Count</label> - <input type="radio" name="radio-1" id="radio-2" value="OWC"> - </fieldset> - </div> - <canvas id="myChartPie" width="90px" height="12px"></canvas> - - <script> + <canvas id="myChartPie" ></canvas> + <script> $( function() { $( "fieldset" ).controlgroup(); }); var ctx1 = document.getElementById("myChartPie").getContext('2d'); var myChart; + $('input[type=radio]').change(function() { + if (this.value == 'NWPM') {//Number of Workshops per month - if(myChart){ + if(myChart){ myChart.destroy(); - } + } + + var dWidth = $(window).width() * 0.9; + var dHeight = $(window).height() * 0.9; + + $( "#myChartPie" ).dialog({ + resizable: false, + draggable: true, + title: 'Bar Chart', + closeOnEscape: true, + stack: true, + zIndex: 10000, + width: dWidth, + height: dHeight, + modal: true + }); + + document.getElementById("visualization").style.visibility='hidden'; myChart = new Chart(ctx1, { type: 'bar', data: { @@ -262,7 +290,24 @@ if(myChart){ myChart.destroy(); } - myChart = new Chart(ctx1, { + + var dWidth = $(window).width() * 0.9; + var dHeight = $(window).height() * 0.9; + + $( "#myChartPie" ).dialog({ + resizable: false, + draggable: true, + title: 'Pie Chart', + closeOnEscape: true, + stack: true, + zIndex: 10000, + width: dWidth, + height: dHeight, + modal: true + }); + + document.getElementById("visualization").style.visibility='hidden'; + myChart = new Chart(ctx1, { type: 'pie', data: { labels : {{ workshoptype_count.0 | safe}}, @@ -282,9 +327,68 @@ } }); } - }); - </script> + + else if (this.value == 'MOIN') { + if(myChart){ + myChart.destroy(); + } + + var dWidth = $(window).width() * 0.9; + var dHeight = $(window).height() * 0.9; + + $( "#visualization" ).dialog({ + resizable: false, + draggable: true, + title: 'Map of India', + closeOnEscape: true, + stack: true, + zIndex: 10000, + width: dWidth, + height: dHeight, + modal: true + }); + + document.getElementById("visualization").style.visibility='visible'; + function drawVisualization() { + var data = google.visualization.arrayToDataTable( + {{ india_map | safe }} + ); + + var opts = { + region: 'IN', + domain: 'IN', + displayMode: 'regions', + resolution: 'provinces', + colorAxis: {colors: ['orange']}, + legend: {position: 'top'}, + }; + + var geochart = new google.visualization.GeoChart( + document.getElementById('visualization')); + geochart.draw(data, opts); + }; + if(google) { + google.load('visualization', '1.0', { + packages: ['geochart'], + callback: function() { + // do stuff, if you wan't - it doesn't matter, because the page isn't blank! + drawVisualization(); + } + }) + } + } + }); + </script> + <style> + #visualization path { + stroke-width:1; /* control the countries borders width */ + stroke:#6699cc; /* choose a color for the border */ + } + </style> + <div id="visualization" style="width: 400px; height: 300px; display: block; margin: 0 auto;" ></div> + </div> </div> +</div> <br> {% endblock %} diff --git a/workshop_app/tests/test_models.py b/workshop_app/tests/test_models.py index 0b33842..44108ad 100644 --- a/workshop_app/tests/test_models.py +++ b/workshop_app/tests/test_models.py @@ -25,11 +25,13 @@ def setUpModule(): email='test.user@gmail.com', password='pass@123') instructor_profile = Profile.objects.create(user=testUser2, position='instructor', - department='cs', institute='ace', phone_number='1122334456', + department='computer engineering', institute='ace', phone_number='1122334456', + title='Doctor', source='Google', location='powai', state='IN-MH', is_email_verified=1) coordinator_profile = Profile.objects.create(user=demoUser2, position='coordinator', - department='IT', institute='iit', phone_number='1122334456', + department='IT', institute='iit', phone_number='1122334456',location='powai', + title='Doctor', source='Google', state='IN-MH', is_email_verified=1) workshoptype1 = WorkshopType.objects.create(workshoptype_name='ISCP', @@ -73,19 +75,25 @@ class ProfileModelTest(TestCase): self.testuser1 = User.objects.get(username='testuser1') self.demouser1 = User.objects.get(username='demouser1') - self.instructor_profile1 = Profile.objects.create(user=self.testuser1, position='instructor', - department='cs', institute='ace', phone_number='1123323344558899192', - is_email_verified=1) + self.instructor_profile1 = Profile.objects.create(user=self.testuser1, + position='instructor', department='computer engineering', + institute='ace', phone_number='1123323344', + title='Doctor', source='Google', location='powai', state='IN-MH', + is_email_verified=1) self.coordinator_profile1 = Profile.objects.create(user=self.demouser1, position='coordinator', - department='IT', institute='iit', phone_number='112233', - is_email_verified=1) + department='IT', institute='iit', phone_number='1122334455', + title='Doctor', source='Google', location='powai', state='IN-MH', + is_email_verified=1) def test_profile_model(self): self.assertEqual(self.demouser1.email,'test.user@gmail.com') self.assertEqual(self.testuser1.email,'test.user@gmail.com') self.assertEqual(self.instructor_profile1.position,'instructor') self.assertEqual(self.coordinator_profile1.position,'coordinator') + self.assertEqual(self.coordinator_profile1.location,'powai') + self.assertEqual(self.instructor_profile1.location,'powai') + self.assertEqual(self.coordinator_profile1.source,'Google') class WorkshopTypeModelTest(TestCase): @@ -197,7 +205,7 @@ class TestimonialModelTest(TestCase): self.testimonial_one = Testimonial.objects.create( name='ABC XYZ', institute='VIDYA GHAR', - department='CS', + department='computer engineering', message='Lorem ipsum dolor sit amet, consectetur \ tempor incididunt ut labore et dolore magna aliqua\ quis nostrud exercitation ullamco laboris nisi ut \ @@ -208,7 +216,7 @@ class TestimonialModelTest(TestCase): def test_testimonials_model(self): self.assertEqual(self.testimonial_one.name, 'ABC XYZ') - self.assertEqual(self.testimonial_one.department, 'CS') + self.assertEqual(self.testimonial_one.department, 'computer engineering') self.assertEqual(self.testimonial_one.institute, 'VIDYA GHAR') self.assertEqual(self.testimonial_one.message, 'Lorem ipsum dolor sit amet, consectetur \ tempor incididunt ut labore et dolore magna aliqua\ diff --git a/workshop_app/tests/test_views.py b/workshop_app/tests/test_views.py index 583efd2..ce5e4f2 100644 --- a/workshop_app/tests/test_views.py +++ b/workshop_app/tests/test_views.py @@ -32,8 +32,12 @@ class TestProfile(TestCase): user=self.user2, department='Computer Engineering', institute='ace', + title='Doctor', position='instructor', phone_number='1122993388', + location='mumbai', + source='Google', + state='IN-MH', is_email_verified=1 ) @@ -104,6 +108,8 @@ class TestProfile(TestCase): 'last name':'user', 'phone number': 1234567890, 'institute':'IIT', + 'location':'mumbai', + 'state': (2), 'department':(2)}) self.assertEqual(self.register_response.status_code,200) @@ -129,10 +135,14 @@ class TestWorkshopCreation(TestCase): self.user_one_profile = Profile.objects.create( user=self.user_one, - department='cs', + department='computer engineering', + title='Doctor', institute='IIT', position='instructor', + source='Google', phone_number='1122993388', + location='mumbai', + state='IN-MH', is_email_verified=1 ) @@ -152,9 +162,13 @@ class TestWorkshopCreation(TestCase): self.user_two_profile = Profile.objects.create( user=self.user_two, - department='cs', + department='computer engineering', institute='ace', position='coordinator', + title='Mr', + source='Google', + location='mumbai', + state='IN-MH', phone_number='1122993388', is_email_verified=1 ) @@ -180,8 +194,8 @@ class TestWorkshopCreation(TestCase): self.client.login(username=self.user_one, password='pass@123') self.client.post('/create_workshop/', { - 'workshop_title' : (2), - 'recurrences' : 'RRULE:FREQ=WEEKLY;UNTIL=20170624T183000Z;BYDAY=WE;' + 'workshop_title' : self.workshoptype.id, + 'recurrences' : 'RRULE:FREQ=WEEKLY;UNTIL=20170924T183000Z;BYDAY=WE;' }) self.workshop = Workshop.objects.get(workshop_instructor=self.user_one) self.assertEqual(str(self.workshop.workshop_title), 'ISCP 1days, 8hours a day') @@ -195,7 +209,7 @@ class TestWorkshopCreation(TestCase): 'condition_one': 1, 'condition_two': 1, 'condition_three': 1, - 'proposed_workshop_title': (2), + 'proposed_workshop_title': self.workshoptype.id, 'proposed_workshop_date': '2017-06-06' }) self.proposed_workshop = ProposeWorkshopDate.objects.get(proposed_workshop_date='2017-06-06') @@ -226,6 +240,10 @@ class TestWorkshopDashboard(TestCase): institute='IIT', position='instructor', phone_number='1122993388', + source='Google', + location='mumbai', + state='IN-MH', + title='Mr', is_email_verified=1 ) @@ -339,5 +357,4 @@ class TestWorkshopStats(TestCase): ) self.assertEqual(response.status_code, 200) self.assertEqual(response.get('Content-Disposition'),'attachment;\ - filename="records_from_2017-01-01_to_2017-12-31.csv"') - + filename="records_from_2017-01-01_to_2017-12-31.csv"')
\ No newline at end of file diff --git a/workshop_app/views.py b/workshop_app/views.py index d037d3b..1075eae 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,15 +1,15 @@ from .forms import ( - UserRegistrationForm, UserLoginForm, - ProfileForm, CreateWorkshop, - ProposeWorkshopDateForm - ) + UserRegistrationForm, UserLoginForm, + ProfileForm, CreateWorkshop, + ProposeWorkshopDateForm + ) from .models import ( - Profile, User, - has_profile, Workshop, - WorkshopType, RequestedWorkshop, - BookedWorkshop, ProposeWorkshopDate, - Testimonial - ) + Profile, User, + has_profile, Workshop, + WorkshopType, RequestedWorkshop, + BookedWorkshop, ProposeWorkshopDate, + Testimonial + ) from django.template.loader import get_template from django.template import RequestContext from datetime import datetime, date @@ -44,1037 +44,1093 @@ __credits__ = ["Mahesh Gudi", "Aditya P.", "Ankit Javalkar", def is_email_checked(user): - if hasattr(user, 'profile'): - return True if user.profile.is_email_verified else False - else: - return False + if hasattr(user, 'profile'): + return True if user.profile.is_email_verified else False + else: + return False def index(request): - '''Landing Page''' - - user = request.user - form = UserLoginForm() - if user.is_authenticated() and is_email_checked(user): - if user.groups.filter(name='instructor').count() > 0: - return redirect('/manage/') - return redirect('/book/') - elif request.method == "POST": - form = UserLoginForm(request.POST) - if form.is_valid(): - user = form.cleaned_data - login(request, user) - if user.groups.filter(name='instructor').count() > 0: - return redirect('/manage/') - return redirect('/book/') - - return render(request, "workshop_app/index.html", {"form": form}) + '''Landing Page''' + + user = request.user + form = UserLoginForm() + if user.is_authenticated() and is_email_checked(user): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/book/') + elif request.method == "POST": + form = UserLoginForm(request.POST) + if form.is_valid(): + user = form.cleaned_data + login(request, user) + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/book/') + + return render(request, "workshop_app/index.html", {"form": form}) def is_instructor(user): - '''Check if the user is having instructor rights''' - return True if user.groups.filter(name='instructor').count() > 0 else False - + '''Check if the user is having instructor rights''' + return True if user.groups.filter(name='instructor').count() > 0 else False + def user_login(request): - '''User Login''' - user = request.user - if user.is_authenticated(): - if user.groups.filter(name='instructor').count() > 0: - return redirect('/manage/') - return redirect('/book/') - - if request.method == "POST": - form = UserLoginForm(request.POST) - if form.is_valid(): - user = form.cleaned_data - login(request, user) - if user.groups.filter(name='instructor').count() > 0: - return redirect('/manage/') - return redirect('/book/') - else: - return render(request, 'workshop_app/login.html', {"form": form}) - else: - form = UserLoginForm() - return render(request, 'workshop_app/login.html', {"form": form}) + '''User Login''' + user = request.user + if user.is_authenticated(): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/book/') + + if request.method == "POST": + form = UserLoginForm(request.POST) + if form.is_valid(): + user = form.cleaned_data + login(request, user) + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/book/') + else: + return render(request, 'workshop_app/login.html', {"form": form}) + else: + 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') + '''Logout''' + logout(request) + return render(request, 'workshop_app/logout.html') def activate_user(request, key=None): - user = request.user - if key is None: - if user.is_authenticated() and user.profile.is_email_verified==0 and \ - timezone.now() > user.profile.key_expiry_time: - status = "1" - Profile.objects.get(user_id=user.profile.user_id).delete() - User.objects.get(id=user.profile.user_id).delete() - return render(request, 'workshop_app/activation.html', - {'status':status}) - elif user.is_authenticated() and user.profile.is_email_verified==0: - return render(request, 'workshop_app/activation.html') - elif user.is_authenticated() and user.profile.is_email_verified: - status = "2" - return render(request, 'workshop_app/activation.html', - {'status':status}) - else: - return redirect('/register/') - - try: - user = Profile.objects.get(activation_key=key) - except: - return redirect('/register/') - - if key == user.activation_key: - user.is_email_verified = True - user.save() - status = "0" - else: - logout(request) - return redirect('/logout/') - return render(request, 'workshop_app/activation.html', - {"status": status}) + user = request.user + if key is None: + if user.is_authenticated() and user.profile.is_email_verified==0 and \ + timezone.now() > user.profile.key_expiry_time: + status = "1" + Profile.objects.get(user_id=user.profile.user_id).delete() + User.objects.get(id=user.profile.user_id).delete() + return render(request, 'workshop_app/activation.html', + {'status':status}) + elif user.is_authenticated() and user.profile.is_email_verified==0: + return render(request, 'workshop_app/activation.html') + elif user.is_authenticated() and user.profile.is_email_verified: + status = "2" + return render(request, 'workshop_app/activation.html', + {'status':status}) + else: + return redirect('/register/') + + try: + user = Profile.objects.get(activation_key=key) + except: + return redirect('/register/') + + if key == user.activation_key: + user.is_email_verified = True + user.save() + status = "0" + else: + logout(request) + return redirect('/logout/') + return render(request, 'workshop_app/activation.html', + {"status": status}) def user_register(request): - '''User Registration form''' - if request.method == 'POST': - form = UserRegistrationForm(request.POST) - if form.is_valid(): - data = form.cleaned_data - username, password, key = form.save() - new_user = authenticate(username=username, password=password) - login(request, new_user) - user_position = request.user.profile.position - send_email( - request, call_on='Registration', - user_position=user_position, - key=key - ) - - return render(request, 'workshop_app/activation.html') - else: - if request.user.is_authenticated(): - return redirect('/view_profile/') - return render( - request, "workshop_app/registration/register.html", - {"form": form} - ) - else: - if request.user.is_authenticated() and is_email_checked(request.user): - return redirect('/my_workshops/') - elif request.user.is_authenticated(): - return render(request, 'workshop_app/activation.html') - form = UserRegistrationForm() - return render(request, "workshop_app/registration/register.html", {"form": form}) + '''User Registration form''' + if request.method == 'POST': + form = UserRegistrationForm(request.POST) + if form.is_valid(): + data = form.cleaned_data + username, password, key = form.save() + new_user = authenticate(username=username, password=password) + login(request, new_user) + user_position = request.user.profile.position + send_email( + request, call_on='Registration', + user_position=user_position, + key=key + ) + + return render(request, 'workshop_app/activation.html') + else: + if request.user.is_authenticated(): + return redirect('/view_profile/') + return render( + request, "workshop_app/registration/register.html", + {"form": form} + ) + else: + if request.user.is_authenticated() and is_email_checked(request.user): + return redirect('/my_workshops/') + elif request.user.is_authenticated(): + return render(request, 'workshop_app/activation.html') + form = UserRegistrationForm() + return render(request, "workshop_app/registration/register.html", {"form": form}) #This is shown to coordinator for booking workshops def book(request): - user = request.user - if user.is_authenticated(): - if is_email_checked(user): - if user.groups.filter(name='instructor').count() > 0: - return redirect('/manage/') - - workshop_details = Workshop.objects.all() - - workshop_occurence_list = [] - today = datetime.now() + dt.timedelta(days=3) - upto = datetime.now() + dt.timedelta(weeks=52) - for workshops in workshop_details: - dates = workshops.recurrences.between( - today, - upto, - inc=True - ) - - for d in range(len(dates)): - workshop_occurence = [ - dates[d].strftime("%d-%m-%Y"), - workshops.workshop_instructor, - workshops.workshop_title, - workshops.workshop_instructor_id, - workshops.workshop_title_id, - workshops.workshop_title.workshoptype_description - ] - - workshop_occurence_list.append(workshop_occurence) - del workshop_occurence - - #Gives you the objects of BookedWorkshop - bookedworkshop = BookedWorkshop.objects.all() - if len(bookedworkshop) != 0: - for b in bookedworkshop: - ''' - handles objects from bookedworkshop - -requested - -proposed - ''' - try: - x = b.booked_workshop_requested.requested_workshop_date.strftime("%d-%m-%Y") - y = b.booked_workshop_requested.requested_workshop_title - except: - x = b.booked_workshop_proposed.proposed_workshop_date.strftime("%d-%m-%Y") - y = b.booked_workshop_proposed.proposed_workshop_title - for a in workshop_occurence_list: - if a[0] == x and a[2] == y: - workshop_occurence_list.remove(a) - del x, y - - #Objects of RequestedWorkshop for that particular coordinator - rW_obj = RequestedWorkshop.objects.filter( - requested_workshop_coordinator=request.user - ) - for r in rW_obj: - x = r.requested_workshop_date.strftime("%d-%m-%Y") - for a in workshop_occurence_list: - if a[0] == x: - workshop_occurence_list.remove(a) - del x - - - #Show upto 12 Workshops per page - paginator = Paginator(workshop_occurence_list, 12) - 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('/activate_user/') - else: - return redirect('/login/') + user = request.user + if user.is_authenticated(): + if is_email_checked(user): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + + workshop_details = Workshop.objects.all() + + workshop_occurence_list = [] + today = datetime.now() + dt.timedelta(days=3) + upto = datetime.now() + dt.timedelta(weeks=52) + for workshops in workshop_details: + dates = workshops.recurrences.between( + today, + upto, + inc=True + ) + + for d in range(len(dates)): + workshop_occurence = [ + dates[d].strftime("%d-%m-%Y"), + workshops.workshop_instructor, + workshops.workshop_title, + workshops.workshop_instructor_id, + workshops.workshop_title_id, + workshops.workshop_title.workshoptype_description + ] + + workshop_occurence_list.append(workshop_occurence) + del workshop_occurence + + #Gives you the objects of BookedWorkshop + bookedworkshop = BookedWorkshop.objects.all() + if len(bookedworkshop) != 0: + for b in bookedworkshop: + ''' + handles objects from bookedworkshop + -requested + -proposed + ''' + try: + x = b.booked_workshop_requested.requested_workshop_date.strftime("%d-%m-%Y") + y = b.booked_workshop_requested.requested_workshop_title + except: + x = b.booked_workshop_proposed.proposed_workshop_date.strftime("%d-%m-%Y") + y = b.booked_workshop_proposed.proposed_workshop_title + for a in workshop_occurence_list: + if a[0] == x and a[2] == y: + workshop_occurence_list.remove(a) + del x, y + + #Objects of RequestedWorkshop for that particular coordinator + rW_obj = RequestedWorkshop.objects.filter( + requested_workshop_coordinator=request.user + ) + for r in rW_obj: + x = r.requested_workshop_date.strftime("%d-%m-%Y") + for a in workshop_occurence_list: + if a[0] == x: + workshop_occurence_list.remove(a) + del x + + + #Show upto 12 Workshops per page + paginator = Paginator(workshop_occurence_list, 12) + 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('/activate_user/') + else: + return redirect('/login/') @login_required def book_workshop(request): - ''' - Function for Updating RequestedWorkshop Model - ''' - 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 = client_data[0][2:] - - if client_data[-1] == '0': - queue = RequestedWorkshop.objects.filter( - requested_workshop_instructor=client_data[1], - requested_workshop_date=datetime.strptime( - client_data[0][2:], "%d-%m-%Y" - ), - requested_workshop_title=client_data[-2] - ).count() + 1 - - return HttpResponse(str(queue)) - - workshops_list = Workshop.objects.filter( - workshop_instructor=client_data[1], - workshop_title_id=client_data[2] - ) - today = datetime.now() + dt.timedelta(days=3) - upto = datetime.now() + dt.timedelta(weeks=52) - for workshop in workshops_list: - workshop_recurrence_list = workshop.recurrences.between( - today, - upto, - inc=True - ) - - rW_obj = RequestedWorkshop() - if RequestedWorkshop.objects.filter( - requested_workshop_instructor=workshop.workshop_instructor, - requested_workshop_date=datetime.strptime( - client_data[0][2:], "%d-%m-%Y", - ), - requested_workshop_coordinator=request.user, - requested_workshop_title=client_data[-1] - ).count() > 0: - - return HttpResponse(dedent("""You already have a booking - for this workshop please check the - instructors response in My Workshops tab and - also check your email.""")) - else: - for w in workshop_recurrence_list: - if workshop_date == (w.strftime("%d-%m-%Y")): - rW_obj.requested_workshop_instructor = workshop.workshop_instructor - rW_obj.requested_workshop_coordinator = request.user - rW_obj.requested_workshop_date = datetime.strptime( - workshop_date,"%d-%m-%Y" - ) - rW_obj.requested_workshop_title = workshop.workshop_title - rW_obj.save() - - queue = RequestedWorkshop.objects.filter( - requested_workshop_instructor=workshop.workshop_instructor, - requested_workshop_date=datetime.strptime( - workshop_date, "%d-%m-%Y", - ), - requested_workshop_title=client_data[-1] - ).count() - - # Mail to instructor - send_email(request, call_on='Booking', - user_position='instructor', - workshop_date=workshop_date, - workshop_title=workshop.workshop_title.workshoptype_name, - user_name=str(request.user.get_full_name()), - other_email=workshop.workshop_instructor.email - ) - phone_number = workshop.workshop_instructor.profile.phone_number - #Mail to coordinator - send_email(request, call_on='Booking', - workshop_date=workshop_date, - workshop_title=workshop.workshop_title.workshoptype_name, - user_name=workshop.workshop_instructor.profile.user.get_full_name(), - other_email=workshop.workshop_instructor.email, - phone_number=phone_number) - - return HttpResponse(dedent("""\ - Your request has been successful, Please check - your email for further information. Your request is number - {0} in the queue.""".format(str(queue)))) - else: - logout(request) - return HttpResponse("Some Error Occurred.") + ''' + Function for Updating RequestedWorkshop Model + ''' + 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 = client_data[0][2:] + + if client_data[-1] == '0': + queue = RequestedWorkshop.objects.filter( + requested_workshop_instructor=client_data[1], + requested_workshop_date=datetime.strptime( + client_data[0][2:], "%d-%m-%Y" + ), + requested_workshop_title=client_data[-2] + ).count() + 1 + + return HttpResponse(str(queue)) + + workshops_list = Workshop.objects.filter( + workshop_instructor=client_data[1], + workshop_title_id=client_data[2] + ) + today = datetime.now() + dt.timedelta(days=3) + upto = datetime.now() + dt.timedelta(weeks=52) + for workshop in workshops_list: + workshop_recurrence_list = workshop.recurrences.between( + today, + upto, + inc=True + ) + + rW_obj = RequestedWorkshop() + if RequestedWorkshop.objects.filter( + requested_workshop_instructor=workshop.workshop_instructor, + requested_workshop_date=datetime.strptime( + client_data[0][2:], "%d-%m-%Y", + ), + requested_workshop_coordinator=request.user, + requested_workshop_title=client_data[-1] + ).count() > 0: + + return HttpResponse(dedent("""You already have a booking + for this workshop please check the + instructors response in My Workshops tab and + also check your email.""")) + else: + for w in workshop_recurrence_list: + if workshop_date == (w.strftime("%d-%m-%Y")): + rW_obj.requested_workshop_instructor = workshop.workshop_instructor + rW_obj.requested_workshop_coordinator = request.user + rW_obj.requested_workshop_date = datetime.strptime( + workshop_date,"%d-%m-%Y" + ) + rW_obj.requested_workshop_title = workshop.workshop_title + rW_obj.save() + + queue = RequestedWorkshop.objects.filter( + requested_workshop_instructor=workshop.workshop_instructor, + requested_workshop_date=datetime.strptime( + workshop_date, "%d-%m-%Y", + ), + requested_workshop_title=client_data[-1] + ).count() + + # Mail to instructor + send_email(request, call_on='Booking', + user_position='instructor', + workshop_date=workshop_date, + workshop_title=workshop.workshop_title.workshoptype_name, + user_name=str(request.user.get_full_name()), + other_email=workshop.workshop_instructor.email + ) + phone_number = workshop.workshop_instructor.profile.phone_number + #Mail to coordinator + send_email(request, call_on='Booking', + workshop_date=workshop_date, + workshop_title=workshop.workshop_title.workshoptype_name, + user_name=workshop.workshop_instructor.profile.user.get_full_name(), + other_email=workshop.workshop_instructor.email, + phone_number=phone_number) + + return HttpResponse(dedent("""\ + Your request has been successful, Please check + your email for further information. Your request is number + {0} in the queue.""".format(str(queue)))) + else: + logout(request) + return HttpResponse("Some Error Occurred.") @login_required def manage(request): - user = request.user - - if user.is_authenticated() and is_email_checked(user): - #Move user to the group via admin - if user.groups.filter(name='instructor').count() > 0: - try: - #Can Handle Multiple Workshops - workshop_details = Workshop.objects.filter( - workshop_instructor=user.id - ) - - workshop_occurence_list = [] - today = datetime.now() + dt.timedelta(days=3) - upto = datetime.now() + dt.timedelta(weeks=52) - for workshop in workshop_details: - workshop_occurence = workshop.recurrences.between( - today, - upto, - inc=True - ) - for i in range(len(workshop_occurence)): - - workshop_occurence_list.append({ - "user": str(user), - "workshop": workshop.workshop_title, - "date": workshop_occurence[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: - a = requested_workshop[j].requested_workshop_date - b = requested_workshop[j].requested_workshop_title - if i['date'] == a and i['workshop'] == b: - workshop_occurence_list.remove(i) - del a, b - - - #Show upto 12 Workshops per page - paginator = Paginator(workshop_occurence_list, 12) - 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_occurence_list": workshops} - ) - - return redirect('/book/') - else: - return redirect('/activate_user/') + user = request.user + + if user.is_authenticated() and is_email_checked(user): + #Move user to the group via admin + if user.groups.filter(name='instructor').count() > 0: + try: + #Can Handle Multiple Workshops + workshop_details = Workshop.objects.filter( + workshop_instructor=user.id + ) + + workshop_occurence_list = [] + today = datetime.now() + dt.timedelta(days=3) + upto = datetime.now() + dt.timedelta(weeks=52) + for workshop in workshop_details: + workshop_occurence = workshop.recurrences.between( + today, + upto, + inc=True + ) + for i in range(len(workshop_occurence)): + + workshop_occurence_list.append({ + "user": str(user), + "workshop": workshop.workshop_title, + "date": workshop_occurence[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: + a = requested_workshop[j].requested_workshop_date + b = requested_workshop[j].requested_workshop_title + if i['date'] == a and i['workshop'] == b: + workshop_occurence_list.remove(i) + del a, b + + + #Show upto 12 Workshops per page + paginator = Paginator(workshop_occurence_list, 12) + 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_occurence_list": workshops} + ) + + return redirect('/book/') + else: + return redirect('/activate_user/') @login_required def my_workshops(request): - user = request.user - - if user.is_authenticated() and is_email_checked(user): - 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") - - if client_data[-1] == 'ACCEPTED': - workshop_date = datetime.strptime( - client_data[1], "%Y-%m-%d" - ) - - coordinator_obj = User.objects.get(username=client_data[0][2:]) - - workshop_status = RequestedWorkshop.objects.get( - requested_workshop_instructor=user.id, - requested_workshop_date=workshop_date, - requested_workshop_coordinator=coordinator_obj.id, - requested_workshop_title=client_data[2] - ) - - workshop_status.status = client_data[-1] - workshop_status.save() - booked_workshop_obj = BookedWorkshop() - booked_workshop_obj.booked_workshop_requested = workshop_status - booked_workshop_obj.save() - ws = workshop_status - cmail = ws.requested_workshop_coordinator.email - cname = ws.requested_workshop_coordinator.profile.user.get_full_name() - cnum = ws.requested_workshop_coordinator.profile.phone_number - cinstitute = ws.requested_workshop_coordinator.profile.institute - inum = request.user.profile.phone_number - wtitle = ws.requested_workshop_title.workshoptype_name - - #For Instructor - send_email(request, call_on='Booking Confirmed', - user_position='instructor', - workshop_date=str(client_data[1]), - workshop_title=wtitle, - user_name=str(cname), - other_email=cmail, - phone_number=cnum, - institute=cinstitute - ) - - #For Coordinator - send_email(request, call_on='Booking Confirmed', - workshop_date=str(client_data[1]), - workshop_title=wtitle, - other_email=cmail, - phone_number=inum - ) - - elif client_data[-1] == 'DELETED': - workshop_date = client_data[1] - workshops_list = Workshop.objects.filter(workshop_instructor=request.user.id, - workshop_title_id=client_data[2] - ) - - today = datetime.now() + dt.timedelta(days=3) - upto = datetime.now() + dt.timedelta(weeks=52) - for workshop in workshops_list: - workshop_recurrence_list = workshop.recurrences.between( - today, - upto, - inc=True - ) - - for d in workshop_recurrence_list: - if workshop_date == d.strftime("%Y-%m-%d"): - rW_obj = RequestedWorkshop() - rW_obj.requested_workshop_instructor = request.user - rW_obj.requested_workshop_coordinator = request.user - rW_obj.requested_workshop_date = workshop_date - rW_obj.requested_workshop_title = workshop.workshop_title - rW_obj.status = client_data[-1] - rW_obj.save() - bW_obj = BookedWorkshop() - bW_obj.booked_workshop_requested = rW_obj - bW_obj.save() - - #For instructor - send_email(request, call_on='Workshop Deleted', - workshop_date=str(client_data[1]), - workshop_title=workshop.workshop_title - ) - - return HttpResponse("Workshop Deleted") - - elif client_data[-1] == 'APPROVED': - workshop_date = datetime.strptime( - client_data[1], "%Y-%m-%d" - ) - - coordinator_obj = User.objects.get(username=client_data[0][2:]) - workshop_status = ProposeWorkshopDate.objects.get( - proposed_workshop_date=workshop_date, - proposed_workshop_coordinator=coordinator_obj.id, - proposed_workshop_title=client_data[2] - ) - - workshop_status.status = 'ACCEPTED' - workshop_status.proposed_workshop_instructor = user - workshop_status.save() - booked_workshop_obj = BookedWorkshop() - booked_workshop_obj.booked_workshop_proposed = workshop_status - booked_workshop_obj.save() - ws = workshop_status - cmail = ws.proposed_workshop_coordinator.email - cname = ws.proposed_workshop_coordinator.profile.user.get_full_name() - cnum = ws.proposed_workshop_coordinator.profile.phone_number - cinstitute = ws.proposed_workshop_coordinator.profile.institute - inum = request.user.profile.phone_number - wtitle = ws.proposed_workshop_title.workshoptype_name - - #For Instructor - send_email(request, call_on='Booking Confirmed', - user_position='instructor', - workshop_date=str(client_data[1]), - workshop_title=wtitle, - user_name=str(cname), - other_email=cmail, - phone_number=cnum, - institute=cinstitute - ) - - #For Coordinator - send_email(request, call_on='Booking Confirmed', - workshop_date=str(client_data[1]), - workshop_title=wtitle, - other_email=cmail, - phone_number=inum - ) - - else: - workshop_date = datetime.strptime( - client_data[1], "%Y-%m-%d" - ) - coordinator_obj = User.objects.get(username=client_data[0][2:]) - workshop_status = RequestedWorkshop.objects.get( - requested_workshop_instructor=user.id, - requested_workshop_date=workshop_date, - requested_workshop_coordinator=coordinator_obj.id, - requested_workshop_title=client_data[2] - ) - workshop_status.status = client_data[-1] - workshop_status.save() - ws = workshop_status - wtitle = ws.requested_workshop_title.workshoptype_name - cmail = ws.requested_workshop_coordinator.email - cname = ws.requested_workshop_coordinator.profile.user.get_full_name() - cnum = ws.requested_workshop_coordinator.profile.phone_number - cinstitute = ws.requested_workshop_coordinator.profile.institute - - #For Instructor - send_email(request, call_on='Booking Request Rejected', - user_position='instructor', - workshop_date=str(client_data[1]), - workshop_title=wtitle, - user_name=str(cname), - other_email=cmail, - phone_number=cnum, - institute=cinstitute - ) - - #For Coordinator - send_email(request, call_on='Booking Request Rejected', - workshop_date=str(client_data[1]), - workshop_title=wtitle, - other_email=cmail - ) - - workshops = [] - workshop_occurence_list = RequestedWorkshop.objects.filter( - requested_workshop_instructor=user.id - ) - for w in workshop_occurence_list: - workshops.append(w) - - proposed_workshop = ProposeWorkshopDate.objects.filter( - proposed_workshop_instructor=user.id - ) - for p in proposed_workshop: - workshops.append(p) - - proposed_workshop_pending = ProposeWorkshopDate.objects.filter( - status='Pending' - ) - for p in proposed_workshop_pending: - workshops.append(p) - - #Show upto 12 Workshops per page - paginator = Paginator(workshops[::-1], 12) - 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/my_workshops.html', - { "workshop_occurences" :workshop_occurences}) - - else: - workshops = [] - workshop_occurence_list = RequestedWorkshop.objects.filter( - requested_workshop_coordinator=user.id - ) - for w in workshop_occurence_list: - workshops.append(w) - - proposed_workshop = ProposeWorkshopDate.objects.filter( - proposed_workshop_coordinator=user.id - ) - for p in proposed_workshop: - workshops.append(p) - - #Show upto 12 Workshops per page - paginator = Paginator(workshops[::-1], 12) - 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/my_workshops.html', - {"workshop_occurences": workshop_occurences}) - else: - return redirect('/login/') + user = request.user + + if user.is_authenticated() and is_email_checked(user): + 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") + + if client_data[-1] == 'ACCEPTED': + workshop_date = datetime.strptime( + client_data[1], "%Y-%m-%d" + ) + + coordinator_obj = User.objects.get(username=client_data[0][2:]) + + workshop_status = RequestedWorkshop.objects.get( + requested_workshop_instructor=user.id, + requested_workshop_date=workshop_date, + requested_workshop_coordinator=coordinator_obj.id, + requested_workshop_title=client_data[2] + ) + + workshop_status.status = client_data[-1] + workshop_status.save() + booked_workshop_obj = BookedWorkshop() + booked_workshop_obj.booked_workshop_requested = workshop_status + booked_workshop_obj.save() + ws = workshop_status + cmail = ws.requested_workshop_coordinator.email + cname = ws.requested_workshop_coordinator.profile.user.get_full_name() + cnum = ws.requested_workshop_coordinator.profile.phone_number + cinstitute = ws.requested_workshop_coordinator.profile.institute + inum = request.user.profile.phone_number + wtitle = ws.requested_workshop_title.workshoptype_name + + #For Instructor + send_email(request, call_on='Booking Confirmed', + user_position='instructor', + workshop_date=str(client_data[1]), + workshop_title=wtitle, + user_name=str(cname), + other_email=cmail, + phone_number=cnum, + institute=cinstitute + ) + + #For Coordinator + send_email(request, call_on='Booking Confirmed', + workshop_date=str(client_data[1]), + workshop_title=wtitle, + other_email=cmail, + phone_number=inum + ) + + elif client_data[-1] == 'DELETED': + workshop_date = client_data[1] + workshops_list = Workshop.objects.filter(workshop_instructor=request.user.id, + workshop_title_id=client_data[2] + ) + + today = datetime.now() + dt.timedelta(days=3) + upto = datetime.now() + dt.timedelta(weeks=52) + for workshop in workshops_list: + workshop_recurrence_list = workshop.recurrences.between( + today, + upto, + inc=True + ) + + for d in workshop_recurrence_list: + if workshop_date == d.strftime("%Y-%m-%d"): + rW_obj = RequestedWorkshop() + rW_obj.requested_workshop_instructor = request.user + rW_obj.requested_workshop_coordinator = request.user + rW_obj.requested_workshop_date = workshop_date + rW_obj.requested_workshop_title = workshop.workshop_title + rW_obj.status = client_data[-1] + rW_obj.save() + bW_obj = BookedWorkshop() + bW_obj.booked_workshop_requested = rW_obj + bW_obj.save() + + #For instructor + send_email(request, call_on='Workshop Deleted', + workshop_date=str(client_data[1]), + workshop_title=workshop.workshop_title + ) + + return HttpResponse("Workshop Deleted") + + elif client_data[-1] == 'APPROVED': + workshop_date = datetime.strptime( + client_data[1], "%Y-%m-%d" + ) + + coordinator_obj = User.objects.get(username=client_data[0][2:]) + workshop_status = ProposeWorkshopDate.objects.get( + proposed_workshop_date=workshop_date, + proposed_workshop_coordinator=coordinator_obj.id, + proposed_workshop_title=client_data[2] + ) + + workshop_status.status = 'ACCEPTED' + workshop_status.proposed_workshop_instructor = user + workshop_status.save() + booked_workshop_obj = BookedWorkshop() + booked_workshop_obj.booked_workshop_proposed = workshop_status + booked_workshop_obj.save() + ws = workshop_status + cmail = ws.proposed_workshop_coordinator.email + cname = ws.proposed_workshop_coordinator.profile.user.get_full_name() + cnum = ws.proposed_workshop_coordinator.profile.phone_number + cinstitute = ws.proposed_workshop_coordinator.profile.institute + inum = request.user.profile.phone_number + wtitle = ws.proposed_workshop_title.workshoptype_name + + #For Instructor + send_email(request, call_on='Booking Confirmed', + user_position='instructor', + workshop_date=str(client_data[1]), + workshop_title=wtitle, + user_name=str(cname), + other_email=cmail, + phone_number=cnum, + institute=cinstitute + ) + + #For Coordinator + send_email(request, call_on='Booking Confirmed', + workshop_date=str(client_data[1]), + workshop_title=wtitle, + other_email=cmail, + phone_number=inum + ) + + else: + workshop_date = datetime.strptime( + client_data[1], "%Y-%m-%d" + ) + coordinator_obj = User.objects.get(username=client_data[0][2:]) + workshop_status = RequestedWorkshop.objects.get( + requested_workshop_instructor=user.id, + requested_workshop_date=workshop_date, + requested_workshop_coordinator=coordinator_obj.id, + requested_workshop_title=client_data[2] + ) + workshop_status.status = client_data[-1] + workshop_status.save() + ws = workshop_status + wtitle = ws.requested_workshop_title.workshoptype_name + cmail = ws.requested_workshop_coordinator.email + cname = ws.requested_workshop_coordinator.profile.user.get_full_name() + cnum = ws.requested_workshop_coordinator.profile.phone_number + cinstitute = ws.requested_workshop_coordinator.profile.institute + + #For Instructor + send_email(request, call_on='Booking Request Rejected', + user_position='instructor', + workshop_date=str(client_data[1]), + workshop_title=wtitle, + user_name=str(cname), + other_email=cmail, + phone_number=cnum, + institute=cinstitute + ) + + #For Coordinator + send_email(request, call_on='Booking Request Rejected', + workshop_date=str(client_data[1]), + workshop_title=wtitle, + other_email=cmail + ) + + workshops = [] + workshop_occurence_list = RequestedWorkshop.objects.filter( + requested_workshop_instructor=user.id + ) + for w in workshop_occurence_list: + workshops.append(w) + + proposed_workshop = ProposeWorkshopDate.objects.filter( + proposed_workshop_instructor=user.id + ) + for p in proposed_workshop: + workshops.append(p) + + proposed_workshop_pending = ProposeWorkshopDate.objects.filter( + status='Pending' + ) + for p in proposed_workshop_pending: + workshops.append(p) + + #Show upto 12 Workshops per page + paginator = Paginator(workshops[::-1], 12) + 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/my_workshops.html', + { "workshop_occurences" :workshop_occurences}) + + else: + workshops = [] + workshop_occurence_list = RequestedWorkshop.objects.filter( + requested_workshop_coordinator=user.id + ) + for w in workshop_occurence_list: + workshops.append(w) + + proposed_workshop = ProposeWorkshopDate.objects.filter( + proposed_workshop_coordinator=user.id + ) + for p in proposed_workshop: + workshops.append(p) + + #Show upto 12 Workshops per page + paginator = Paginator(workshops[::-1], 12) + 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/my_workshops.html', + {"workshop_occurences": workshop_occurences}) + else: + return redirect('/login/') @login_required def propose_workshop(request): - '''Coordinator proposed a workshop and date''' - - user = request.user - if is_email_checked(user): - if is_instructor(user): - return redirect('/manage/') - else: - if request.method == 'POST': - form = ProposeWorkshopDateForm(request.POST) - if form.is_valid(): - form_data = form.save(commit=False) - form_data.proposed_workshop_coordinator = user - #Avoiding Duplicate workshop entries for same date and workshop_title - if ProposeWorkshopDate.objects.filter( - proposed_workshop_date=form_data.proposed_workshop_date, - proposed_workshop_title=form_data.proposed_workshop_title, - proposed_workshop_coordinator=form_data.proposed_workshop_coordinator - ).exists(): - return redirect('/my_workshops/') - else: - form_data.proposed_workshop_coordinator.save() - form_data.save() - instructors = Profile.objects.filter(position='instructor') - for i in instructors: - send_email(request, call_on='Proposed Workshop', - user_position='instructor', - workshop_date=str(form_data.proposed_workshop_date), - workshop_title=form_data.proposed_workshop_title, - user_name=str(user.get_full_name()), - other_email=i.user.email, - phone_number=user.profile.phone_number, - institute=user.profile.institute - ) - return redirect('/my_workshops/') - else: - form = ProposeWorkshopDateForm() - return render( - request, 'workshop_app/propose_workshop.html', - {"form": form } - ) - else: - return render(request, 'workshop_app/activation.html') + '''Coordinator proposed a workshop and date''' + + user = request.user + if is_email_checked(user): + if is_instructor(user): + return redirect('/manage/') + else: + if request.method == 'POST': + form = ProposeWorkshopDateForm(request.POST) + if form.is_valid(): + form_data = form.save(commit=False) + form_data.proposed_workshop_coordinator = user + #Avoiding Duplicate workshop entries for same date and workshop_title + if ProposeWorkshopDate.objects.filter( + proposed_workshop_date=form_data.proposed_workshop_date, + proposed_workshop_title=form_data.proposed_workshop_title, + proposed_workshop_coordinator=form_data.proposed_workshop_coordinator + ).exists(): + return redirect('/my_workshops/') + else: + form_data.proposed_workshop_coordinator.save() + form_data.save() + instructors = Profile.objects.filter(position='instructor') + for i in instructors: + send_email(request, call_on='Proposed Workshop', + user_position='instructor', + workshop_date=str(form_data.proposed_workshop_date), + workshop_title=form_data.proposed_workshop_title, + user_name=str(user.get_full_name()), + other_email=i.user.email, + phone_number=user.profile.phone_number, + institute=user.profile.institute + ) + return redirect('/my_workshops/') + else: + form = ProposeWorkshopDateForm() + return render( + request, 'workshop_app/propose_workshop.html', + {"form": form } + ) + else: + return render(request, 'workshop_app/activation.html') @login_required def view_profile(request): - """ view instructor and coordinator profile """ - user = request.user - if is_email_checked(user) and user.is_authenticated(): - return render(request, "workshop_app/view_profile.html") - else: - if user.is_authenticated(): - return render(request, 'workshop_app/activation.html') - else: - try: - logout(request) - return redirect('/login/') - except: - return redirect('/register/') + """ view instructor and coordinator profile """ + user = request.user + if is_email_checked(user) and user.is_authenticated(): + return render(request, "workshop_app/view_profile.html") + else: + if user.is_authenticated(): + return render(request, 'workshop_app/activation.html') + else: + try: + logout(request) + return redirect('/login/') + except: + return redirect('/register/') @login_required def edit_profile(request): - """ edit profile details facility for instructor and coordinator """ - - user = request.user - if is_email_checked(user): - if is_instructor(user): - template = 'workshop_app/manage.html' - else: - template = 'workshop_app/booking.html' - else: - try: - logout(request) - return redirect('/login/') - except: - return redirect('/register/') - - context = {'template': template} - if has_profile(user) and is_email_checked(user): - profile = Profile.objects.get(user_id=user.id) - else: - profile = None - - if request.method == 'POST': - form = ProfileForm(request.POST, user=user, instance=profile) - if form.is_valid(): - form_data = form.save(commit=False) - form_data.user = user - form_data.user.first_name = request.POST['first_name'] - form_data.user.last_name = request.POST['last_name'] - form_data.user.save() - form_data.save() - - return render( - request, 'workshop_app/profile_updated.html' - ) - else: - context['form'] = form - return render(request, 'workshop_app/edit_profile.html', context) - else: - form = ProfileForm(user=user, instance=profile) - return render(request, 'workshop_app/edit_profile.html', {'form':form}) + """ edit profile details facility for instructor and coordinator """ + + user = request.user + if is_email_checked(user): + if is_instructor(user): + template = 'workshop_app/manage.html' + else: + template = 'workshop_app/booking.html' + else: + try: + logout(request) + return redirect('/login/') + except: + return redirect('/register/') + + context = {'template': template} + if has_profile(user) and is_email_checked(user): + profile = Profile.objects.get(user_id=user.id) + else: + profile = None + + if request.method == 'POST': + form = ProfileForm(request.POST, user=user, instance=profile) + if form.is_valid(): + form_data = form.save(commit=False) + form_data.user = user + form_data.user.first_name = request.POST['first_name'] + form_data.user.last_name = request.POST['last_name'] + form_data.user.save() + form_data.save() + + return render( + request, 'workshop_app/profile_updated.html' + ) + else: + context['form'] = form + return render(request, 'workshop_app/edit_profile.html', context) + else: + form = ProfileForm(user=user, instance=profile) + return render(request, 'workshop_app/edit_profile.html', {'form':form}) @login_required def create_workshop(request): - '''Instructor creates workshops''' - - user = request.user - if is_instructor(user) and is_email_checked(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_instructor = user - form_data.workshop_instructor.save() - form_data.save() - return redirect('/manage/') - else: - form = CreateWorkshop() - return render( - request, 'workshop_app/create_workshop.html', - {"form": form } - ) - else: - return redirect('/book/') + '''Instructor creates workshops''' + + user = request.user + if is_instructor(user) and is_email_checked(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_instructor = user + form_data.workshop_instructor.save() + form_data.save() + return redirect('/manage/') + else: + form = CreateWorkshop() + return render( + request, 'workshop_app/create_workshop.html', + {"form": form } + ) + else: + return redirect('/book/') @login_required def view_workshoptype_list(request): - '''Gives the types of workshop details ''' - user = request.user - if is_email_checked(user): - workshoptype_list = WorkshopType.objects.all() - - paginator = Paginator(workshoptype_list, 12) #Show upto 12 workshops per page - - page = request.GET.get('page') - try: - workshoptype = paginator.page(page) - except PageNotAnInteger: - #If page is not an integer, deliver first page. - workshoptype = paginator.page(1) - except EmptyPage: - #If page is out of range(e.g 999999), deliver last page. - workshoptype = paginator.page(paginator.num_pages) - - return render( - request, 'workshop_app/view_workshoptype_list.html', \ - {'workshoptype': workshoptype} - ) - else: - return redirect('/activate_user/') + '''Gives the types of workshop details ''' + user = request.user + if is_email_checked(user): + workshoptype_list = WorkshopType.objects.all() + + paginator = Paginator(workshoptype_list, 12) #Show upto 12 workshops per page + + page = request.GET.get('page') + try: + workshoptype = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + workshoptype = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + workshoptype = paginator.page(paginator.num_pages) + + return render( + request, 'workshop_app/view_workshoptype_list.html', \ + {'workshoptype': workshoptype} + ) + else: + return redirect('/activate_user/') def view_workshoptype_details(request): - '''Gives the details for types of workshops.''' - workshoptype_list = WorkshopType.objects.all() - - paginator = Paginator(workshoptype_list, 12) #Show upto 12 workshops per page - - page = request.GET.get('page') - try: - workshoptype = paginator.page(page) - except PageNotAnInteger: - #If page is not an integer, deliver first page. - workshoptype = paginator.page(1) - except EmptyPage: - #If page is out of range(e.g 999999), deliver last page. - workshoptype = paginator.page(paginator.num_pages) - - return render( - request, 'workshop_app/view_workshoptype_details.html', \ - {'workshoptype': workshoptype} - ) - + '''Gives the details for types of workshops.''' + workshoptype_list = WorkshopType.objects.all() + + paginator = Paginator(workshoptype_list, 12) #Show upto 12 workshops per page + + page = request.GET.get('page') + try: + workshoptype = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + workshoptype = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + workshoptype = paginator.page(paginator.num_pages) + + return render( + request, 'workshop_app/view_workshoptype_details.html', \ + {'workshoptype': workshoptype} + ) + def benefits(request): - return render(request, 'workshop_app/view_benefits.html') + return render(request, 'workshop_app/view_benefits.html') def faq(request): - return render(request, 'workshop_app/view_faq.html') + return render(request, 'workshop_app/view_faq.html') def how_to_participate(request): - return render(request, 'workshop_app/how_to_participate.html') + return render(request, 'workshop_app/how_to_participate.html') def file_view(request, workshop_title): - if workshop_title =='flowchart': - pdf_file = open(path.join(settings.MEDIA_ROOT,'flowchart.pdf'), 'rb') - return HttpResponse(pdf_file, content_type="application/pdf") - else: - filename = WorkshopType.objects.get(id=workshop_title) - attachment_path = path.dirname(filename.workshoptype_attachments.path) - zipfile_name = string_io() - zipfile = ZipFile(zipfile_name, "w") - attachments = listdir(attachment_path) - for file in attachments: - file_path = sep.join((attachment_path, file)) - zipfile.write(file_path, path.basename(file_path)) - zipfile.close() - zipfile_name.seek(0) - response = HttpResponse(content_type='application/zip') - response['Content-Disposition'] = 'attachment; filename={0}.zip'.format( - filename.workshoptype_name.replace(" ", "_") - ) - response.write(zipfile_name.read()) - return response + if workshop_title =='flowchart': + pdf_file = open(path.join(settings.MEDIA_ROOT,'flowchart.pdf'), 'rb') + return HttpResponse(pdf_file, content_type="application/pdf") + else: + filename = WorkshopType.objects.get(id=workshop_title) + attachment_path = path.dirname(filename.workshoptype_attachments.path) + zipfile_name = string_io() + zipfile = ZipFile(zipfile_name, "w") + attachments = listdir(attachment_path) + for file in attachments: + file_path = sep.join((attachment_path, file)) + zipfile.write(file_path, path.basename(file_path)) + zipfile.close() + zipfile_name.seek(0) + response = HttpResponse(content_type='application/zip') + response['Content-Disposition'] = 'attachment; filename={0}.zip'.format( + filename.workshoptype_name.replace(" ", "_") + ) + response.write(zipfile_name.read()) + return response def testimonials(request): - testimonials = Testimonial.objects.all().order_by('-id') - paginator = Paginator(testimonials, 3) #Show upto 12 workshops per page - - page = request.GET.get('page') - try: - messages = paginator.page(page) - except PageNotAnInteger: - #If page is not an integer, deliver first page. - messages = paginator.page(1) - except EmptyPage: - #If page is out of range(e.g 999999), deliver last page. - messages = paginator.page(paginator.num_pages) - return render(request, 'workshop_app/testimonals.html', - {"messages":messages}) + testimonials = Testimonial.objects.all().order_by('-id') + paginator = Paginator(testimonials, 3) #Show upto 12 workshops per page + + page = request.GET.get('page') + try: + messages = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + messages = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + messages = paginator.page(paginator.num_pages) + return render(request, 'workshop_app/testimonals.html', + {"messages":messages}) def check_workshop_type(x): - try: - y = datetime.strftime(x.proposed_workshop_date, '%d-%m-%Y') - except: - y = datetime.strftime(x.requested_workshop_date, '%d-%m-%Y') - return y + try: + y = datetime.strftime(x.proposed_workshop_date, '%d-%m-%Y') + except: + y = datetime.strftime(x.requested_workshop_date, '%d-%m-%Y') + return y @login_required def workshop_stats(request): - user = request.user - today = datetime.now() - upto = today + dt.timedelta(days=15) - - #For Monthly Chart - workshop_count = [0] * 12 - for x in range(12): - workshop_count[x] +=RequestedWorkshop.objects.filter( - requested_workshop_date__year=str(today.year), - requested_workshop_date__month=str(x+1), - status='ACCEPTED').count() - workshop_count[x] +=ProposeWorkshopDate.objects.filter( - proposed_workshop_date__year=str(today.year), - proposed_workshop_date__month=str(x+1), - status='ACCEPTED').count() - - #Count Total Number of workshops for each type - workshop_titles = WorkshopType.objects.all() - workshoptype_dict = {} - for title in workshop_titles: - workshoptype_dict[title]=0 - - for title in workshoptype_dict.keys(): - workshoptype_dict[title] += RequestedWorkshop.objects.filter( - requested_workshop_title=title, - status='ACCEPTED').count() - workshoptype_dict[title] += ProposeWorkshopDate.objects.filter( - proposed_workshop_title=title, - status='ACCEPTED').count() - #For Pie Chart - workshoptype_num = [] - workshoptype_title = [] - for title in workshoptype_dict.keys(): - workshoptype_title.append(str(title)) - - for count in workshoptype_dict.values(): - workshoptype_num.append(count) - - workshoptype_count = [workshoptype_title, workshoptype_num] - del workshoptype_title, workshoptype_num - - if request.method == 'POST': - try: - from_dates = request.POST.get('from') - to_dates = request.POST.get('to') - - #Fetches Accepted workshops which were proposed by Coordinators - proposed_workshops = ProposeWorkshopDate.objects.filter( - proposed_workshop_date__range=(from_dates, to_dates), - status='ACCEPTED' - ) - - # Fetches Accepted workshops which were Accepted by - # Instructors based on their Availability - requested_workshops = RequestedWorkshop.objects.filter( - requested_workshop_date__range=(from_dates, to_dates), - status='ACCEPTED' - ) - - upcoming_workshops = [] - - for workshop in proposed_workshops: - upcoming_workshops.append(workshop) - - for workshop in requested_workshops: - upcoming_workshops.append(workshop) - - upcoming_workshops = sorted(upcoming_workshops, - key=lambda x: check_workshop_type(x)) - - download = request.POST.get('Download') - if download: - response = HttpResponse(content_type='text/csv') - - response['Content-Disposition'] = 'attachment;\ - filename="records_from_{0}_to_{1}.csv"'.format( - from_dates,to_dates - ) - - writer = csv.writer(response) - header = [ - 'coordinator name', - 'instructor name', - 'workshop', - 'date', - 'status', - 'institute name' - ] - - writer.writerow(header) - - for workshop in upcoming_workshops: - try: - row = [ - workshop.proposed_workshop_coordinator, - workshop.proposed_workshop_instructor, - workshop.proposed_workshop_title, - workshop.proposed_workshop_date, - workshop.status, - workshop.proposed_workshop_coordinator.profile.institute - ] - - except: - row = [ - workshop.requested_workshop_coordinator, - workshop.requested_workshop_instructor, - workshop.requested_workshop_title, - workshop.requested_workshop_date, - workshop.status, - workshop.requested_workshop_coordinator.profile.institute - ] - - writer.writerow(row) - return response - else: - return render(request, 'workshop_app/workshop_stats.html', - { - "upcoming_workshops": upcoming_workshops, - "show_workshop_stats": settings.SHOW_WORKSHOP_STATS, - "workshop_count": workshop_count, - "workshoptype_count": workshoptype_count, - - }) - except: - messages.info(request, 'Please enter Valid Dates') - - if is_instructor(user) and is_email_checked(user): - try: - #Fetches Accepted workshops which were proposed by Coordinators - proposed_workshops = ProposeWorkshopDate.objects.filter( - proposed_workshop_date__range=(today, upto), - status='ACCEPTED' - ) - - #Fetches Accepted workshops which were Accepted by - # Instructors based on their Availability - requested_workshops = RequestedWorkshop.objects.filter( - requested_workshop_date__range=(today, upto), - status='ACCEPTED' - ) - - upcoming_workshops = [] - for workshop in proposed_workshops: - upcoming_workshops.append(workshop) - - for workshop in requested_workshops: - upcoming_workshops.append(workshop) - - upcoming_workshops = sorted(upcoming_workshops, - key=lambda x: check_workshop_type(x)) - - except: - upcoming_workshops = None - - paginator = Paginator(upcoming_workshops, 12) - - page = request.GET.get('page') - try: - upcoming_workshops = paginator.page(page) - except PageNotAnInteger: - #If page is not an integer, deliver first page. - upcoming_workshops = paginator.page(1) - except EmptyPage: - #If page is out of range(e.g 999999), deliver last page. - upcoming_workshops = paginator.page(paginator.num_pages) - - - return render(request, 'workshop_app/workshop_stats.html', - { - "upcoming_workshops": upcoming_workshops, - "show_workshop_stats": settings.SHOW_WORKSHOP_STATS, - "workshop_count": workshop_count, - "workshoptype_count": workshoptype_count, - }) - else: - redirect('/manage/') + user = request.user + today = datetime.now() + upto = today + dt.timedelta(days=15) + + #For Monthly Chart + workshop_count = [0] * 12 + for x in range(12): + workshop_count[x] +=RequestedWorkshop.objects.filter( + requested_workshop_date__year=str(today.year), + requested_workshop_date__month=str(x+1), + status='ACCEPTED').count() + workshop_count[x] +=ProposeWorkshopDate.objects.filter( + proposed_workshop_date__year=str(today.year), + proposed_workshop_date__month=str(x+1), + status='ACCEPTED').count() + + #Count Total Number of workshops for each type + workshop_titles = WorkshopType.objects.all() + workshoptype_dict = {} + for title in workshop_titles: + workshoptype_dict[title]=0 + + for title in workshoptype_dict.keys(): + workshoptype_dict[title] += RequestedWorkshop.objects.filter( + requested_workshop_title=title, + status='ACCEPTED').count() + workshoptype_dict[title] += ProposeWorkshopDate.objects.filter( + proposed_workshop_title=title, + status='ACCEPTED').count() + #For Pie Chart + workshoptype_num = [] + workshoptype_title = [] + for title in workshoptype_dict.keys(): + workshoptype_title.append(str(title)) + + for count in workshoptype_dict.values(): + workshoptype_num.append(count) + + workshoptype_count = [workshoptype_title, workshoptype_num] + del workshoptype_title, workshoptype_num + + #For India Map + states = [ + ['Code', 'State', 'Number'], + ["IN-AP", "Andhra Pradesh", 0], + ["IN-AR", "Arunachal Pradesh", 0], + ["IN-AS", "Assam", 0], + ["IN-BR", "Bihar", 0], + ["IN-CT", "Chhattisgarh", 0], + ["IN-GA", "Goa", 0], + ["IN-GJ", "Gujarat", 0], + ["IN-HR", "Haryana", 0], + ["IN-HP", "Himachal Pradesh", 0], + ["IN-JK", "Jammu and Kashmir", 0], + ["IN-JH", "Jharkhand", 0], + ["IN-KA", "Karnataka", 0], + ["IN-KL", "Kerala", 0], + ["IN-MP", "Madhya Pradesh", 0], + ["IN-MH", "Maharashtra", 0], + ["IN-MN", "Manipur", 0], + ["IN-ML", "Meghalaya", 0], + ["IN-MZ", "Mizoram", 0], + ["IN-NL", "Nagaland", 0], + ["IN-OR", "Odisha", 0], + ["IN-PB", "Punjab", 0], + ["IN-RJ", "Rajasthan", 0], + ["IN-SK", "Sikkim", 0], + ["IN-TN", "Tamil Nadu", 0], + ["IN-TG", "Telangana", 0], + ["IN-TR", "Tripura", 0], + ["IN-UT", "Uttarakhand", 0], + ["IN-UP", "Uttar Pradesh", 0], + ["IN-WB", "West Bengal", 0], + ["IN-AN", "Andaman and Nicobar Islands", 0], + ["IN-CH", "Chandigarh", 0], + ["IN-DN", "Dadra and Nagar Haveli", 0], + ["IN-DD", "Daman and Diu", 0], + ["IN-DL", "Delhi", 0], + ["IN-LD", "Lakshadweep", 0], + ["IN-PY", "Puducherry", 0] + ] + + workshop_state = [] + requestedWorkshops = RequestedWorkshop.objects.filter(status='ACCEPTED') + proposedWorkshops = ProposeWorkshopDate.objects.filter(status='ACCEPTED') + for workshop in requestedWorkshops: + for s in states: + if s[0] == workshop.requested_workshop_coordinator.profile.state: + s[2] +=1 + + for workshop in proposedWorkshops: + for s in states: + if s[0] == workshop.proposed_workshop_coordinator.profile.state: + s[2] +=1 + + #For Data Downloading and Viewing + if request.method == 'POST': + try: + from_dates = request.POST.get('from') + to_dates = request.POST.get('to') + + #Fetches Accepted workshops which were proposed by Coordinators + proposed_workshops = ProposeWorkshopDate.objects.filter( + proposed_workshop_date__range=(from_dates, to_dates), + status='ACCEPTED' + ) + + # Fetches Accepted workshops which were Accepted by + # Instructors based on their Availability + requested_workshops = RequestedWorkshop.objects.filter( + requested_workshop_date__range=(from_dates, to_dates), + status='ACCEPTED' + ) + + upcoming_workshops = [] + + for workshop in proposed_workshops: + upcoming_workshops.append(workshop) + + for workshop in requested_workshops: + upcoming_workshops.append(workshop) + + upcoming_workshops = sorted(upcoming_workshops, + key=lambda x: check_workshop_type(x)) + + download = request.POST.get('Download') + if download: + response = HttpResponse(content_type='text/csv') + + response['Content-Disposition'] = 'attachment;\ + filename="records_from_{0}_to_{1}.csv"'.format( + from_dates,to_dates + ) + + writer = csv.writer(response) + header = [ + 'coordinator name', + 'instructor name', + 'workshop', + 'date', + 'status', + 'institute name' + ] + + writer.writerow(header) + + for workshop in upcoming_workshops: + try: + row = [ + workshop.proposed_workshop_coordinator, + workshop.proposed_workshop_instructor, + workshop.proposed_workshop_title, + workshop.proposed_workshop_date, + workshop.status, + workshop.proposed_workshop_coordinator.profile.institute + ] + + except: + row = [ + workshop.requested_workshop_coordinator, + workshop.requested_workshop_instructor, + workshop.requested_workshop_title, + workshop.requested_workshop_date, + workshop.status, + workshop.requested_workshop_coordinator.profile.institute + ] + + writer.writerow(row) + return response + else: + return render(request, 'workshop_app/workshop_stats.html', + { + "upcoming_workshops": upcoming_workshops, + "show_workshop_stats": settings.SHOW_WORKSHOP_STATS, + "workshop_count": workshop_count, + "workshoptype_count": workshoptype_count, + "india_map": states + }) + except: + messages.info(request, 'Please enter Valid Dates') + + if is_instructor(user) and is_email_checked(user): + try: + #Fetches Accepted workshops which were proposed by Coordinators + proposed_workshops = ProposeWorkshopDate.objects.filter( + proposed_workshop_date__range=(today, upto), + status='ACCEPTED' + ) + + #Fetches Accepted workshops which were Accepted by + # Instructors based on their Availability + requested_workshops = RequestedWorkshop.objects.filter( + requested_workshop_date__range=(today, upto), + status='ACCEPTED' + ) + + upcoming_workshops = [] + for workshop in proposed_workshops: + upcoming_workshops.append(workshop) + + for workshop in requested_workshops: + upcoming_workshops.append(workshop) + + upcoming_workshops = sorted(upcoming_workshops, + key=lambda x: check_workshop_type(x)) + + except: + upcoming_workshops = None + + paginator = Paginator(upcoming_workshops, 12) + + page = request.GET.get('page') + try: + upcoming_workshops = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + upcoming_workshops = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + upcoming_workshops = paginator.page(paginator.num_pages) + + + return render(request, 'workshop_app/workshop_stats.html', + { + "upcoming_workshops": upcoming_workshops, + "show_workshop_stats": settings.SHOW_WORKSHOP_STATS, + "workshop_count": workshop_count, + "workshoptype_count": workshoptype_count, + "india_map": states + }) + else: + redirect('/manage/') |