From 379d04803c59b350b7061ab2557542449aafc0e8 Mon Sep 17 00:00:00 2001 From: Akshen Date: Tue, 7 Feb 2017 11:38:28 +0530 Subject: Initial Commit --- workshop_app/__init__.py | 0 workshop_app/admin.py | 3 +++ workshop_app/apps.py | 7 +++++++ workshop_app/migrations/__init__.py | 0 workshop_app/models.py | 5 +++++ workshop_app/tests.py | 3 +++ workshop_app/views.py | 3 +++ 7 files changed, 21 insertions(+) create mode 100644 workshop_app/__init__.py create mode 100644 workshop_app/admin.py create mode 100644 workshop_app/apps.py create mode 100644 workshop_app/migrations/__init__.py create mode 100644 workshop_app/models.py create mode 100644 workshop_app/tests.py create mode 100644 workshop_app/views.py (limited to 'workshop_app') diff --git a/workshop_app/__init__.py b/workshop_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workshop_app/admin.py b/workshop_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/workshop_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/workshop_app/apps.py b/workshop_app/apps.py new file mode 100644 index 0000000..dc9a567 --- /dev/null +++ b/workshop_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class WorkshopAppConfig(AppConfig): + name = 'workshop_app' diff --git a/workshop_app/migrations/__init__.py b/workshop_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workshop_app/models.py b/workshop_app/models.py new file mode 100644 index 0000000..bd4b2ab --- /dev/null +++ b/workshop_app/models.py @@ -0,0 +1,5 @@ +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/workshop_app/tests.py b/workshop_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/workshop_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/workshop_app/views.py b/workshop_app/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/workshop_app/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. -- cgit From 8a2bd288c77ce3165518f7bf1eff75825b4db5b3 Mon Sep 17 00:00:00 2001 From: Akshen Date: Tue, 14 Feb 2017 14:01:37 +0530 Subject: Basic Login Done --- workshop_app/admin.py | 2 + workshop_app/models.py | 26 +++++++++-- workshop_app/views.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 5 deletions(-) (limited to 'workshop_app') diff --git a/workshop_app/admin.py b/workshop_app/admin.py index 8c38f3f..53d8ad5 100644 --- a/workshop_app/admin.py +++ b/workshop_app/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin +from .models import Profile # Register your models here. +admin.site.register(Profile) \ No newline at end of file diff --git a/workshop_app/models.py b/workshop_app/models.py index bd4b2ab..07db83a 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -1,5 +1,25 @@ -from __future__ import unicode_literals - +#from __future__ import unicode_literals from django.db import models +from django.contrib.auth.models import User + +position_choices = ( + ("student", "Student"), + ("instructor", "Instructor") + ) + +class Profile(models.Model): + """Profile for users""" + + user = models.OneToOneField(User) + institute = models.CharField(max_length=150) + department = models.CharField(max_length=150) + position = models.CharField(max_length=32, choices=position_choices) + + def __str__(self): + return u"{0} {1} | {2}".format(self.user.first_name, self.user.last_name, self.user.email) + + +def has_profile(user): + """ check if user has profile """ + return True if hasattr(user, 'profile') else False -# Create your models here. diff --git a/workshop_app/views.py b/workshop_app/views.py index 91ea44a..334a1dc 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,3 +1,119 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +from forms import UserRegistrationForm, UserLoginForm, ProfileForm +from .models import Profile, User, has_profile +from django.template import RequestContext +from django.contrib.auth import login, logout, authenticate +from django.contrib.auth.decorators import login_required +from django.contrib import messages -# Create your views here. + +def home(request): + '''Home''' + return render(request, "home.html") + +def is_instructor(user): + '''Check if the user is having instructor rights''' + if user.groups.filter(name='instructor').exists(): + return True + +def user_login(request): + '''Login''' + user = request.user + if user.is_authenticated(): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/view_profile/') + + if request.method == "POST": + form = UserLoginForm(request.POST) + if form.is_valid(): + user = form.cleaned_data + login(request, user) + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/view_profile/') + else: + return render(request, 'workshop_app/login.html', {"form": form}) + else: + form = UserLoginForm() + return render(request, 'workshop_app/login.html', {"form": form}) + +def user_logout(request): + '''Logout''' + logout(request) + return render(request, 'workshop_app/logout.html') + +def user_register(request): + '''User Registeration form''' + if request.method == 'POST': + form = UserRegistrationForm(request.POST) + if form.is_valid(): + data = form.cleaned_data + username, password = form.save() + new_user = authenticate(username=username, password=password) + login(request, new_user) + return redirect('/home') + else: + return render(request, "workshop_app/register.html", {"form": form}) + else: + form = UserRegistrationForm() + + return render(request, "workshop_app/register.html", {"form": form}) + + +def book(request): + user = request.user + if user.is_authenticated(): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return render(request, "workshop_app/booking.html") + else: + return redirect('/login/') + +def manage(request): + user = request.user + if user.is_authenticated(): + if user.groups.filter(name='instructor').count() > 0: + return render(request, "workshop_app/manage.html") + return redirect('/book/') + else: + return redirect('/login/') + +@login_required +def view_profile(request): + """ view moderators and users profile """ + return render(request, "workshop_app/view_profile.html") + +@login_required +def edit_profile(request): + """ edit profile details facility for instructor and students """ + + user = request.user + if is_instructor(user): + template = 'workshop_app/manage.html' + else: + template = 'workshop_app/user.html' + context = {'template': template} + if has_profile(user): + profile = Profile.objects.get(user_id=user.id) + else: + profile = None + + if request.method == 'POST': + form = ProfileForm(request.POST, user=user, instance=profile) + if form.is_valid(): + form_data = form.save(commit=False) + form_data.user = user + form_data.user.first_name = request.POST['first_name'] + form_data.user.last_name = request.POST['last_name'] + form_data.user.save() + form_data.save() + + return render(request, 'workshop_app/profile_updated.html', context) + else: + context['form'] = form + return my_render_to_response('workshop_app/edit_profile.html', context) + else: + form = ProfileForm(user=user, instance=profile) + context['form'] = form + return render(request, 'workshop_app/edit_profile.html', context) -- cgit From 39573ea6c7b15f863436355b2587d02d50373bf5 Mon Sep 17 00:00:00 2001 From: Akshen Date: Thu, 16 Feb 2017 12:07:19 +0530 Subject: Courses Model Added --- workshop_app/admin.py | 5 +++-- workshop_app/models.py | 17 +++++++++++++++-- workshop_app/views.py | 23 +++++++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'workshop_app') diff --git a/workshop_app/admin.py b/workshop_app/admin.py index 53d8ad5..5a4da13 100644 --- a/workshop_app/admin.py +++ b/workshop_app/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Profile +from .models import Profile, Courses # Register your models here. -admin.site.register(Profile) \ No newline at end of file +admin.site.register(Profile) +admin.site.register(Courses) \ No newline at end of file diff --git a/workshop_app/models.py b/workshop_app/models.py index 07db83a..0dbff06 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -2,13 +2,14 @@ from django.db import models from django.contrib.auth.models import User + position_choices = ( - ("student", "Student"), + ("coordinator", "Coordinator"), ("instructor", "Instructor") ) class Profile(models.Model): - """Profile for users""" + """Profile for users(instructors and coordinators)""" user = models.OneToOneField(User) institute = models.CharField(max_length=150) @@ -23,3 +24,15 @@ def has_profile(user): """ check if user has profile """ return True if hasattr(user, 'profile') else False +class Courses(models.Model): + """"Admin creates courses which can be used by the instructor to create workshops. + """ + + course_name = models.CharField(max_length=120) + course_description = models.TextField() + course_duration = models.CharField(max_length=12) + + + def __str__(self): + return u"{0} {1}".format(self.course_name, self.course_duration) + diff --git a/workshop_app/views.py b/workshop_app/views.py index 334a1dc..54dc43d 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -7,9 +7,10 @@ from django.contrib.auth.decorators import login_required from django.contrib import messages -def home(request): - '''Home''' - return render(request, "home.html") + +def index(request): + '''Landing Page''' + return render(request, "workshop_app/index.html") def is_instructor(user): '''Check if the user is having instructor rights''' @@ -86,13 +87,13 @@ def view_profile(request): @login_required def edit_profile(request): - """ edit profile details facility for instructor and students """ + """ edit profile details facility for instructor and coordinator """ user = request.user if is_instructor(user): template = 'workshop_app/manage.html' else: - template = 'workshop_app/user.html' + template = 'workshop_app/booking.html' context = {'template': template} if has_profile(user): profile = Profile.objects.get(user_id=user.id) @@ -112,8 +113,18 @@ def edit_profile(request): return render(request, 'workshop_app/profile_updated.html', context) else: context['form'] = form - return my_render_to_response('workshop_app/edit_profile.html', context) + return render(request, 'workshop_app/edit_profile.html', context) else: form = ProfileForm(user=user, instance=profile) context['form'] = form return render(request, 'workshop_app/edit_profile.html', context) + +@login_required +def create_workshop(request): + '''Instructor creates workshops''' + + user = request.user + if is_instructor(user): + return render(request, 'workshop_app/create_workshop.html') + else: + return redirect('/book/') -- cgit From 057e1ded6560f03ed5a66885eef452bf3317b645 Mon Sep 17 00:00:00 2001 From: Akshen Date: Thu, 23 Feb 2017 16:57:35 +0530 Subject: instructor on hold since looking after PythonExpress model --- workshop_app/admin.py | 5 +- workshop_app/forms.py | 127 +++++++++++++++++++++ workshop_app/models.py | 28 ++++- workshop_app/static/workshop_app/css/modal.css | 20 ++++ .../static/workshop_app/css/sticky-footer.css | 10 ++ workshop_app/static/workshop_app/js/overlay.js | 7 ++ workshop_app/templates/workshop_app/base.html | 52 +++++++++ workshop_app/templates/workshop_app/booking.html | 22 ++++ .../templates/workshop_app/create_workshop.html | 48 ++++++++ .../templates/workshop_app/edit_profile.html | 37 ++++++ workshop_app/templates/workshop_app/index.html | 10 ++ workshop_app/templates/workshop_app/login.html | 20 ++++ workshop_app/templates/workshop_app/logout.html | 16 +++ workshop_app/templates/workshop_app/manage.html | 35 ++++++ .../templates/workshop_app/profile_updated.html | 28 +++++ workshop_app/templates/workshop_app/register.html | 18 +++ .../workshop_app/view_course_details.html | 26 +++++ .../templates/workshop_app/view_course_list.html | 101 ++++++++++++++++ .../templates/workshop_app/view_profile.html | 57 +++++++++ workshop_app/views.py | 64 +++++++++-- 20 files changed, 714 insertions(+), 17 deletions(-) create mode 100644 workshop_app/forms.py create mode 100644 workshop_app/static/workshop_app/css/modal.css create mode 100644 workshop_app/static/workshop_app/css/sticky-footer.css create mode 100644 workshop_app/static/workshop_app/js/overlay.js create mode 100644 workshop_app/templates/workshop_app/base.html create mode 100644 workshop_app/templates/workshop_app/booking.html create mode 100644 workshop_app/templates/workshop_app/create_workshop.html create mode 100644 workshop_app/templates/workshop_app/edit_profile.html create mode 100644 workshop_app/templates/workshop_app/index.html create mode 100644 workshop_app/templates/workshop_app/login.html create mode 100644 workshop_app/templates/workshop_app/logout.html create mode 100644 workshop_app/templates/workshop_app/manage.html create mode 100644 workshop_app/templates/workshop_app/profile_updated.html create mode 100644 workshop_app/templates/workshop_app/register.html create mode 100644 workshop_app/templates/workshop_app/view_course_details.html create mode 100644 workshop_app/templates/workshop_app/view_course_list.html create mode 100644 workshop_app/templates/workshop_app/view_profile.html (limited to 'workshop_app') diff --git a/workshop_app/admin.py b/workshop_app/admin.py index 5a4da13..b980438 100644 --- a/workshop_app/admin.py +++ b/workshop_app/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from .models import Profile, Courses +from .models import Profile, Course, Workshop # Register your models here. admin.site.register(Profile) -admin.site.register(Courses) \ No newline at end of file +admin.site.register(Course) +admin.site.register(Workshop) \ No newline at end of file diff --git a/workshop_app/forms.py b/workshop_app/forms.py new file mode 100644 index 0000000..3cc0021 --- /dev/null +++ b/workshop_app/forms.py @@ -0,0 +1,127 @@ +from django import forms +from .models import Profile, Course, Workshop +from string import punctuation, digits, letters +from django.contrib.auth.models import User +from django.contrib.auth import authenticate + + + +UNAME_CHARS = letters + "._" + digits +PWD_CHARS = letters + punctuation + digits + +position_choices = ( + ("coordinator", "Coordinator"), + ("instructor", "Instructor") + ) + +class UserRegistrationForm(forms.Form): + """A Class to create new form for User's Registration. + It has the various fields and functions required to register + a new user to the system""" + + username = forms.CharField(max_length=32, help_text='''Letters, digits, + period only.''') + email = forms.EmailField() + password = forms.CharField(max_length=32, widget=forms.PasswordInput()) + confirm_password = forms.CharField\ + (max_length=32, widget=forms.PasswordInput()) + first_name = forms.CharField(max_length=32) + last_name = forms.CharField(max_length=32) + institute = forms.CharField\ + (max_length=128, help_text='Institute/Organization') + department = forms.CharField\ + (max_length=64, help_text='Department you work/study at') + position = forms.ChoiceField\ + (help_text='If you are an instructor please mail us at python[at]fossee[dot]in', choices=position_choices) + + def clean_username(self): + u_name = self.cleaned_data["username"] + if u_name.strip(UNAME_CHARS): + msg = "Only letters, digits, period are"\ + " allowed in username" + raise forms.ValidationError(msg) + try: + User.objects.get(username__exact=u_name) + raise forms.ValidationError("Username already exists.") + except User.DoesNotExist: + return u_name + + def clean_password(self): + pwd = self.cleaned_data['password'] + if pwd.strip(PWD_CHARS): + raise forms.ValidationError("Only letters, digits and punctuation\ + are allowed in password") + return pwd + + def clean_confirm_password(self): + c_pwd = self.cleaned_data['confirm_password'] + pwd = self.data['password'] + if c_pwd != pwd: + raise forms.ValidationError("Passwords do not match") + + return c_pwd + + def save(self): + u_name = self.cleaned_data["username"] + u_name = u_name.lower() + pwd = self.cleaned_data["password"] + email = self.cleaned_data['email'] + new_user = User.objects.create_user(u_name, email, pwd) + + new_user.first_name = self.cleaned_data["first_name"] + new_user.last_name = self.cleaned_data["last_name"] + new_user.save() + + cleaned_data = self.cleaned_data + 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.save() + + return u_name, pwd + +class UserLoginForm(forms.Form): + """Creates a form which will allow the user to log into the system.""" + + username = forms.CharField(max_length=32) + password = forms.CharField(max_length=32, widget=forms.PasswordInput()) + + def clean(self): + super(UserLoginForm, self).clean() + try: + 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") + 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', + 'position'] + + first_name = forms.CharField(max_length=32) + last_name = forms.CharField(max_length=32) + + def __init__(self, *args, **kwargs): + if 'user' in kwargs: + user = kwargs.pop('user') + super(ProfileForm, self).__init__(*args, **kwargs) + 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 courses available.""" + + class Meta: + model = Workshop + fields = ['workshop_title', 'date', 'start_time', 'end_time'] \ No newline at end of file diff --git a/workshop_app/models.py b/workshop_app/models.py index 0dbff06..9aceb57 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -8,6 +8,12 @@ position_choices = ( ("instructor", "Instructor") ) + + +def has_profile(user): + """ check if user has profile """ + return True if hasattr(user, 'profile') else False + class Profile(models.Model): """Profile for users(instructors and coordinators)""" @@ -20,11 +26,7 @@ class Profile(models.Model): return u"{0} {1} | {2}".format(self.user.first_name, self.user.last_name, self.user.email) -def has_profile(user): - """ check if user has profile """ - return True if hasattr(user, 'profile') else False - -class Courses(models.Model): +class Course(models.Model): """"Admin creates courses which can be used by the instructor to create workshops. """ @@ -32,7 +34,21 @@ class Courses(models.Model): course_description = models.TextField() course_duration = models.CharField(max_length=12) - def __str__(self): return u"{0} {1}".format(self.course_name, self.course_duration) + +class Workshop(models.Model): + """Instructor Creates workshop based on + Courses available""" + + workshop_creator = models.ForeignKey(Profile, on_delete=models.CASCADE) + workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE,\ + help_text='Select the course you would like to create a workshop for') + date = models.DateField() + start_time = models.TimeField() + end_time = models.TimeField() + status = models.BooleanField() + + def __str__(self): + return u"{0} | {1}".format(self.workshop_title, self.date) diff --git a/workshop_app/static/workshop_app/css/modal.css b/workshop_app/static/workshop_app/css/modal.css new file mode 100644 index 0000000..dc767a0 --- /dev/null +++ b/workshop_app/static/workshop_app/css/modal.css @@ -0,0 +1,20 @@ +#overlay { + visibility: hidden; + position: absolute; + left: 0px; + top: 0px; + width:100%; + height:100%; + text-align:center; + z-index: 1000; +} + +#overlay div { + width:900px; + height: 450px; + margin: 100px auto; + background-color: #fff; + border:1px solid #000; + padding:15px; + text-align:center; +} diff --git a/workshop_app/static/workshop_app/css/sticky-footer.css b/workshop_app/static/workshop_app/css/sticky-footer.css new file mode 100644 index 0000000..42471ee --- /dev/null +++ b/workshop_app/static/workshop_app/css/sticky-footer.css @@ -0,0 +1,10 @@ +.footer { + position: absolute; + bottom: 0; + padding-left: 75px; + +} + +.hiddenRow { + padding: 0 !important; +} \ No newline at end of file diff --git a/workshop_app/static/workshop_app/js/overlay.js b/workshop_app/static/workshop_app/js/overlay.js new file mode 100644 index 0000000..6563c0d --- /dev/null +++ b/workshop_app/static/workshop_app/js/overlay.js @@ -0,0 +1,7 @@ +function overlay(course_no) { + el = document.getElementById("overlay"); + course_id = document.getElementById("course_id"); + el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible"; + + console.log(course_no); +} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html new file mode 100644 index 0000000..cebab31 --- /dev/null +++ b/workshop_app/templates/workshop_app/base.html @@ -0,0 +1,52 @@ + + + + + + {% block title %} + HomePage + {% endblock %} + + + + + + + + + + + + {% block extra %} + {% endblock %} + + + + {% block header %} + + {% endblock %} + + {% block content %} +

