diff options
-rw-r--r-- | workshop_app/forms.py | 24 | ||||
-rw-r--r-- | workshop_app/models.py | 14 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/booking.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/create_workshop.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/edit_profile.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/index.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/login.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/logout.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/manage.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/profile_updated.html | 5 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/register.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/view_course_details.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/view_course_list.html | 2 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/view_profile.html | 6 | ||||
-rw-r--r-- | workshop_app/views.py | 45 | ||||
-rw-r--r-- | workshop_portal/settings.py | 3 |
16 files changed, 83 insertions, 34 deletions
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" %} <!DOCTYPE html> <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 %} <nav class="navbar navbar-inverse"> diff --git a/workshop_app/templates/workshop_app/profile_updated.html b/workshop_app/templates/workshop_app/profile_updated.html index e9a0d54..2974aaf 100644 --- a/workshop_app/templates/workshop_app/profile_updated.html +++ b/workshop_app/templates/workshop_app/profile_updated.html @@ -1,4 +1,4 @@ -{% extends "./base.html" %} +{% extends "workshop_app/base.html" %} {% block title %} Profile Changing @@ -22,7 +22,6 @@ {% endblock %} {% block content %} -{% dinesh akshen %} <h3>Your Profile has changed {{ user.first_name }}</h3> -{% endblock content %} +{% endblock %} diff --git a/workshop_app/templates/workshop_app/register.html b/workshop_app/templates/workshop_app/register.html index fdb8bf8..3009048 100644 --- a/workshop_app/templates/workshop_app/register.html +++ b/workshop_app/templates/workshop_app/register.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} Register diff --git a/workshop_app/templates/workshop_app/view_course_details.html b/workshop_app/templates/workshop_app/view_course_details.html index 58004da..aca59a0 100644 --- a/workshop_app/templates/workshop_app/view_course_details.html +++ b/workshop_app/templates/workshop_app/view_course_details.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} View Course Details diff --git a/workshop_app/templates/workshop_app/view_course_list.html b/workshop_app/templates/workshop_app/view_course_list.html index 4348a0d..68c3009 100644 --- a/workshop_app/templates/workshop_app/view_course_list.html +++ b/workshop_app/templates/workshop_app/view_course_list.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} View Course List diff --git a/workshop_app/templates/workshop_app/view_profile.html b/workshop_app/templates/workshop_app/view_profile.html index 546af88..00bd210 100644 --- a/workshop_app/templates/workshop_app/view_profile.html +++ b/workshop_app/templates/workshop_app/view_profile.html @@ -1,4 +1,4 @@ -{% extends './base.html' %} +{% extends 'workshop_app/base.html' %} {% block title %} View Profile @@ -43,6 +43,10 @@ <th><label for="id_institute"><h5>{{ user.profile.institute }}</h5></label></th> </tr> <tr> + <th><label for="id_phone_number"><h5>Phone Number:</h5></label></th> + <th><label for="id_phone_number"><h5>{{ user.profile.phone_number }}</h5></label></th> + </tr> + <tr> <th><label for="id_department"><h5>Department:</h5></label></th> <th><label for="id_department"><h5>{{ user.profile.department }}</h5></label></th> </tr> diff --git a/workshop_app/views.py b/workshop_app/views.py index 2cb805e..fab6e8d 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render, redirect + from .forms import UserRegistrationForm, UserLoginForm, ProfileForm, CreateWorkshop from .models import Profile, User, has_profile, Workshop, Course from django.template import RequestContext @@ -6,7 +6,9 @@ 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.core.mail import send_mail +from django.shortcuts import render, redirect +from django.db import IntegrityError def index(request): @@ -50,13 +52,21 @@ def user_register(request): 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('/view_profile/') + try: + data = form.cleaned_data + username, password = form.save() + new_user = authenticate(username=username, password=password) + login(request, new_user) + user_position = request.user.profile.position + send_email(request, call_on='Registration', + user_position=user_position) + return redirect('/view_profile/') + except IntegrityError as e: + 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}) @@ -76,7 +86,7 @@ def manage(request): user = request.user if user.is_authenticated(): print user.id, user - if user.groups.filter(name='instructor').count() > 0: + 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 redirect('/book/') @@ -173,4 +183,19 @@ def view_course_details(request): return redirect('/') else: - return redirect('/book/')
\ No newline at end of file + return redirect('/book/') + +def send_email(request, call_on, user_position=None): + ''' + Email sending function + ''' + + if call_on == 'Registration': + if user_position == 'instructor': + pass + else: + pass + + elif call_on == 'Booking': + pass + diff --git a/workshop_portal/settings.py b/workshop_portal/settings.py index e0c00d9..e804406 100644 --- a/workshop_portal/settings.py +++ b/workshop_portal/settings.py @@ -41,7 +41,7 @@ INSTALLED_APPS = [ ] -MIDDLEWARE = [ +MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -49,6 +49,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + ] ROOT_URLCONF = 'workshop_portal.urls' |