summaryrefslogtreecommitdiff
path: root/workshop_app
diff options
context:
space:
mode:
authorpnshiralkar2020-04-26 03:32:09 +0530
committerpnshiralkar2020-04-26 03:32:09 +0530
commitce04a86556bbbf95851de528d7a74acbc30fc1fb (patch)
tree13fb30b7033ca2e9f9bc16b88fb8019142c6d153 /workshop_app
parent37f0afbf21fc6d4e9eb92433d666fccfd6654d53 (diff)
downloadworkshop_booking-ce04a86556bbbf95851de528d7a74acbc30fc1fb.tar.gz
workshop_booking-ce04a86556bbbf95851de528d7a74acbc30fc1fb.tar.bz2
workshop_booking-ce04a86556bbbf95851de528d7a74acbc30fc1fb.zip
Propose workshop by coordinator and accept workshop by instructor done
Diffstat (limited to 'workshop_app')
-rw-r--r--workshop_app/admin.py265
-rw-r--r--workshop_app/forms.py178
-rw-r--r--workshop_app/models.py11
-rw-r--r--workshop_app/templates/workshop_app/my_workshops.html97
-rw-r--r--workshop_app/urls.py28
-rw-r--r--workshop_app/views.py1723
6 files changed, 1001 insertions, 1301 deletions
diff --git a/workshop_app/admin.py b/workshop_app/admin.py
index 3eec8af..e713589 100644
--- a/workshop_app/admin.py
+++ b/workshop_app/admin.py
@@ -1,208 +1,125 @@
import csv
-from django.http import HttpResponse
+
from django.contrib import admin
+from django.http import HttpResponse
+
from .models import (
- Profile, WorkshopType,
- Workshop, ProposeWorkshopDate,
- RequestedWorkshop, BookedWorkshop,
- Testimonial, ProfileComments, Banner
- )
+ Profile, WorkshopType,
+ Workshop,
+ Testimonial, ProfileComments, Banner
+)
+
try:
from StringIO import StringIO as string_io
except ImportError:
from io import BytesIO as string_io
-#Custom Classes
+
+# Custom Classes
class ProfileAdmin(admin.ModelAdmin):
- list_display = ['title','user', 'institute','location','department',
- 'phone_number','position']
- list_filter = ['position', 'department']
- actions = ['download_csv']
-
- def download_csv(self, request, queryset):
- openfile = string_io()
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename=profile_data.csv'
-
- writer = csv.writer(response)
- writer.writerow(['email_id', 'title','username', 'first_name', 'last_name',
- 'institute', 'location', 'department',
- 'phone_number', 'position'])
-
- for q in queryset:
- writer.writerow([q.user.email, q.title, q.user, q.user.first_name,
- q.user.last_name, q.institute,
- q.location, q.department, q.phone_number,
- q.position])
-
- openfile.seek(0)
- response.write(openfile.read())
- return response
-
- download_csv.short_description = "Download CSV file for selected stats."
-
-
-class ProposeWorkshopDateAdmin(admin.ModelAdmin):
- list_display = ['proposed_workshop_title', 'proposed_workshop_date',
- 'proposed_workshop_coordinator', 'status',
- 'proposed_workshop_instructor']
- list_filter = ['status']
- actions = ['download_csv']
-
- def download_csv(self, request, queryset):
- openfile = string_io()
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename=proposedworkshop_data.csv'
-
- writer = csv.writer(response)
- writer.writerow(['proposed_workshop_title', 'proposed_workshop_date',
- 'proposed_workshop_coordinator', 'status','proposed_workshop_instructor'])
-
- for q in queryset:
- writer.writerow([q.proposed_workshop_title, q.proposed_workshop_date,
- q.proposed_workshop_coordinator, q.status,
- q.proposed_workshop_instructor])
-
- openfile.seek(0)
- response.write(openfile.read())
- return response
-
- download_csv.short_description = "Download CSV file for selected stats."
-
-
-class RequestedWorkshopAdmin(admin.ModelAdmin):
- list_display = ['requested_workshop_title',
- 'requested_workshop_date',
- 'requested_workshop_coordinator',
- 'requested_workshop_instructor',
- 'status']
-
- list_filter = ['status']
- actions = ['download_csv']
-
- def download_csv(self, request, queryset):
- openfile = string_io()
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename=requestedworkshop_data.csv'
-
- writer = csv.writer(response)
- writer.writerow(['requested_workshop_title',
- 'requested_workshop_date',
- 'requested_workshop_coordinator',
- 'requested_workshop_instructor',
- 'status'])
-
- for q in queryset:
- writer.writerow([q.requested_workshop_title,
- q.requested_workshop_date,
- q.requested_workshop_coordinator,
- q.requested_workshop_instructor,
- q.status])
-
- openfile.seek(0)
- response.write(openfile.read())
- return response
-
- download_csv.short_description = "Download CSV file for selected stats."
+ list_display = ['title', 'user', 'institute', 'location', 'department',
+ 'phone_number', 'position']
+ list_filter = ['position', 'department']
+ actions = ['download_csv']
+
+ def download_csv(self, request, queryset):
+ openfile = string_io()
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment;filename=profile_data.csv'
+ writer = csv.writer(response)
+ writer.writerow(['email_id', 'title', 'username', 'first_name', 'last_name',
+ 'institute', 'location', 'department',
+ 'phone_number', 'position'])
+ for q in queryset:
+ writer.writerow([q.user.email, q.title, q.user, q.user.first_name,
+ q.user.last_name, q.institute,
+ q.location, q.department, q.phone_number,
+ q.position])
+
+ openfile.seek(0)
+ response.write(openfile.read())
+ return response
+
+ download_csv.short_description = "Download CSV file for selected stats."
class WorkshopAdmin(admin.ModelAdmin):
- list_display = ['workshop_title','workshop_instructor']
- list_filter = ['workshop_title']
+ list_display = ['title', 'instructor', 'date', 'status', 'coordinator']
+ list_filter = ['title', 'date']
+ actions = ['download_csv']
+
+ def download_csv(self, request, queryset):
+ openfile = string_io()
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment;filename=workshop_data.csv'
+ writer = csv.writer(response)
+ writer.writerow(['title', 'date', 'instructor', 'coordinator', 'status'])
+
+ for q in queryset:
+ writer.writerow([q.title, q.date, q.instructor, q.coordinator, q.status])
+
+ openfile.seek(0)
+ response.write(openfile.read())
+ return response
+
+ download_csv.short_description = "Download CSV file for selected stats."
class WorkshopTypeAdmin(admin.ModelAdmin):
- list_display = ['workshoptype_name', 'workshoptype_duration']
- list_filter = ['workshoptype_name']
- actions = ['download_csv']
+ list_display = ['name', 'duration']
+ list_filter = ['name']
+ actions = ['download_csv']
+
+ def download_csv(self, request, queryset):
+ openfile = string_io()
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment;filename=workshoptype_data.csv'
+ writer = csv.writer(response)
+ writer.writerow(['name', 'duration'])
- def download_csv(self, request, queryset):
- openfile = string_io()
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename=workshoptype_data.csv'
+ for q in queryset:
+ writer.writerow([q.name, q.workshoptype_duration])
- writer = csv.writer(response)
- writer.writerow(['workshoptype_name', 'workshoptype_duration'])
-
- for q in queryset:
- writer.writerow([q.workshoptype_name, q.workshoptype_duration])
+ openfile.seek(0)
+ response.write(openfile.read())
+ return response
- openfile.seek(0)
- response.write(openfile.read())
- return response
-
- download_csv.short_description = "Download CSV file for selected stats."
+ download_csv.short_description = "Download CSV file for selected stats."
class TestimonialAdmin(admin.ModelAdmin):
- list_display = ['name', 'department', 'institute']
- list_filter = ['department']
- actions = ['download_csv']
-
- def download_csv(self, request, queryset):
- openfile = string_io()
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename=testimonials_data.csv'
-
- writer = csv.writer(response)
- writer.writerow(['name', 'department', 'institute'])
-
- for q in queryset:
- writer.writerow([q.name,
- q.department,
- q.institute
- ])
-
- openfile.seek(0)
- response.write(openfile.read())
- return response
-
- download_csv.short_description = "Download CSV file for selected stats."
-
-class BookedWorkshopAdmin(admin.ModelAdmin):
- list_display = ['booked_workshop_requested',
- 'booked_workshop_proposed']
- actions = ['download_csv']
-
- def download_csv(self, request, queryset):
- openfile = string_io()
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename=bookedworkshops_data.csv'
-
- writer = csv.writer(response)
- writer.writerow(['booked_workshop_requested',
- 'booked_workshop_proposed'])
-
- for q in queryset:
- writer.writerow([q.booked_workshop_requested,
- q.booked_workshop_proposed
- ])
-
- openfile.seek(0)
- response.write(openfile.read())
- return response
-
- download_csv.short_description = "Download CSV file for selected stats."
+ list_display = ['name', 'department', 'institute']
+ list_filter = ['department']
+ actions = ['download_csv']
+
+ def download_csv(self, request, queryset):
+ openfile = string_io()
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment;filename=testimonials_data.csv'
+ writer = csv.writer(response)
+ writer.writerow(['name', 'department', 'institute'])
+
+ for q in queryset:
+ writer.writerow([q.name,
+ q.department,
+ q.institute
+ ])
+
+ openfile.seek(0)
+ response.write(openfile.read())
+ return response
+ download_csv.short_description = "Download CSV file for selected stats."
class ProfileCommentAdmin(admin.ModelAdmin):
- list_display = ['comment', 'created_date', 'coordinator_profile', 'instructor_profile']
+ list_display = ['comment', 'created_date', 'coordinator', 'instructor']
# Register your models here.
admin.site.register(Profile, ProfileAdmin)
admin.site.register(WorkshopType, WorkshopTypeAdmin)
admin.site.register(Workshop, WorkshopAdmin)
-admin.site.register(ProposeWorkshopDate, ProposeWorkshopDateAdmin)
-admin.site.register(RequestedWorkshop, RequestedWorkshopAdmin)
-admin.site.register(BookedWorkshop, BookedWorkshopAdmin)
admin.site.register(Testimonial, TestimonialAdmin)
admin.site.register(ProfileComments, ProfileCommentAdmin)
admin.site.register(Banner)
diff --git a/workshop_app/forms.py b/workshop_app/forms.py
index 68ada33..1bddada 100644
--- a/workshop_app/forms.py
+++ b/workshop_app/forms.py
@@ -1,11 +1,10 @@
+from string import punctuation, digits
+
from django import forms
from django.utils import timezone
-from .models import (
- Profile, User, Workshop, WorkshopType,
- RequestedWorkshop, BookedWorkshop, ProposeWorkshopDate,
- ProfileComments
- )
-from string import punctuation, digits
+
+from .models import (Profile, Workshop, ProfileComments, department_choices, title, source, states)
+
try:
from string import letters
except ImportError:
@@ -15,86 +14,9 @@ from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from .send_mails import generate_activation_key
-
UNAME_CHARS = letters + "._" + digits
PWD_CHARS = letters + punctuation + digits
-position_choices = (
- ("coordinator", "Coordinator"),
- ("instructor", "Instructor")
- )
-
-department_choices = (
- ("computer engineering", "Computer Science"),
- ("information technology", "Information Technology"),
- ("civil engineering", "Civil Engineering"),
- ("electrical engineering", "Electrical Engineering"),
- ("mechanical engineering", "Mechanical Engineering"),
- ("chemical engineering", "Chemical Engineering"),
- ("aerospace engineering", "Aerospace Engineering"),
- ("biosciences and bioengineering", "Biosciences and BioEngineering"),
- ("electronics", "Electronics"),
- ("energy science and engineering", "Energy Science and Engineering"),
- )
-
-title = (
- ("Professor", "Prof."),
- ("Doctor", "Dr."),
- ("Shriman", "Shri"),
- ("Shrimati", "Smt"),
- ("Kumari", "Ku"),
- ("Mr", "Mr."),
- ("Mrs", "Mrs."),
- ("Miss", "Ms."),
- )
-
-source = (
- ("FOSSEE Email", "FOSSEE Email"),
- ("FOSSEE website", "FOSSEE website"),
- ("Google", "Google"),
- ("Social Media", "Social Media"),
- ("From other College", "From other College"),
- )
-
-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.
@@ -106,19 +28,18 @@ class UserRegistrationForm(forms.Form):
period and underscore only.''')
email = forms.EmailField()
password = forms.CharField(max_length=32, widget=forms.PasswordInput())
- confirm_password = forms.CharField\
- (max_length=32, widget=forms.PasswordInput())
+ confirm_password = forms.CharField(max_length=32, widget=forms.PasswordInput())
title = forms.ChoiceField(choices=title)
first_name = forms.CharField(max_length=32)
last_name = forms.CharField(max_length=32)
- phone_number = forms.RegexField(regex=r'^.{10}$',
- error_messages={'invalid':"Phone number must be entered \
+ phone_number = forms.RegexField(regex=r'^.{10}$',
+ error_messages={'invalid': "Phone number must be entered \
in the format: '9999999999'.\
Up to 10 digits allowed."})
- institute = forms.CharField(max_length=128,
- help_text='Please write full name of your Institute/Organization')
+ institute = forms.CharField(max_length=128,
+ help_text='Please write full name of your Institute/Organization')
department = forms.ChoiceField(help_text='Department you work/study',
- choices=department_choices)
+ choices=department_choices)
location = forms.CharField(max_length=255, help_text="Place/City")
state = forms.ChoiceField(choices=states)
how_did_you_hear_about_us = forms.ChoiceField(choices=source)
@@ -126,7 +47,7 @@ class UserRegistrationForm(forms.Form):
def clean_username(self):
u_name = self.cleaned_data["username"]
if u_name.strip(UNAME_CHARS):
- msg = "Only letters, digits, period are"\
+ msg = "Only letters, digits, period are" \
" allowed in username"
raise forms.ValidationError(msg)
try:
@@ -170,48 +91,47 @@ class UserRegistrationForm(forms.Form):
new_profile = Profile(user=new_user)
new_profile.institute = cleaned_data["institute"]
new_profile.department = cleaned_data["department"]
- #new_profile.position = cleaned_data["position"]
+ # new_profile.position = cleaned_data["position"]
new_profile.phone_number = cleaned_data["phone_number"]
new_profile.location = cleaned_data["location"]
new_profile.title = cleaned_data["title"]
new_profile.state = cleaned_data["state"]
- new_profile.how_did_you_hear_about_us = cleaned_data["how_did_you_hear_about_us" ]
+ new_profile.how_did_you_hear_about_us = cleaned_data["how_did_you_hear_about_us"]
new_profile.activation_key = generate_activation_key(new_user.username)
- new_profile.key_expiry_time = timezone.now() + \
- timezone.timedelta(days=1)
+ new_profile.key_expiry_time = timezone.now() + timezone.timedelta(days=1)
new_profile.save()
key = Profile.objects.get(user=new_user).activation_key
return u_name, pwd, key
+
class UserLoginForm(forms.Form):
"""Creates a form which will allow the user to log into the system."""
username = forms.CharField(max_length=32,
- widget=forms.TextInput())
+ widget=forms.TextInput())
password = forms.CharField(max_length=32,
- widget=forms.PasswordInput())
+ widget=forms.PasswordInput())
def clean(self):
super(UserLoginForm, self).clean()
try:
- u_name, pwd = self.cleaned_data["username"],\
+ u_name, pwd = self.cleaned_data["username"], \
self.cleaned_data["password"]
user = authenticate(username=u_name, password=pwd)
except Exception:
- raise forms.ValidationError\
- ("Username and/or Password is not entered")
+ raise forms.ValidationError("Username and/or Password is not entered")
if not user:
raise forms.ValidationError("Invalid username/password")
return user
+
class ProfileForm(forms.ModelForm):
""" profile form for coordinator and instructor """
class Meta:
model = Profile
- fields = ['first_name', 'last_name', 'institute', 'department',
- ]
+ fields = ['first_name', 'last_name', 'institute', 'department']
first_name = forms.CharField(max_length=32)
last_name = forms.CharField(max_length=32)
@@ -223,48 +143,44 @@ class ProfileForm(forms.ModelForm):
self.fields['first_name'].initial = user.first_name
self.fields['last_name'].initial = user.last_name
+
class CreateWorkshop(forms.ModelForm):
"""
Instructors can create Workshops based on the Types
of available workshops.
"""
- def __init__( self, *args, **kwargs ):
+ def __init__(self, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
- super(CreateWorkshop, self).__init__( *args, **kwargs )
- self.fields['recurrences'].label = " " #the trick to hide field :)
+ super(CreateWorkshop, self).__init__(*args, **kwargs)
class Meta:
model = Workshop
- fields = ['workshop_title', 'recurrences']
+ fields = ['title']
+
-
-class ProposeWorkshopDateForm(forms.ModelForm):
+# debug : Changed this
+class WorkshopForm(forms.ModelForm):
"""
Coordinators will propose a workshop and date
- """
+ """
errorlist_css_class = 'errorlist'
- def __init__( self, *args, **kwargs ):
+
+ def __init__(self, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
- super(ProposeWorkshopDateForm, self).__init__(*args, **kwargs)
- self.fields['condition_one'].label = ""
- self.fields['condition_one'].required = True
- self.fields['condition_two'].label = ""
- self.fields['condition_two'].required = True
- self.fields['condition_three'].label = ""
- self.fields['condition_three'].required = True
- self.fields['proposed_workshop_title'].label = "Workshop :"
- self.fields['proposed_workshop_date'].label = "Workshop Date :"
-
+ super(WorkshopForm, self).__init__(*args, **kwargs)
+ self.fields['tnc_accepted'].label = ""
+ self.fields['tnc_accepted'].required = True
+ self.fields['title'].label = "Workshop :"
+ self.fields['date'].label = "Workshop Date :"
+
class Meta:
- model = ProposeWorkshopDate
- exclude = ['status', 'proposed_workshop_instructor',
- 'proposed_workshop_coordinator']
+ model = Workshop
+ exclude = ['status', 'instructor', 'coordinator']
widgets = {
- 'proposed_workshop_date': forms.DateInput(attrs={
- 'class':'datepicker'})
- }
-
+ 'date': forms.DateInput(attrs={
+ 'class': 'datepicker'})
+ }
class ProfileCommentsForm(forms.ModelForm):
@@ -281,8 +197,8 @@ class ProfileCommentsForm(forms.ModelForm):
class Meta:
model = ProfileComments
exclude = ['coordinator_profile', 'instructor_profile',
- 'created_date'
- ]
+ 'created_date'
+ ]
widgets = {
- 'comments' : forms.CharField(),
- } \ No newline at end of file
+ 'comments': forms.CharField(),
+ }
diff --git a/workshop_app/models.py b/workshop_app/models.py
index 46433b3..c526999 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -41,8 +41,6 @@ source = (
("From other College", "From other College"),
)
-# TODO: states and dept_chocies var also exists in forms.py. Use only one.
-
states = (
("IN-AP", "Andhra Pradesh"),
("IN-AR", "Arunachal Pradesh"),
@@ -89,13 +87,13 @@ def has_profile(user):
def attachments(instance, filename):
- return os.sep.join((instance.workshoptype_name.replace(" ", '_'), filename))
+ return os.sep.join((instance.name.replace(" ", '_'), filename))
class Profile(models.Model):
"""Profile for users(instructors and coordinators)"""
- user = models.OneToOneField(User)
+ user = models.OneToOneField(User, on_delete=models.CASCADE)
title = models.CharField(max_length=32, blank=True, choices=title)
institute = models.CharField(max_length=150)
department = models.CharField(max_length=150, choices=department_choices)
@@ -156,10 +154,11 @@ class Workshop(models.Model):
Contains details of workshops
"""
coordinator = models.ForeignKey(User, on_delete=models.CASCADE)
- instructor = models.ForeignKey(User, null=True, related_name="%(app_label)s_%(class)s_related")
+ instructor = models.ForeignKey(User, null=True, related_name="%(app_label)s_%(class)s_related", on_delete=models.CASCADE)
title = models.ForeignKey(WorkshopType, on_delete=models.CASCADE, help_text='Select the type of workshop.')
date = models.DateField()
status = models.CharField(max_length=32, default="Pending")
+ tnc_accepted = models.BooleanField(help_text="I accept the terms and conditions")
def __str__(self):
return u"{0} | {1} | {2} | {3} | {4}".format(
@@ -197,7 +196,7 @@ class ProfileComments(models.Model):
coordinator = models.ForeignKey(User,
on_delete=models.CASCADE)
comment = models.TextField()
- instructor = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_related")
+ instructor = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_related", on_delete=models.CASCADE)
created_date = models.DateTimeField(default=timezone.now)
def __str__(self):
diff --git a/workshop_app/templates/workshop_app/my_workshops.html b/workshop_app/templates/workshop_app/my_workshops.html
index 417fa55..a22dced 100644
--- a/workshop_app/templates/workshop_app/my_workshops.html
+++ b/workshop_app/templates/workshop_app/my_workshops.html
@@ -140,17 +140,17 @@
<tbody>
{% for workshop in team_workshops %}
<tr>
- <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.proposed_workshop_coordinator.id }}">
- {{ workshop.proposed_workshop_coordinator.get_full_name }}</a>
+ <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.coordinator.id }}">
+ {{ workshop.coordinator.get_full_name }}</a>
</td>
<td>
- {{ workshop.proposed_workshop_instructor.get_full_name }}
+ {{ workshop.instructor.get_full_name }}
</td>
<td>
- {{ workshop.proposed_workshop_title }}
+ {{ workshop.title }}
</td>
<td>
- {{ workshop.proposed_workshop_date | date }}
+ {{ workshop.date | date }}
</td>
</tr>
{% endfor %}
@@ -179,20 +179,20 @@
{% for workshop in workshops %}
<tbody>
<tr>
- {% if workshop.status == 'Pending' and workshop.requested_workshop_instructor %}
+ {% if workshop.status == 'Pending' and workshop.instructor %}
{% if request.user.profile.position == 'instructor' %}
- <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.requested_workshop_coordinator.profile.user.id }}">
- {{ workshop.requested_workshop_coordinator.get_full_name }}</a></td>
+ <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.coordinator.profile.user.id }}">
+ {{ workshop.coordinator.get_full_name }}</a></td>
{% else %}
- <td>{{ workshop.requested_workshop_instructor.get_full_name }}</td>
+ <td>{{ workshop.instructor.get_full_name }}</td>
{% endif %}
- <td>{{ workshop.requested_workshop_title }}</td>
- <td>{{ workshop.requested_workshop_date | date }}</td>
+ <td>{{ workshop.title }}</td>
+ <td>{{ workshop.date | date }}</td>
<td><span class = "label label-warning">{{ workshop.status }}</span></td>
{% endif %}
- {% if request.user.profile.position == 'instructor' and workshop.status == 'Pending' and workshop.requested_workshop_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_id }},ACCEPTED')" data-toggle="popover" title="Please Note" data-content="Once Accepted you can't Reject, you have to personally contact the Coordinator if the workshop is to be cancelled"> Accept</button></td>
- <td><button class="btn btn-danger btn-sm" id="book-btn" onClick="sendData('{{workshop.requested_workshop_coordinator}},{{workshop.requested_workshop_date| safe}},{{ workshop.requested_workshop_title_id }},REJECTED')" data-toggle="popover" title="Please Note" data-content="Once Rejected you cannot revoke this action."> Reject </button></td>
+ {% if request.user.profile.position == 'instructor' and workshop.status == 'Pending' and workshop.instructor %}
+ <td><button class="btn btn-primary btn-sm" id="book-btn" onClick="sendData('{{workshop.coordinator}},{{workshop.date| safe}},{{ workshop.title_id }},ACCEPTED')" data-toggle="popover" title="Please Note" data-content="Once Accepted you can't Reject, you have to personally contact the Coordinator if the workshop is to be cancelled"> Accept</button></td>
+ <td><button class="btn btn-danger btn-sm" id="book-btn" onClick="sendData('{{workshop.coordinator}},{{workshop.date| safe}},{{ workshop.title_id }},REJECTED')" data-toggle="popover" title="Please Note" data-content="Once Rejected you cannot revoke this action."> Reject </button></td>
{% endif %}
</tr>
</tbody>
@@ -221,54 +221,54 @@
{% for workshop in workshops %}
<tbody>
<tr>
- {% if workshop.status == 'ACCEPTED' and workshop.requested_workshop_title %}
+ {% if workshop.status == 'ACCEPTED' and workshop.title %}
{% if request.user.profile.position == 'instructor' %}
- <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.requested_workshop_coordinator.profile.user.id }}">
- {{ workshop.requested_workshop_coordinator.get_full_name }}</a></td>
- <td>{{ workshop.requested_workshop_coordinator.profile.institute }}</td>
+ <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.coordinator.profile.user.id }}">
+ {{ workshop.coordinator.get_full_name }}</a></td>
+ <td>{{ workshop.coordinator.profile.institute }}</td>
{% else %}
- <td>{{ workshop.requested_workshop_instructor.get_full_name }}</td>
+ <td>{{ workshop.instructor.get_full_name }}</td>
{% endif %}
- <td>{{ workshop.requested_workshop_title |capfirst }}</td>
- {% if workshop.requested_workshop_date > today %}
- <td>{{ workshop.requested_workshop_date | date }}
+ <td>{{ workshop.title |capfirst }}</td>
+ {% if workshop.date > today %}
+ <td>{{ workshop.date | date }}
<span class="glyphicon glyphicon-calendar" data-toggle="popinfo" title="Note" data-content="Click here to change date"
- class="datepicker" onclick="changeDate('R,{{ workshop.requested_workshop_date| safe}}, {{forloop.counter}}')">
+ class="datepicker" onclick="changeDate('R,{{ workshop.date| safe}}, {{forloop.counter}}')">
</span>
<div class="myDialogR{{forloop.counter}}" style="display: none;" title="Select New Date">
<input type="text" class="rDate{{forloop.counter}}" /><br>
- <button class="btn btn-primary btn-xs" type="submit" onclick="submitNewDate('{{forloop.counter}},R,{{workshop.requested_workshop_instructor_id}},{{workshop.requested_workshop_coordinator_id}},{{ workshop.requested_workshop_title_id }},{{ workshop.requested_workshop_date | safe}}')">Save</button>
+ <button class="btn btn-primary btn-xs" type="submit" onclick="submitNewDate('{{forloop.counter}},R,{{workshop.instructor_id}},{{workshop.coordinator_id}},{{ workshop.title_id }},{{ workshop.date | safe}}')">Save</button>
</div>
</td>
{% else %}
- <td>{{ workshop.requested_workshop_date | date }}</td>
+ <td>{{ workshop.date | date }}</td>
{% endif %}
<td><span class = "label label-success">{{ workshop.status }}</span></td>
{% endif %}
{% if workshop.status == 'ACCEPTED' and workshop.condition_one %}
{% if request.user.profile.position == 'instructor' %}
- <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.proposed_workshop_coordinator.profile.user.id }}">
- {{ workshop.proposed_workshop_coordinator.get_full_name }}</a></td>
- <td>{{ workshop.proposed_workshop_coordinator.profile.institute }}</td>
+ <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.coordinator.profile.user.id }}">
+ {{ workshop.coordinator.get_full_name }}</a></td>
+ <td>{{ workshop.coordinator.profile.institute }}</td>
{% else %}
- <td>{{ workshop.proposed_workshop_instructor.get_full_name }}</td>
+ <td>{{ workshop.instructor.get_full_name }}</td>
{% endif %}
- <td>{{ workshop.proposed_workshop_title }}</td>
- {% if workshop.proposed_workshop_date > today %}
- <td>{{ workshop.proposed_workshop_date | date }}
+ <td>{{ workshop.title }}</td>
+ {% if workshop.date > today %}
+ <td>{{ workshop.date | date }}
<span class="glyphicon glyphicon-calendar"
class="datepicker" data-toggle="popinfo" title="Note" data-content="Click here to change date"
- onclick="changeDate('P,{{ workshop.proposed_workshop_date | safe}}, {{forloop.counter}}')">
+ onclick="changeDate('P,{{ workshop.date | safe}}, {{forloop.counter}}')">
</span>
<div class="myDialogP{{forloop.counter}}" style="display: none;" title="Select New Date">
<input type="text" class="pDate{{forloop.counter}}" /><br>
- <button class="btn btn-primary btn-xs" type="submit" onclick="submitNewDate('{{forloop.counter}},P,{{workshop.proposed_workshop_instructor_id}},{{workshop.proposed_workshop_coordinator_id}},{{ workshop.proposed_workshop_title_id }},{{ workshop.proposed_workshop_date | safe}}')">Update</button>
+ <button class="btn btn-primary btn-xs" type="submit" onclick="submitNewDate('{{forloop.counter}},P,{{workshop.instructor_id}},{{workshop.coordinator_id}},{{ workshop.title_id }},{{ workshop.date | safe}}')">Update</button>
</div>
</td>
{% else %}
- <td>{{ workshop.proposed_workshop_date | date }}</td>
+ <td>{{ workshop.date | date }}</td>
{% endif %}
<td><span class = "label label-success">{{ workshop.status }}</span></td>
{% endif %}
@@ -306,19 +306,24 @@
{% for workshop in workshops %}
<tbody>
<tr>
- {% if workshop.status == 'Pending' and workshop.condition_one %}
+ {% if workshop.status == 'Pending' and workshop.tnc_accepted %}
{% if request.user.profile.position == 'instructor' %}
- <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.proposed_workshop_coordinator.profile.user.id }}">
- {{ workshop.proposed_workshop_coordinator.get_full_name }}</a></td>
- <td>{{ workshop.proposed_workshop_coordinator.profile.institute }}</td>
+ <td><a href="{{ URL_ROOT }}/view_comment_profile/{{ workshop.coordinator.profile.user.id }}">
+ {{ workshop.coordinator.get_full_name }}</a></td>
+ <td>{{ workshop.coordinator.profile.institute }}</td>
{% endif %}
- <td>{{ workshop.proposed_workshop_title }}</td>
- <td>{{ workshop.proposed_workshop_date | date }}</td>
+ <td>{{ workshop.title }}</td>
+ <td>{{ workshop.date | date }}</td>
<td><span class = "label label-warning">{{ workshop.status }}</span></td>
{% if request.user.profile.position == 'instructor' and workshop.status == 'Pending' %}
- <td><button class="btn btn-primary btn-sm" id="book-btn" onClick="sendData('{{workshop.proposed_workshop_coordinator}},{{workshop.proposed_workshop_date| safe}},{{ workshop.proposed_workshop_title_id }},APPROVED')" data-toggle="popover" title="Please Note" data-content="Once Accepted you can't Reject, you have to personally contact the Coordinator if the workshop is to be cancelled"> Accept</button></td>
+ <td><form method="post">
+ <input type="hidden" name="action" value="approve">
+ <input type="hidden" name="workshop_id" value="{{ workshop.id }}">
+ {% csrf_token %}
+ <button class="btn btn-primary btn-sm" id="book-btn" data-toggle="popover" title="Please Note" data-content="Once Accepted you can't Reject, you have to personally contact the Coordinator if the workshop is to be cancelled"> Accept</button>
+ </form></td>
{% endif %}
{% endif %}
</tr>
@@ -351,12 +356,12 @@
<tr>
{% if workshop.status == 'DELETED' or workshop.status == 'REJECTED' %}
{% if request.user.profile.position == 'instructor' %}
- <td>{{ workshop.requested_workshop_coordinator.get_full_name }}</td>
+ <td>{{ workshop.coordinator.get_full_name }}</td>
{% else %}
- <td>{{ workshop.requested_workshop_instructor.get_full_name }}</td>
+ <td>{{ workshop.instructor.get_full_name }}</td>
{% endif %}
- <td>{{ workshop.requested_workshop_title | capfirst }}</td>
- <td>{{ workshop.requested_workshop_date | date }}</td>
+ <td>{{ workshop.title | capfirst }}</td>
+ <td>{{ workshop.date | date }}</td>
<td><span class = "label label-danger">{{ workshop.status }}</span></td>
{% endif %}
diff --git a/workshop_app/urls.py b/workshop_app/urls.py
index 704ae58..c58ba3b 100644
--- a/workshop_app/urls.py
+++ b/workshop_app/urls.py
@@ -30,21 +30,21 @@ urlpatterns = [
url(r'^logout/$', views.user_logout),
url(r'^view_profile/$', views.view_profile),
url(r'^edit_profile/$', views.edit_profile),
- url(r'^book/$', views.book),
- url(r'^book_workshop/$', views.book_workshop),
+ # url(r'^book/$', views.book),
+ # url(r'^book_workshop/$', views.book_workshop),
url(r'^my_workshops/$', views.my_workshops),
- url(r'^how_to_participate/$', views.how_to_participate),
- url(r'^faq/$', views.faq),
- url(r'^manage/$', views.manage),
- url(r'^view_workshoptype_list/$', views.view_workshoptype_list),
- url(r'^view_workshoptype_details/([1-9][0-9]*)$', \
- views.view_workshoptype_details),
- url(r'^create_workshop/$', views.create_workshop),
+ # url(r'^how_to_participate/$', views.how_to_participate),
+ # url(r'^faq/$', views.faq),
+ # url(r'^manage/$', views.manage),
+ # url(r'^view_workshoptype_list/$', views.view_workshoptype_list),
+ # url(r'^view_workshoptype_details/([1-9][0-9]*)$', \
+ # views.view_workshoptype_details),
+ # url(r'^create_workshop/$', views.create_workshop),
url(r'^propose_workshop/$', views.propose_workshop),
- url(r'^workshop_stats/$', views.workshop_stats),
- url(r'^jsi18n/$', django.views.i18n.javascript_catalog, js_info_dict),
- url(r'^self_workshop', views.self_workshop),
- url(r'^view_comment_profile/([1-9][0-9]*)$', views.view_comment_profile),
- url(r'^download/',views.download_csv_data),
+ # url(r'^workshop_stats/$', views.workshop_stats),
+ # url(r'^jsi18n/$', django.views.i18n.javascript_catalog, js_info_dict),
+ # url(r'^self_workshop', views.self_workshop),
+ # url(r'^view_comment_profile/([1-9][0-9]*)$', views.view_comment_profile),
+ # url(r'^download/',views.download_csv_data),
]
diff --git a/workshop_app/views.py b/workshop_app/views.py
index 3ebae9f..a5a7f66 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -1,46 +1,39 @@
-from textwrap import dedent
from os import listdir, path, sep
from zipfile import ZipFile
-import datetime as dt
-import csv
-import logging
+
+from teams.models import Team
+
try:
from StringIO import StringIO as string_io
except ImportError:
from io import BytesIO as string_io
-from datetime import datetime, date
-from itertools import chain
+from datetime import datetime
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.decorators import login_required
-from django.contrib import messages
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, redirect
from django.utils import timezone
-from django.http import HttpResponse, HttpResponseRedirect
-from django.conf import settings
-from django.contrib import messages
+from django.http import HttpResponse
from .forms import (
- UserRegistrationForm, UserLoginForm,
- ProfileForm, CreateWorkshop,
- ProposeWorkshopDateForm, ProfileCommentsForm
- )
+ UserRegistrationForm, UserLoginForm,
+ ProfileForm, CreateWorkshop,
+ WorkshopForm
+)
from .models import (
- Profile, User,
- has_profile, Workshop,
- WorkshopType, RequestedWorkshop,
- BookedWorkshop, ProposeWorkshopDate,
- Testimonial, ProfileComments, Banner
- )
-from teams.models import Team
+ Profile, User,
+ has_profile, Workshop,
+ WorkshopType,
+ Testimonial, Banner
+)
from .send_mails import send_email
__author__ = "Akshen Doke"
__credits__ = ["Mahesh Gudi", "Aditya P.", "Ankit Javalkar",
- "Prathamesh Salunke", "Kiran Kishore",
- "KhushalSingh Rajput", "Prabhu Ramachandran",
- "Arun KP"]
+ "Prathamesh Salunke", "Kiran Kishore",
+ "KhushalSingh Rajput", "Prabhu Ramachandran",
+ "Arun KP"]
def is_email_checked(user):
@@ -60,7 +53,7 @@ def index(request):
user = request.user
form = UserLoginForm()
testimonials = Testimonial.objects.all()
- if user.is_authenticated() and is_email_checked(user):
+ if user.is_authenticated and is_email_checked(user):
if user.groups.filter(name='instructor').count() > 0:
return redirect('/manage/')
return redirect('/book/')
@@ -75,13 +68,13 @@ def index(request):
return redirect('/manage/')
return redirect('/book/')
- return render(request, "workshop_app/index.html",
- {
- "form": form,
- "testimonials": testimonials,
- "banners": Banner.objects.all(),
- }
- )
+ return render(request, "workshop_app/index.html",
+ {
+ "form": form,
+ "testimonials": testimonials,
+ "banners": Banner.objects.all(),
+ }
+ )
def is_instructor(user):
@@ -94,7 +87,7 @@ def user_login(request):
user = request.user
if is_superuser(user):
return redirect('/admin')
- if user.is_authenticated():
+ if user.is_authenticated:
if user.groups.filter(name='instructor').count() > 0:
return redirect('/manage/')
return redirect('/book/')
@@ -125,19 +118,19 @@ def activate_user(request, key=None):
if is_superuser(user):
return redirect("/admin")
if key is None:
- if user.is_authenticated() and user.profile.is_email_verified==0 and \
- timezone.now() > user.profile.key_expiry_time:
+ 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:
+ {'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:
+ elif user.is_authenticated and user.profile.is_email_verified:
status = "2"
return render(request, 'workshop_app/activation.html',
- {'status':status})
+ {'status': status})
else:
return redirect('/register/')
@@ -154,7 +147,7 @@ def activate_user(request, key=None):
logout(request)
return redirect('/logout/')
return render(request, 'workshop_app/activation.html',
- {"status": status})
+ {"status": status})
def user_register(request):
@@ -168,556 +161,429 @@ def user_register(request):
login(request, new_user)
user_position = request.user.profile.position
send_email(
- request, call_on='Registration',
- user_position=user_position,
- key=key
- )
+ request, call_on='Registration',
+ user_position=user_position,
+ key=key
+ )
return render(request, 'workshop_app/activation.html')
else:
- if request.user.is_authenticated():
+ 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):
+ if request.user.is_authenticated and is_email_checked(request.user):
return redirect('/my_workshops/')
- elif request.user.is_authenticated():
+ 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/')
-
-
-@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.")
-
-
-@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/')
-
-
+# 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/')
+#
+#
+# @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.")
+#
+#
+# @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/')
+#
+#
@login_required
def my_workshops(request):
user = request.user
- if user.is_authenticated() and is_email_checked(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]
+ client_data = request.POST
+ action = request.POST.get('action')
+ if action == 'accept' or 'approve':
+ workshop_status = Workshop.objects.get(id=client_data.get('workshop_id'))
+ # Change Status of the selected workshop
+ workshop_status.status = 'ACCEPTED'
+ workshop_status.instructor = user
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
+ # Parameters for emails
+ cmail = ws.coordinator.email
+ cname = ws.coordinator.profile.user.get_full_name()
+ cnum = ws.coordinator.profile.phone_number
+ cinstitute = ws.coordinator.profile.institute
inum = request.user.profile.phone_number
- wtitle = ws.requested_workshop_title.workshoptype_name
+ wtitle = ws.title.name
+ workshop_date = str(ws.date)
- #For Instructor
+ # 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
+ user_position='instructor',
+ workshop_date=workshop_date,
+ 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_date=workshop_date,
+ workshop_title=wtitle,
+ other_email=cmail,
+ phone_number=inum
+ )
+
+ elif action == 'reject':
+ # Change Status of the selected workshop
+ workshop_status = RequestedWorkshop.objects.get(id=client_data.get('workshop_id'))
+ workshop_status.status = 'REJECTED'
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
- )
-
- elif client_data[-1] == 'CHANGE_DATE':
- temp, iid = client_data[0].split("=")
- temp, new_workshop_date = client_data[-2].split("%3D")
- cid, workshop_title_id = client_data[1], client_data[2]
- new_workshop_date = datetime.strptime(
- new_workshop_date, "%Y-%m-%d"
- )
- workshop_date = datetime.strptime(
- client_data[3], "%Y-%m-%d"
- )
+ # Parameters for emails
+ 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
+ workshop_date = str(ws.requested_workshop_date)
+ # For Instructor
+ send_email(request, call_on='Booking Request Rejected',
+ user_position='instructor',
+ workshop_date=workshop_date,
+ 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=workshop_date,
+ workshop_title=wtitle,
+ other_email=cmail
+ )
+
+ elif action == 'change_date':
+ cid = client_data.get('cid')
+ new_workshop_date = datetime.strptime(client_data.get('new_date'), "%Y-%m-%d")
cemail = User.objects.get(id=cid)
today = datetime.today()
if today > new_workshop_date:
- return HttpResponse("Please Give proper Date!")
+ # Invalid date
+ pass
else:
- result = RequestedWorkshop.objects.filter(
- requested_workshop_instructor=user.id,
- requested_workshop_coordinator=cid,
- requested_workshop_title_id=workshop_title_id,
- requested_workshop_date=workshop_date).update(
- requested_workshop_date=new_workshop_date)
- if result:
- del temp
+ if client_data.get('workshop_type') == 'requested':
+ workshop = RequestedWorkshop.objects.filter(id=client_data.get('workshop_id'))
+ workshop_date = workshop[0].requested_workshop_date
+ workshop.update(requested_workshop_date=new_workshop_date)
else:
- ProposeWorkshopDate.objects.filter(
- proposed_workshop_instructor=user.id,
- proposed_workshop_coordinator=cid,
- proposed_workshop_title_id=workshop_title_id,
- proposed_workshop_date=workshop_date).update(
- proposed_workshop_date=new_workshop_date)
-
- #For Instructor
+ workshop = ProposeWorkshopDate.objects.objects.filter(id=client_data.get('workshop_id'))
+ workshop_date = workshop.proposed_workshop_date
+ workshop.update(proposed_workshop_date=new_workshop_date)
+
+ # For Instructor
send_email(request, call_on='Change Date',
- user_position='instructor',
- workshop_date=workshop_date.date(),
- new_workshop_date=str(new_workshop_date.date())
- )
-
- #For Coordinator
- send_email(request, call_on='Change Date',
- new_workshop_date=str(new_workshop_date.date()),
- workshop_date=str(workshop_date.date()),
- other_email=cemail.email
- )
-
- return HttpResponse("Date Changed")
-
- 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
+ user_position='instructor',
+ workshop_date=str(workshop_date),
+ new_workshop_date=str(new_workshop_date.date())
+ )
- #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
- )
+ # For Coordinator
+ send_email(request, call_on='Change Date',
+ new_workshop_date=str(new_workshop_date.date()),
+ workshop_date=str(workshop_date),
+ other_email=cemail.email
+ )
workshops = []
today = datetime.today().date()
- workshop_occurence_list = RequestedWorkshop.objects.filter(
- requested_workshop_instructor=user.id,
- requested_workshop_date__gte=today,
- ).order_by('-requested_workshop_date')
+ proposed_workshop = Workshop.objects.filter(
+ instructor=user.id,
+ date__gte=today,
+ ).order_by('-date')
- proposed_workshop = ProposeWorkshopDate.objects.filter(
- proposed_workshop_instructor=user.id,
- proposed_workshop_date__gte=today,
- ).order_by('-proposed_workshop_date')
+ proposed_workshop_pending = Workshop.objects.filter(
+ status='Pending'
+ ).order_by('-date')
- proposed_workshop_pending = ProposeWorkshopDate.objects.filter(
- status='Pending'
- ).order_by('-proposed_workshop_date')
-
- workshops = list(workshop_occurence_list) + list(proposed_workshop) + list(proposed_workshop_pending)
+ workshops = list(proposed_workshop) + list(proposed_workshop_pending)
+ print(workshops)
# team_members = list(set(user.profile.team_set.all().values_list('members', flat=True)))
teams = Team.objects.filter(members=user.profile)
-
+ team_workshops = []
if teams:
team_members = Profile.objects.filter(team__in=teams).exclude(id=user.profile.id).distinct()
team_member_ids = team_members.values_list('user__id')
- team_workshops = ProposeWorkshopDate.objects.filter(
- proposed_workshop_date__gte=today,
- proposed_workshop_instructor_id__in=team_member_ids,
- )
+ team_workshops = Workshop.objects.filter(
+ date__gte=today,
+ instructor_id__in=team_member_ids,
+ )
return render(request, 'workshop_app/my_workshops.html',
- { "workshops" :workshops,
- "team_workshops": team_workshops,
- "today": today})
+ {"workshops": workshops,
+ "team_workshops": team_workshops,
+ "today": today})
else:
- workshops = []
- workshop_occurence_list = RequestedWorkshop.objects.filter(
- requested_workshop_coordinator=user.id
- ).order_by('-requested_workshop_date')
-
- proposed_workshop = ProposeWorkshopDate.objects.filter(
- proposed_workshop_coordinator=user.id
- ).order_by('-proposed_workshop_date')
-
- workshops = list(workshop_occurence_list) + list(proposed_workshop)
-
+ workshops = Workshop.objects.filter(
+ coordinator=user.id
+ ).order_by('-date')
return render(request, 'workshop_app/my_workshops.html',
- {"workshops": workshops})
+ {"workshops": workshops})
else:
return redirect('/login/')
@login_required
def propose_workshop(request):
- '''Coordinator proposed a workshop and date'''
+ """Coordinator proposed a workshop and date"""
user = request.user
if is_superuser(user):
@@ -727,38 +593,37 @@ def propose_workshop(request):
return redirect('/manage/')
else:
if request.method == 'POST':
- form = ProposeWorkshopDateForm(request.POST)
+ form = WorkshopForm(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():
+ form_data.coordinator = user
+ # Avoiding Duplicate workshop entries for same date and workshop_title
+ if Workshop.objects.filter(
+ date=form_data.date,
+ title=form_data.title,
+ coordinator=form_data.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
- )
+ user_position='instructor',
+ workshop_date=str(form_data.date),
+ workshop_title=form_data.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()
+ form = WorkshopForm()
return render(
- request, 'workshop_app/propose_workshop.html',
- {"form": form }
- )
+ request, 'workshop_app/propose_workshop.html',
+ {"form": form}
+ )
else:
return render(request, 'workshop_app/activation.html')
@@ -769,10 +634,10 @@ def view_profile(request):
user = request.user
if is_superuser(user):
return redirect('/admin')
- if is_email_checked(user) and user.is_authenticated():
+ if is_email_checked(user) and user.is_authenticated:
return render(request, "workshop_app/view_profile.html")
else:
- if user.is_authenticated():
+ if user.is_authenticated:
return render(request, 'workshop_app/activation.html')
else:
try:
@@ -818,8 +683,8 @@ def edit_profile(request):
form_data.save()
return render(
- request, 'workshop_app/profile_updated.html'
- )
+ request, 'workshop_app/profile_updated.html'
+ )
else:
context['form'] = form
return render(request, 'workshop_app/edit_profile.html', context)
@@ -840,7 +705,7 @@ def create_workshop(request):
form = CreateWorkshop(request.POST)
if form.is_valid():
form_data = form.save(commit=False)
- #form_data.profile_id = profile.id
+ # form_data.profile_id = profile.id
form_data.workshop_instructor = user
form_data.workshop_instructor.save()
form_data.save()
@@ -848,9 +713,9 @@ def create_workshop(request):
else:
form = CreateWorkshop()
return render(
- request, 'workshop_app/create_workshop.html',
- {"form": form }
- )
+ request, 'workshop_app/create_workshop.html',
+ {"form": form}
+ )
else:
return redirect('/book/')
@@ -864,9 +729,9 @@ def view_workshoptype_details(request, workshoptype_id):
view_workshoptype_details = WorkshopType.objects.get(id=workshoptype_id)
return render(
- request, 'workshop_app/view_workshoptype_details.html', \
- {'workshoptype': view_workshoptype_details}
- )
+ request, 'workshop_app/view_workshoptype_details.html', \
+ {'workshoptype': view_workshoptype_details}
+ )
def view_workshoptype_list(request):
@@ -877,22 +742,22 @@ def view_workshoptype_list(request):
workshoptype_list = WorkshopType.objects.all()
- paginator = Paginator(workshoptype_list, 12) #Show upto 12 workshops per page
+ 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.
+ # 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.
+ # 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}
- )
+ request, 'workshop_app/view_workshoptype_list.html', \
+ {'workshoptype': workshoptype}
+ )
def faq(request):
@@ -904,7 +769,7 @@ def how_to_participate(request):
def file_view(request, workshop_title):
- if workshop_title =='flowchart':
+ if workshop_title == 'flowchart':
return render(request, 'workshop_app/how_to_participate.html')
else:
filename = WorkshopType.objects.get(id=workshop_title)
@@ -919,13 +784,12 @@ def file_view(request, workshop_title):
zipfile_name.seek(0)
response = HttpResponse(content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename={0}.zip'.format(
- filename.workshoptype_name.replace(" ", "_")
- )
+ filename.workshoptype_name.replace(" ", "_")
+ )
response.write(zipfile_name.read())
return response
-
def check_workshop_type(x):
try:
y = datetime.strftime(x.proposed_workshop_date, '%d-%m-%Y')
@@ -933,360 +797,359 @@ def check_workshop_type(x):
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=120)
-
- #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:
- return redirect('/manage/')
-
-
-def self_workshop(request):
- return render(request, "workshop_app/self_workshop.html")
-
-
-
-@login_required
-def view_comment_profile(request, user_id):
- '''instructor can view/post comments on coordinator profile '''
- user = request.user
- if is_instructor(user) and is_email_checked(user):
- comment_form = ProfileCommentsForm()
- coordinator_profile = Profile.objects.get(user_id=user_id)
- requested_workshop = RequestedWorkshop.objects.filter(requested_workshop_coordinator=user_id).order_by(
- 'requested_workshop_title')
- propose_workshop = ProposeWorkshopDate.objects.filter(proposed_workshop_coordinator=user_id).order_by(
- 'proposed_workshop_date')
- workshops=[]
- for workshop in propose_workshop:
- workshops.append(workshop)
-
- for workshop in requested_workshop:
- workshops.append(workshop)
- try:
- comments = ProfileComments.objects.filter(coordinator_profile_id=user_id).order_by('-created_date')
- except:
- comments = None
- if request.method == 'POST':
- comment_formpost = ProfileCommentsForm(request.POST)
- if comment_formpost.is_valid():
- form_data = comment_formpost.save(commit=False)
- form_data.coordinator_profile_id = user_id
- form_data.instructor_profile_id = user.id
- form_data.save()
-
- return render(request, "workshop_app/view_comment_profile.html",
- {"coordinator_profile": coordinator_profile,
- "comments": comments,
- "comment_form": comment_form
- })
- else:
- if comments is not None:
- #Show upto 12 Workshops per page
- paginator = Paginator(comments, 12)
- page = request.GET.get('page')
- try:
- comments = paginator.page(page)
- except PageNotAnInteger:
- #If page is not an integer, deliver first page.
- comments = paginator.page(1)
- except EmptyPage:
- #If page is out of range(e.g 999999), deliver last page.
- comments = paginator.page(paginator.num_pages)
- workshop={}
- return render(request, "workshop_app/view_comment_profile.html",
- {"coordinator_profile": coordinator_profile,
- "comments": comments,
- "comment_form": comment_form,
- "Workshops":workshops})
- return redirect('/book/')
-
-@login_required
-def download_csv_data(request):
- user=request.user
- if user.profile.position == 'instructor':
- requested_workshop = RequestedWorkshop.objects.filter(requested_workshop_instructor=user.id).order_by(
- 'requested_workshop_title')
- propose_workshop = ProposeWorkshopDate.objects.filter(proposed_workshop_instructor=user.id).order_by(
- 'proposed_workshop_date')
- upcoming_workshops = []
- for workshop in propose_workshop:
- upcoming_workshops.append(workshop)
-
- for workshop in requested_workshop:
- upcoming_workshops.append(workshop)
-
- response = HttpResponse(content_type='text/csv')
-
- response['Content-Disposition'] = 'attachment;\
- filename="records_of_{0}.csv"'.format(
- user.username
- )
-
- 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 redirect('/book/')
+# @login_required
+# def workshop_stats(request):
+# user = request.user
+# today = datetime.now()
+# upto = today + dt.timedelta(days=120)
+#
+# #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:
+# return redirect('/manage/')
+#
+#
+# def self_workshop(request):
+# return render(request, "workshop_app/self_workshop.html")
+#
+#
+#
+# @login_required
+# def view_comment_profile(request, user_id):
+# '''instructor can view/post comments on coordinator profile '''
+# user = request.user
+# if is_instructor(user) and is_email_checked(user):
+# comment_form = ProfileCommentsForm()
+# coordinator_profile = Profile.objects.get(user_id=user_id)
+# requested_workshop = RequestedWorkshop.objects.filter(requested_workshop_coordinator=user_id).order_by(
+# 'requested_workshop_title')
+# propose_workshop = ProposeWorkshopDate.objects.filter(proposed_workshop_coordinator=user_id).order_by(
+# 'proposed_workshop_date')
+# workshops=[]
+# for workshop in propose_workshop:
+# workshops.append(workshop)
+#
+# for workshop in requested_workshop:
+# workshops.append(workshop)
+# try:
+# comments = ProfileComments.objects.filter(coordinator_profile_id=user_id).order_by('-created_date')
+# except:
+# comments = None
+# if request.method == 'POST':
+# comment_formpost = ProfileCommentsForm(request.POST)
+# if comment_formpost.is_valid():
+# form_data = comment_formpost.save(commit=False)
+# form_data.coordinator_profile_id = user_id
+# form_data.instructor_profile_id = user.id
+# form_data.save()
+#
+# return render(request, "workshop_app/view_comment_profile.html",
+# {"coordinator_profile": coordinator_profile,
+# "comments": comments,
+# "comment_form": comment_form
+# })
+# else:
+# if comments is not None:
+# #Show upto 12 Workshops per page
+# paginator = Paginator(comments, 12)
+# page = request.GET.get('page')
+# try:
+# comments = paginator.page(page)
+# except PageNotAnInteger:
+# #If page is not an integer, deliver first page.
+# comments = paginator.page(1)
+# except EmptyPage:
+# #If page is out of range(e.g 999999), deliver last page.
+# comments = paginator.page(paginator.num_pages)
+# workshop={}
+# return render(request, "workshop_app/view_comment_profile.html",
+# {"coordinator_profile": coordinator_profile,
+# "comments": comments,
+# "comment_form": comment_form,
+# "Workshops":workshops})
+# return redirect('/book/')
+#
+# @login_required
+# def download_csv_data(request):
+# user=request.user
+# if user.profile.position == 'instructor':
+# requested_workshop = RequestedWorkshop.objects.filter(requested_workshop_instructor=user.id).order_by(
+# 'requested_workshop_title')
+# propose_workshop = ProposeWorkshopDate.objects.filter(proposed_workshop_instructor=user.id).order_by(
+# 'proposed_workshop_date')
+# upcoming_workshops = []
+# for workshop in propose_workshop:
+# upcoming_workshops.append(workshop)
+#
+# for workshop in requested_workshop:
+# upcoming_workshops.append(workshop)
+#
+# response = HttpResponse(content_type='text/csv')
+#
+# response['Content-Disposition'] = 'attachment;\
+# filename="records_of_{0}.csv"'.format(
+# user.username
+# )
+#
+# 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 redirect('/book/')