summaryrefslogtreecommitdiff
path: root/workshop_app/views.py
diff options
context:
space:
mode:
authorAkshen Doke2017-03-07 11:26:04 +0530
committerAkshen2017-05-19 15:30:31 +0530
commit2a0875890fd64e6b3b86a7e08378eea36bcf7ce4 (patch)
tree2c08e13142c7e165912e60662dfdc1d0e95f492b /workshop_app/views.py
parent057e1ded6560f03ed5a66885eef452bf3317b645 (diff)
downloadworkshop_booking-2a0875890fd64e6b3b86a7e08378eea36bcf7ce4.tar.gz
workshop_booking-2a0875890fd64e6b3b86a7e08378eea36bcf7ce4.tar.bz2
workshop_booking-2a0875890fd64e6b3b86a7e08378eea36bcf7ce4.zip
Phone Number added, email verification todo
Diffstat (limited to 'workshop_app/views.py')
-rw-r--r--workshop_app/views.py45
1 files changed, 35 insertions, 10 deletions
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
+