Base Template Content. Please override me

+ {% endblock %} + + + + \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html new file mode 100644 index 0000000..05ddbb6 --- /dev/null +++ b/workshop_app/templates/workshop_app/booking.html @@ -0,0 +1,22 @@ +{% extends './base.html' %} + +{% block title %} + Booking +{% endblock %} + +{% block header %} + +{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html new file mode 100644 index 0000000..64727ad --- /dev/null +++ b/workshop_app/templates/workshop_app/create_workshop.html @@ -0,0 +1,48 @@ +{% extends "./base.html" %} + +{% block title %} + Create Event +{% endblock %} + + {% block extra %} + + + + + + + + {% endblock %} + +{% block header %} + +{% endblock %} + +{% block content %} +
+
+ {% csrf_token %} + {{ form.as_p }} +
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/edit_profile.html b/workshop_app/templates/workshop_app/edit_profile.html new file mode 100644 index 0000000..d2c5655 --- /dev/null +++ b/workshop_app/templates/workshop_app/edit_profile.html @@ -0,0 +1,37 @@ +{% extends "./base.html" %} + +{% block title %} + Edit Profile +{% endblock %} + +{% block header %} + +{% endblock %} + +{% block content %} +
+
+ {% csrf_token %} +
+ + {{ form.as_table }} +
+
+
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/index.html b/workshop_app/templates/workshop_app/index.html new file mode 100644 index 0000000..7e163c8 --- /dev/null +++ b/workshop_app/templates/workshop_app/index.html @@ -0,0 +1,10 @@ +{% extends "./base.html" %} + + + + + {% block title %} + Welcome + {% endblock %} + + \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/login.html b/workshop_app/templates/workshop_app/login.html new file mode 100644 index 0000000..fa505ab --- /dev/null +++ b/workshop_app/templates/workshop_app/login.html @@ -0,0 +1,20 @@ +{% extends './base.html' %} + + {% block title %} + Login + {% endblock %} + + {% block content %} +
+
+
+ {% csrf_token %} + {{ form.as_table }} +
+
+ +
+
+
+
+ {% endblock %} diff --git a/workshop_app/templates/workshop_app/logout.html b/workshop_app/templates/workshop_app/logout.html new file mode 100644 index 0000000..70a7862 --- /dev/null +++ b/workshop_app/templates/workshop_app/logout.html @@ -0,0 +1,16 @@ +{% extends './base.html' %} + + {% block title %} + Logged out + {% endblock %} + + + {% block content %} +
+
+

You have logged out successfully.

+

If you want to Login again please click here

+
+
+ + {% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html new file mode 100644 index 0000000..a161ec2 --- /dev/null +++ b/workshop_app/templates/workshop_app/manage.html @@ -0,0 +1,35 @@ +{% extends './base.html' %} + +{% block header %} + +{% endblock %} + +{% block content %} + +
+ {% csrf_token %} + {% for w in workshop_details %} + {{ w.date }}
+ {{ w.start_time }}
+ {{ w.end_time }}
+ {{ w.workshop_creator }}
+ {{ w.workshop_title }} + {{ w.status }} + {% endfor %} +
+ +{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/profile_updated.html b/workshop_app/templates/workshop_app/profile_updated.html new file mode 100644 index 0000000..e9a0d54 --- /dev/null +++ b/workshop_app/templates/workshop_app/profile_updated.html @@ -0,0 +1,28 @@ +{% extends "./base.html" %} + +{% block title %} + Profile Changing +{% endblock %} + +{% block header %} + +{% endblock %} + +{% block content %} +{% dinesh akshen %} +

Your Profile has changed {{ user.first_name }}

+{% endblock content %} + diff --git a/workshop_app/templates/workshop_app/register.html b/workshop_app/templates/workshop_app/register.html new file mode 100644 index 0000000..fdb8bf8 --- /dev/null +++ b/workshop_app/templates/workshop_app/register.html @@ -0,0 +1,18 @@ +{% extends './base.html' %} + + {% block title %} + Register + {% endblock %} + + {% block content %} +
+
+
+ {% csrf_token %} +
+ {{ form.as_p }} + +
+
+
+ {% endblock %} diff --git a/workshop_app/templates/workshop_app/view_course_details.html b/workshop_app/templates/workshop_app/view_course_details.html new file mode 100644 index 0000000..58004da --- /dev/null +++ b/workshop_app/templates/workshop_app/view_course_details.html @@ -0,0 +1,26 @@ +{% extends './base.html' %} + +{% block title %} + View Course Details +{% endblock %} + +{% block header %} + +{% endblock %} + +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/view_course_list.html b/workshop_app/templates/workshop_app/view_course_list.html new file mode 100644 index 0000000..4348a0d --- /dev/null +++ b/workshop_app/templates/workshop_app/view_course_list.html @@ -0,0 +1,101 @@ +{% extends './base.html' %} + +{% block title %} + View Course List +{% endblock %} + + +{% block header %} + +{% endblock %} + +{% block extra %} + + + + + + +{% endblock %} + +{% block content %} + +
+ + + + + + + + + + + {% for course in courses %} + + + + + + + + + + + + + {% endfor %} +
idCourse NameCourse Duration
{{ forloop.counter }}{{ course.course_name }}{{ course.course_duration }}
+
+ + + + + + +
{{ course.course_description|safe }}
+
+
+ +
+ +
+ + +
+{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/view_profile.html b/workshop_app/templates/workshop_app/view_profile.html new file mode 100644 index 0000000..546af88 --- /dev/null +++ b/workshop_app/templates/workshop_app/view_profile.html @@ -0,0 +1,57 @@ +{% extends './base.html' %} + +{% block title %} + View Profile +{% endblock %} + +{% block header %} + +{% endblock %} + +{% block content %} + +
+ {% csrf_token %} + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ Edit Profile +
+{% endblock %} diff --git a/workshop_app/views.py b/workshop_app/views.py index 54dc43d..2cb805e 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,10 +1,11 @@ from django.shortcuts import render, redirect -from forms import UserRegistrationForm, UserLoginForm, ProfileForm -from .models import Profile, User, has_profile +from .forms import UserRegistrationForm, UserLoginForm, ProfileForm, CreateWorkshop +from .models import Profile, User, has_profile, Workshop, Course from django.template import RequestContext 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 @@ -23,7 +24,7 @@ def user_login(request): if user.is_authenticated(): if user.groups.filter(name='instructor').count() > 0: return redirect('/manage/') - return redirect('/view_profile/') + return redirect('/book/') if request.method == "POST": form = UserLoginForm(request.POST) @@ -32,7 +33,7 @@ def user_login(request): login(request, user) if user.groups.filter(name='instructor').count() > 0: return redirect('/manage/') - return redirect('/view_profile/') + return redirect('/book/') else: return render(request, 'workshop_app/login.html', {"form": form}) else: @@ -53,12 +54,11 @@ def user_register(request): username, password = form.save() new_user = authenticate(username=username, password=password) login(request, new_user) - return redirect('/home') + return redirect('/view_profile/') else: return render(request, "workshop_app/register.html", {"form": form}) else: form = UserRegistrationForm() - return render(request, "workshop_app/register.html", {"form": form}) @@ -71,18 +71,21 @@ def book(request): else: return redirect('/login/') +@login_required def manage(request): user = request.user if user.is_authenticated(): + print user.id, user if user.groups.filter(name='instructor').count() > 0: - return render(request, "workshop_app/manage.html") + workshop_details = Workshop.objects.all() + return render(request, "workshop_app/manage.html", {"workshop_details": workshop_details}) return redirect('/book/') else: return redirect('/login/') @login_required def view_profile(request): - """ view moderators and users profile """ + """ view instructor and coordinator profile """ return render(request, "workshop_app/view_profile.html") @login_required @@ -125,6 +128,49 @@ def create_workshop(request): user = request.user if is_instructor(user): - return render(request, 'workshop_app/create_workshop.html') + if request.method == 'POST': + form = CreateWorkshop(request.POST) + if form.is_valid(): + form.save() + return redirect('/manage/') + else: + form = CreateWorkshop() + return render(request, 'workshop_app/create_workshop.html', {"form": form }) + else: + return redirect('/book/') + +@login_required +def view_course_list(request): + '''Gives the course details ''' + user = request.user + if is_instructor(user): + course_list = Course.objects.all() + paginator = Paginator(course_list, 9) #Show upto 12 Courses per page + + page = request.GET.get('page') + try: + courses = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + courses = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + courses = paginator.page(paginator.num_pages) + + return render(request, 'workshop_app/view_course_list.html', \ + {'courses': courses}) + else: return redirect('/book/') + +@login_required +def view_course_details(request): + '''Gives the course details ''' + + user = request.user + if is_instructor(user): + + return redirect('/') + + else: + return redirect('/book/') \ No newline at end of file -- cgit From 2a0875890fd64e6b3b86a7e08378eea36bcf7ce4 Mon Sep 17 00:00:00 2001 From: Akshen Doke Date: Tue, 7 Mar 2017 11:26:04 +0530 Subject: Phone Number added, email verification todo --- workshop_app/forms.py | 24 ++++++++---- workshop_app/models.py | 14 ++++++- workshop_app/templates/workshop_app/booking.html | 2 +- .../templates/workshop_app/create_workshop.html | 2 +- .../templates/workshop_app/edit_profile.html | 2 +- workshop_app/templates/workshop_app/index.html | 2 +- workshop_app/templates/workshop_app/login.html | 2 +- workshop_app/templates/workshop_app/logout.html | 2 +- workshop_app/templates/workshop_app/manage.html | 2 +- .../templates/workshop_app/profile_updated.html | 5 +-- workshop_app/templates/workshop_app/register.html | 2 +- .../workshop_app/view_course_details.html | 2 +- .../templates/workshop_app/view_course_list.html | 2 +- .../templates/workshop_app/view_profile.html | 6 ++- workshop_app/views.py | 45 +++++++++++++++++----- 15 files changed, 81 insertions(+), 33 deletions(-) (limited to 'workshop_app') diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 3cc0021..4264c20 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -27,12 +27,18 @@ class UserRegistrationForm(forms.Form): (max_length=32, widget=forms.PasswordInput()) first_name = forms.CharField(max_length=32) last_name = forms.CharField(max_length=32) - institute = forms.CharField\ - (max_length=128, help_text='Institute/Organization') - department = forms.CharField\ - (max_length=64, help_text='Department you work/study at') - position = forms.ChoiceField\ - (help_text='If you are an instructor please mail us at python[at]fossee[dot]in', choices=position_choices) + phone_number = forms.RegexField(regex=r'^\+?1?\d{9,15}$', + error_message=("Phone number must be entered \ + in the format: '+999999999'.\ + Up to 15 digits allowed.")) + institute = forms.CharField(max_length=128, + help_text='Institute/Organization') + department = forms.CharField(max_length=64, help_text='Department you work \ + study at') + position = forms.ChoiceField(help_text='If you are an instructor please \ + mail us at python[at]fossee[dot]in', + choices=position_choices + ) def clean_username(self): u_name = self.cleaned_data["username"] @@ -65,11 +71,13 @@ class UserRegistrationForm(forms.Form): u_name = self.cleaned_data["username"] u_name = u_name.lower() pwd = self.cleaned_data["password"] - email = self.cleaned_data['email'] + email = self.cleaned_data["email"] new_user = User.objects.create_user(u_name, email, pwd) new_user.first_name = self.cleaned_data["first_name"] new_user.last_name = self.cleaned_data["last_name"] + + new_user.save() cleaned_data = self.cleaned_data @@ -77,7 +85,7 @@ class UserRegistrationForm(forms.Form): new_profile.institute = cleaned_data["institute"] new_profile.department = cleaned_data["department"] new_profile.position = cleaned_data["position"] - + new_profile.phone_number = cleaned_data["phone_number"] new_profile.save() return u_name, pwd diff --git a/workshop_app/models.py b/workshop_app/models.py index 9aceb57..8c146c0 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -1,6 +1,7 @@ #from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import User +from django.core.validators import RegexValidator position_choices = ( @@ -20,10 +21,21 @@ class Profile(models.Model): user = models.OneToOneField(User) institute = models.CharField(max_length=150) department = models.CharField(max_length=150) + phone_number = models.CharField( + max_length=15, + validators=[RegexValidator( + regex=r'^\+?1?\d{9,15}$', message=( + "Phone number must be entered \ + in the format: '+999999999'.\ + Up to 15 digits allowed.") + )]) position = models.CharField(max_length=32, choices=position_choices) def __str__(self): - return u"{0} {1} | {2}".format(self.user.first_name, self.user.last_name, self.user.email) + return u"{0} {1} | {2} ".format(self.user.first_name, + self.user.last_name, + self.user.email + ) class Course(models.Model): diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html index 05ddbb6..01cd609 100644 --- a/workshop_app/templates/workshop_app/booking.html +++ b/workshop_app/templates/workshop_app/booking.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} Booking diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html index 64727ad..93de011 100644 --- a/workshop_app/templates/workshop_app/create_workshop.html +++ b/workshop_app/templates/workshop_app/create_workshop.html @@ -1,4 +1,4 @@ -{% extends "./base.html" %} +{% extends "workshop_app/base.html" %} {% block title %} Create Event diff --git a/workshop_app/templates/workshop_app/edit_profile.html b/workshop_app/templates/workshop_app/edit_profile.html index d2c5655..6d5698b 100644 --- a/workshop_app/templates/workshop_app/edit_profile.html +++ b/workshop_app/templates/workshop_app/edit_profile.html @@ -1,4 +1,4 @@ -{% extends "./base.html" %} +{% extends "workshop_app/base.html" %} {% block title %} Edit Profile diff --git a/workshop_app/templates/workshop_app/index.html b/workshop_app/templates/workshop_app/index.html index 7e163c8..f0923bb 100644 --- a/workshop_app/templates/workshop_app/index.html +++ b/workshop_app/templates/workshop_app/index.html @@ -1,4 +1,4 @@ -{% extends "./base.html" %} +{% extends "workshop_app/base.html" %} diff --git a/workshop_app/templates/workshop_app/login.html b/workshop_app/templates/workshop_app/login.html index fa505ab..cc733c7 100644 --- a/workshop_app/templates/workshop_app/login.html +++ b/workshop_app/templates/workshop_app/login.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} Login diff --git a/workshop_app/templates/workshop_app/logout.html b/workshop_app/templates/workshop_app/logout.html index 70a7862..793bf5a 100644 --- a/workshop_app/templates/workshop_app/logout.html +++ b/workshop_app/templates/workshop_app/logout.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} Logged out diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html index a161ec2..4a399a1 100644 --- a/workshop_app/templates/workshop_app/manage.html +++ b/workshop_app/templates/workshop_app/manage.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block header %} {% endblock %} +{% csrf_token %} {% block content %} - +
- {% csrf_token %} diff --git a/workshop_app/views.py b/workshop_app/views.py index fab6e8d..f32e4a1 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,5 +1,8 @@ -from .forms import UserRegistrationForm, UserLoginForm, ProfileForm, CreateWorkshop +from .forms import ( + UserRegistrationForm, UserLoginForm, + ProfileForm, CreateWorkshop + ) from .models import Profile, User, has_profile, Workshop, Course from django.template import RequestContext from django.contrib.auth import login, logout, authenticate @@ -9,7 +12,13 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.mail import send_mail from django.shortcuts import render, redirect from django.db import IntegrityError - +from workshop_portal.settings import ( + EMAIL_HOST, + EMAIL_PORT, + EMAIL_HOST_USER, + EMAIL_HOST_PASSWORD, + EMAIL_USE_TLS + ) def index(request): '''Landing Page''' @@ -58,15 +67,21 @@ def user_register(request): new_user = authenticate(username=username, password=password) login(request, new_user) user_position = request.user.profile.position - send_email(request, call_on='Registration', - user_position=user_position) + send_email( + request, call_on='Registration', + user_position=user_position + ) return redirect('/view_profile/') except IntegrityError as e: - return render(request, - "workshop_app/registeration_error.html") + return render( + request, + "workshop_app/registeration_error.html" + ) else: - return render(request, "workshop_app/register.html", - {"form": form}) + return render( + request, "workshop_app/register.html", + {"form": form} + ) else: form = UserRegistrationForm() return render(request, "workshop_app/register.html", {"form": form}) @@ -85,10 +100,13 @@ def book(request): def manage(request): user = request.user if user.is_authenticated(): - print user.id, user + #print user.id, user if user.groups.filter(name='instructor').count() > 0: #Move user to the group via admin workshop_details = Workshop.objects.all() - return render(request, "workshop_app/manage.html", {"workshop_details": workshop_details}) + return render( + request, "workshop_app/manage.html", + {"workshop_details": workshop_details} + ) return redirect('/book/') else: return redirect('/login/') @@ -123,7 +141,10 @@ def edit_profile(request): form_data.user.save() form_data.save() - return render(request, 'workshop_app/profile_updated.html', context) + return render( + request, 'workshop_app/profile_updated.html', + context + ) else: context['form'] = form return render(request, 'workshop_app/edit_profile.html', context) @@ -145,7 +166,10 @@ def create_workshop(request): return redirect('/manage/') else: form = CreateWorkshop() - return render(request, 'workshop_app/create_workshop.html', {"form": form }) + return render( + request, 'workshop_app/create_workshop.html', + {"form": form } + ) else: return redirect('/book/') @@ -167,8 +191,10 @@ def view_course_list(request): #If page is out of range(e.g 999999), deliver last page. courses = paginator.page(paginator.num_pages) - return render(request, 'workshop_app/view_course_list.html', \ - {'courses': courses}) + return render( + request, 'workshop_app/view_course_list.html', \ + {'courses': courses} + ) else: return redirect('/book/') @@ -187,14 +213,32 @@ def view_course_details(request): def send_email(request, call_on, user_position=None): ''' - Email sending function + Email sending function while registration and + booking confirmation. ''' if call_on == 'Registration': if user_position == 'instructor': - pass + message = 'Thank You for Registering on this platform. \n \ + Since you have ask for Instructor Profile, \n \ + we will get back to you soon after verifying your \n \ + profile. \ + If you don\'t get any response within 3days, \ + Please contact us at ' + send_mail( + 'Welcome to FOSSEE', message, EMAIL_HOST_USER, + [request.user.email], fail_silently=False + ) + #Send a mail to admin as well as a notification. else: - pass + message = 'Thank You for Registering on this platform.\n \ + Rules. \n \ + If you face any issue during your session please contact \ + fossee.' + send_mail( + 'Welcome to FOSSEE', message, EMAIL_HOST_USER, + [request.user.email], fail_silently=False + ) elif call_on == 'Booking': pass -- cgit From 5e4d54c0f67bf0cb6f90202997a47b914af6beb3 Mon Sep 17 00:00:00 2001 From: Akshen Doke Date: Thu, 9 Mar 2017 11:35:09 +0530 Subject: handle Registeration Failure --- .../templates/workshop_app/registeration_error.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 workshop_app/templates/workshop_app/registeration_error.html (limited to 'workshop_app') diff --git a/workshop_app/templates/workshop_app/registeration_error.html b/workshop_app/templates/workshop_app/registeration_error.html new file mode 100644 index 0000000..7e2c9d8 --- /dev/null +++ b/workshop_app/templates/workshop_app/registeration_error.html @@ -0,0 +1,13 @@ +{% extends 'workshop_app/base.html' %} + +{% block title %} + Registeration Error +{% endblock %} + +{% block content %} +
+
+

Error Occurred While registration

+

Please try to register again using different username or email and see to it that you fill all the fields.

+
+ {% endblock %} \ No newline at end of file -- cgit From f751cd3c07619d8ee1e5b96c23b19cfae2005c0f Mon Sep 17 00:00:00 2001 From: Akshen Doke Date: Thu, 9 Mar 2017 11:37:06 +0530 Subject: Instructor Creates a Workshop The Instructor Creates a Workshop which is displayed in the /manage template irrespective of who is the Instructor --- workshop_app/forms.py | 4 +++- workshop_app/models.py | 6 ++++-- workshop_app/templates/workshop_app/manage.html | 1 - workshop_app/views.py | 17 +++++++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'workshop_app') diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 420181e..a7f3fa1 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -129,4 +129,6 @@ class CreateWorkshop(forms.ModelForm): class Meta: model = Workshop - fields = ['workshop_title', 'date', 'start_time', 'end_time'] \ No newline at end of file + fields = ['workshop_title', 'date', 'start_time', 'end_time'] + + diff --git a/workshop_app/models.py b/workshop_app/models.py index 2735069..8fe7d3a 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -32,7 +32,9 @@ class Profile(models.Model): position = models.CharField(max_length=32, choices=position_choices) def __str__(self): - return u"{0} {1} | {2} ".format(self.user.first_name, + return u"id: {0}| {1} {2} | {3} ".format( + self.user.id, + self.user.first_name, self.user.last_name, self.user.email ) @@ -54,7 +56,7 @@ class Workshop(models.Model): """Instructor Creates workshop based on Courses available""" - workshop_creator = models.ForeignKey(Profile, on_delete=models.CASCADE) + workshop_creator = models.ForeignKey(User, on_delete=models.CASCADE) workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE,\ help_text='Select the course you would like to create a workshop for') date = models.DateField() diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html index 4a399a1..b2404ed 100644 --- a/workshop_app/templates/workshop_app/manage.html +++ b/workshop_app/templates/workshop_app/manage.html @@ -28,7 +28,6 @@ {{ w.end_time }}
{{ w.workshop_creator }}
{{ w.workshop_title }} - {{ w.status }} {% endfor %} diff --git a/workshop_app/views.py b/workshop_app/views.py index f32e4a1..e20a742 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -22,6 +22,13 @@ from workshop_portal.settings import ( def index(request): '''Landing Page''' + + user = request.user + if user.is_authenticated(): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/book/') + return render(request, "workshop_app/index.html") def is_instructor(user): @@ -158,11 +165,17 @@ def create_workshop(request): '''Instructor creates workshops''' user = request.user + #profile = User.objects.get(user_id=user.id) + print user.id if is_instructor(user): if request.method == 'POST': form = CreateWorkshop(request.POST) if form.is_valid(): - form.save() + form_data = form.save(commit=False) + #form_data.profile_id = profile.id + form_data.workshop_creator = user + form_data.workshop_creator.save() + form_data.save() return redirect('/manage/') else: form = CreateWorkshop() @@ -223,7 +236,7 @@ def send_email(request, call_on, user_position=None): Since you have ask for Instructor Profile, \n \ we will get back to you soon after verifying your \n \ profile. \ - If you don\'t get any response within 3days, \ + In case if you don\'t get any response within 3days, \ Please contact us at ' send_mail( 'Welcome to FOSSEE', message, EMAIL_HOST_USER, -- cgit From 55585b6864e128dfd4fae5ae391373abf96c5ce5 Mon Sep 17 00:00:00 2001 From: Akshen Doke Date: Thu, 30 Mar 2017 10:54:05 +0530 Subject: Recurrence done Booking ToDo --- workshop_app/forms.py | 11 ++- workshop_app/models.py | 40 +++++++--- workshop_app/templates/workshop_app/base.html | 1 + workshop_app/templates/workshop_app/booking.html | 57 ++++++++++++++ .../templates/workshop_app/create_workshop.html | 4 + workshop_app/templates/workshop_app/manage.html | 73 ++++++++++++++--- workshop_app/views.py | 91 +++++++++++++++++++--- 7 files changed, 243 insertions(+), 34 deletions(-) (limited to 'workshop_app') diff --git a/workshop_app/forms.py b/workshop_app/forms.py index a7f3fa1..eb74a99 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -1,6 +1,11 @@ from django import forms from .models import Profile, Course, Workshop -from string import punctuation, digits, letters +from string import punctuation, digits +try: + from string import letters +except: + from string import ascii_letters as letters + from django.contrib.auth.models import User from django.contrib.auth import authenticate @@ -129,6 +134,6 @@ class CreateWorkshop(forms.ModelForm): class Meta: model = Workshop - fields = ['workshop_title', 'date', 'start_time', 'end_time'] - + fields = ['workshop_title', 'recurrences'] + diff --git a/workshop_app/models.py b/workshop_app/models.py index 8fe7d3a..a16c6a3 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -2,14 +2,17 @@ from django.db import models from django.contrib.auth.models import User from django.core.validators import RegexValidator - +from recurrence.fields import RecurrenceField position_choices = ( ("coordinator", "Coordinator"), ("instructor", "Instructor") ) - +status_choices = ( + ("pending", "Pending"), + ("confirm", "Confirm") + ) def has_profile(user): """ check if user has profile """ @@ -41,7 +44,8 @@ class Profile(models.Model): class Course(models.Model): - """"Admin creates courses which can be used by the instructor to create workshops. + """"Admin creates courses which can be used by the instructor + to create workshops. """ course_name = models.CharField(max_length=120) @@ -56,13 +60,29 @@ class Workshop(models.Model): """Instructor Creates workshop based on Courses available""" - workshop_creator = models.ForeignKey(User, on_delete=models.CASCADE) - workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE,\ - help_text='Select the course you would like to create a workshop for') - date = models.DateField() - start_time = models.TimeField() - end_time = models.TimeField() + workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE) + workshop_title = models.ForeignKey( + Course, on_delete=models.CASCADE,\ + help_text='Select the course you \ + would like to create a workshop for' + ) + + recurrences = RecurrenceField() #status = models.BooleanField() Book, Pending, Booked def __str__(self): - return u"{0} | {1}".format(self.workshop_title, self.date) + return u"{0} | {1} ".format(self.workshop_title, self.workshop_instructor) + + +# class completed_Workshop(models.Model): +# """ +# Contains Data of Booked/Completed Workshops +# """ + +# workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE) +# workshop_coordinator = models.ForeignKey(User) +# status = models.CharField(max_length=32, choices=status_choices) +# workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE) + + + diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html index cebab31..9971dd4 100644 --- a/workshop_app/templates/workshop_app/base.html +++ b/workshop_app/templates/workshop_app/base.html @@ -17,6 +17,7 @@ + {% block extra %} {% endblock %} diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html index 01cd609..4657b4a 100644 --- a/workshop_app/templates/workshop_app/booking.html +++ b/workshop_app/templates/workshop_app/booking.html @@ -4,6 +4,10 @@ Booking {% endblock %} +{% block extra %} + +{% endblock %} + {% block header %} +{% endblock %} + +{% block content %} +
+
+ + + + + + + + + {% csrf_token %} + {% for workshop in workshop_details %} + + + + + + + + + {% endfor %} +
Instructor NameCourse NameCourse DayBooking
{{ workshop.1.0 }}{{ workshop.1.1 }}{{ workshop.0 }}
+
+ +
+ +
+ {% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html index 93de011..e643594 100644 --- a/workshop_app/templates/workshop_app/create_workshop.html +++ b/workshop_app/templates/workshop_app/create_workshop.html @@ -40,7 +40,11 @@
{% csrf_token %} +
+ {{ form.media }} {{ form.as_p }} + +
diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html index b2404ed..3afca6b 100644 --- a/workshop_app/templates/workshop_app/manage.html +++ b/workshop_app/templates/workshop_app/manage.html @@ -20,15 +20,68 @@ {% block content %} -
- {% csrf_token %} - {% for w in workshop_details %} - {{ w.date }}
- {{ w.start_time }}
- {{ w.end_time }}
- {{ w.workshop_creator }}
- {{ w.workshop_title }} - {% endfor %} -
+ {% if workshop_occurence_list %} +
+ + + + + + + + + + {% csrf_token %} + {% for workshop in workshop_occurence_list %} + {% for w in workshop %} + + + + + + + + {% endfor %} + {% endfor %} +
Instructor NameCourse NameCourse DayBooking
{{ w.user }}{{ w.workshop }}{{ w.date }}
+
+ +
+ +
+ + {% else %} +
+
+

Welcome Instructor

+

Please navigate to View Course list and depending upon + your expertise and availability create a workshop by going to + Create Event.

+ +
+
+ {% endif %} {% endblock %} \ No newline at end of file diff --git a/workshop_app/views.py b/workshop_app/views.py index e20a742..1fe5084 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -5,6 +5,7 @@ from .forms import ( ) from .models import Profile, User, has_profile, Workshop, Course from django.template import RequestContext +from datetime import datetime, date from django.contrib.auth import login, logout, authenticate from django.contrib.auth.decorators import login_required from django.contrib import messages @@ -12,6 +13,8 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.mail import send_mail from django.shortcuts import render, redirect from django.db import IntegrityError +from collections import OrderedDict +from dateutil.parser import parse from workshop_portal.settings import ( EMAIL_HOST, EMAIL_PORT, @@ -99,7 +102,44 @@ def book(request): if user.is_authenticated(): if user.groups.filter(name='instructor').count() > 0: return redirect('/manage/') - return render(request, "workshop_app/booking.html") + workshop_details = Workshop.objects.all() + workshop_occurence = {} + for workshops in workshop_details: + dates = workshops.recurrences.between( + datetime(2017, 3, 12, 0, 0, 0), + datetime(2017, 12, 31, 0, 0, 0), #Needs to be changed + inc=True + ) + + for d in range(len(dates)): + workshop_occurence[dates[d].strftime("%d-%m-%Y")] = [ + workshops.workshop_instructor, + workshops.workshop_title + ] + + # workshop_occurence = OrderedDict(sorted(workshop_occurence.items())) + workshop_occurence = list(workshop_occurence.items()) + + + + + #Show upto 3 Workshops per page + paginator = Paginator(workshop_occurence, 6) + page = request.GET.get('page') + try: + workshop_occurences = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + workshop_occurences = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + workshop_occurences = paginator.page(paginator.num_pages) + + return render( + request, "workshop_app/booking.html", + {"workshop_details": workshop_occurences} + ) + else: return redirect('/login/') @@ -107,13 +147,42 @@ def book(request): def manage(request): user = request.user if user.is_authenticated(): - #print user.id, user - if user.groups.filter(name='instructor').count() > 0: #Move user to the group via admin - workshop_details = Workshop.objects.all() + #Move user to the group via admin + if user.groups.filter(name='instructor').count() > 0: + try: + workshop_details = Workshop.objects.get(workshop_instructor=user) + workshop_occurence_list = workshop_details.recurrences.between( + datetime(2017, 3, 12, 0, 0, 0), + datetime(2017, 12, 31, 0, 0, 0), + inc=True + ) + for i in range(len(workshop_occurence_list)): + workshop_occurence_list[i] = [{ + "user": str(user), + "workshop": workshop_details, + "date": workshop_occurence_list[i].date + }] + + + #Show upto 3 Workshops per page + paginator = Paginator(workshop_occurence_list, 3) + page = request.GET.get('page') + try: + workshops = paginator.page(page) + except PageNotAnInteger: + #If page is not an integer, deliver first page. + workshops = paginator.page(1) + except EmptyPage: + #If page is out of range(e.g 999999), deliver last page. + workshops = paginator.page(paginator.num_pages) + + except: + workshops = None return render( - request, "workshop_app/manage.html", - {"workshop_details": workshop_details} - ) + request, "workshop_app/manage.html", + {"workshop_occurence_list": workshops} + ) + return redirect('/book/') else: return redirect('/login/') @@ -165,16 +234,16 @@ def create_workshop(request): '''Instructor creates workshops''' user = request.user - #profile = User.objects.get(user_id=user.id) - print user.id + + if is_instructor(user): if request.method == 'POST': form = CreateWorkshop(request.POST) if form.is_valid(): form_data = form.save(commit=False) #form_data.profile_id = profile.id - form_data.workshop_creator = user - form_data.workshop_creator.save() + form_data.workshop_instructor = user + form_data.workshop_instructor.save() form_data.save() return redirect('/manage/') else: -- cgit From b9940ff15c335a4c7fc7f59868377ed271d021db Mon Sep 17 00:00:00 2001 From: Akshen Doke Date: Mon, 3 Apr 2017 16:44:51 +0530 Subject: Created RequestWorkshop --- workshop_app/forms.py | 8 +- workshop_app/models.py | 39 ++++-- workshop_app/send_mails.py | 55 ++++++++ workshop_app/static/workshop_app/img/img1.png | Bin 0 -> 19947 bytes workshop_app/static/workshop_app/img/img2.png | Bin 0 -> 14023 bytes workshop_app/templates/workshop_app/base.html | 2 +- workshop_app/templates/workshop_app/booking.html | 34 ++++- .../templates/workshop_app/create_workshop.html | 11 +- workshop_app/templates/workshop_app/index.html | 20 +++ .../templates/workshop_app/view_course_list.html | 1 + workshop_app/views.py | 142 +++++++++++---------- 11 files changed, 220 insertions(+), 92 deletions(-) create mode 100644 workshop_app/send_mails.py create mode 100644 workshop_app/static/workshop_app/img/img1.png create mode 100644 workshop_app/static/workshop_app/img/img2.png (limited to 'workshop_app') diff --git a/workshop_app/forms.py b/workshop_app/forms.py index eb74a99..fa0834c 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -40,7 +40,9 @@ class UserRegistrationForm(forms.Form): help_text='Institute/Organization') department = forms.CharField(max_length=64, help_text='Department you work \ study at') - position = forms.ChoiceField(help_text='If you are an instructor please \ + position = forms.ChoiceField(help_text='Instructors, please wait \ + for our admin approval, if your instructor \ + account is not activated in 7 days, please\ mail us at python[at]fossee[dot]in', choices=position_choices ) @@ -132,6 +134,10 @@ class ProfileForm(forms.ModelForm): class CreateWorkshop(forms.ModelForm): """Instructors can create Workshops based on the courses available.""" + def __init__( self, *args, **kwargs ): + super(CreateWorkshop, self).__init__( *args, **kwargs ) + self.fields['recurrences'].label = " " #the trick to hide field :) + class Meta: model = Workshop fields = ['workshop_title', 'recurrences'] diff --git a/workshop_app/models.py b/workshop_app/models.py index a16c6a3..096ce5d 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -50,12 +50,13 @@ class Course(models.Model): course_name = models.CharField(max_length=120) course_description = models.TextField() - course_duration = models.CharField(max_length=12) + course_duration = models.CharField(max_length=32) def __str__(self): return u"{0} {1}".format(self.course_name, self.course_duration) + class Workshop(models.Model): """Instructor Creates workshop based on Courses available""" @@ -63,26 +64,38 @@ class Workshop(models.Model): workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE) workshop_title = models.ForeignKey( Course, on_delete=models.CASCADE,\ - help_text='Select the course you \ - would like to create a workshop for' + help_text='Select the course for which \ + you would like to create a workshop.' ) - + #For recurring workshops source: django-recurrence recurrences = RecurrenceField() - #status = models.BooleanField() Book, Pending, Booked def __str__(self): return u"{0} | {1} ".format(self.workshop_title, self.workshop_instructor) -# class completed_Workshop(models.Model): -# """ -# Contains Data of Booked/Completed Workshops -# """ +class RequestedWorkshop(models.Model): + """ + Contains Data of Booked/Completed Workshops + """ + + requested_workshop_instructor = models.ForeignKey( + User, + on_delete=models.CASCADE + ) + requested_workshop_coordinator = models.ForeignKey( + User, + related_name="%(app_label)s_%(class)s_related" + ) + status = models.CharField( + max_length=32, default="Pending", + choices=status_choices + ) + requested_workshop_title = models.ForeignKey( + Workshop, + on_delete=models.CASCADE + ) -# workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE) -# workshop_coordinator = models.ForeignKey(User) -# status = models.CharField(max_length=32, choices=status_choices) -# workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE) diff --git a/workshop_app/send_mails.py b/workshop_app/send_mails.py new file mode 100644 index 0000000..4eff778 --- /dev/null +++ b/workshop_app/send_mails.py @@ -0,0 +1,55 @@ +from django.core.mail import send_mail +from workshop_portal.settings import ( + EMAIL_HOST, + EMAIL_PORT, + EMAIL_HOST_USER, + EMAIL_HOST_PASSWORD, + EMAIL_USE_TLS + ) + +def send_email(request, call_on, user_position=None): + ''' + Email sending function while registration and + booking confirmation. + ''' + + if call_on == 'Registration': + if user_position == 'instructor': + message = 'Thank You for Registering on this platform. \n \ + Since you have ask for Instructor Profile, \n \ + we will get back to you soon after verifying your \n \ + profile. \ + In case if you don\'t get any response within 3days, \ + Please contact us at ' + send_mail( + 'Welcome to FOSSEE', message, EMAIL_HOST_USER, + [request.user.email], fail_silently=False + ) + #Send a mail to admin as well as a notification. + else: + message = 'Thank You for Registering on this platform.\n \ + Rules. \n \ If you face any issue during \ + your session please contact fossee.' + send_mail( + 'Welcome to FOSSEE', message, EMAIL_HOST_USER, + [request.user.email], fail_silently=False + ) + + elif call_on == 'Booking': + if user_position == 'instructor': + message = 'You got a workshop booking request \ + from user name ' + send_mail( + 'Python Workshop Booking | FOSSEE', message, EMAIL_HOST_USER, + [request.user.email], fail_silently=False + ) + + else: + message = 'Thank You for Booking on this platform.\n \ + Rules to be added \ + If you face any issue during your session please contact \ + fossee.' + send_mail( + 'Python Workshop Booking | FOSSEE', message, EMAIL_HOST_USER, + [request.user.email], fail_silently=False + ) diff --git a/workshop_app/static/workshop_app/img/img1.png b/workshop_app/static/workshop_app/img/img1.png new file mode 100644 index 0000000..07dc07f Binary files /dev/null and b/workshop_app/static/workshop_app/img/img1.png differ diff --git a/workshop_app/static/workshop_app/img/img2.png b/workshop_app/static/workshop_app/img/img2.png new file mode 100644 index 0000000..0e47923 Binary files /dev/null and b/workshop_app/static/workshop_app/img/img2.png differ diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html index 9971dd4..fef8840 100644 --- a/workshop_app/templates/workshop_app/base.html +++ b/workshop_app/templates/workshop_app/base.html @@ -21,7 +21,7 @@ {% block extra %} {% endblock %} - + {% block header %}
+
+
diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html index 3afca6b..eab3f52 100644 --- a/workshop_app/templates/workshop_app/manage.html +++ b/workshop_app/templates/workshop_app/manage.html @@ -9,6 +9,7 @@
+
diff --git a/workshop_app/templates/workshop_app/my_workshops.html b/workshop_app/templates/workshop_app/my_workshops.html new file mode 100644 index 0000000..77cd561 --- /dev/null +++ b/workshop_app/templates/workshop_app/my_workshops.html @@ -0,0 +1,143 @@ +{% extends "workshop_app/base.html" %} + +{% block title %} + My Workshops +{% endblock %} + +{% block extra %} + + + + + +{% endblock %} + + +{% block header %} + +{% endblock %} + + +{% block content %} +{% if workshop_occurences %} +
+ + + + {% if request.user.profile.position == 'instructor' %} + + {% else %} + + {% endif %} + + + + + + {% csrf_token %} + {% for workshop in workshop_occurences %} + + + {% if request.user.profile.position == 'instructor' %} + + {% else %} + + {% endif %} + + + {% if workshop.status == 'Pending' %} + + {% elif workshop.status == 'ACCEPTED' %} + + {% else %} + + {% endif %} + {% if request.user.profile.position == 'instructor' %} + + {% endif %} + + + + {% endfor %} +
Coordinator NameInstructor NameCourse NameCourse DayStatus
{{ workshop.requested_workshop_coordinator }}{{ workshop.requested_workshop_instructor }}{{ workshop.requested_workshop_title }}{{ workshop.requested_workshop_date }}{{ workshop.status }}{{ workshop.status }}{{ workshop.status }}
+
+ + +
+ +
+ +{% else %} +
+
+

Welcome Instructor

+

Your workshop related information will be shown here, Please navigate to View Course list and depending upon + your expertise and availability create a workshop by going to + Create Event.

+
+
+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/workshop_app/templates/workshop_app/view_course_list.html b/workshop_app/templates/workshop_app/view_course_list.html index e5c10e6..d1fb343 100644 --- a/workshop_app/templates/workshop_app/view_course_list.html +++ b/workshop_app/templates/workshop_app/view_course_list.html @@ -13,7 +13,9 @@
+