SHARE
TWEET

Untitled

a guest Oct 4th, 2017 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.contrib.auth import authenticate, login, logout
  2. from django.contrib.auth.decorators import login_required
  3. from django.shortcuts import render, redirect
  4. from .models import *
  5. # Create your views here.
  6. def index(request):
  7.     return render(request,'app/index.html')
  8.  
  9. def teachers(request):
  10.     teachers = Teacher.objects.all()
  11.     return render(request,'app/teachers.html', {'teachers': teachers})
  12.  
  13. def students(request):
  14.     students = Student.objects.all()
  15.     return render(request,'app/students.html', {'students': students})
  16.  
  17. def departments(request):
  18.     departments = Departments.objects.all()
  19.     return render(request,'app/departments.html', {'departments': departments})
  20.  
  21. def attendance(request):
  22.     attendance = Attendance.objects.all()
  23.     return render(request,'app/attendance.html', {'attendance': attendance})
  24.  
  25. def login_form(request):
  26.     return render(request,'app/login_form.html')
  27.  
  28. def login_action(request):
  29.     # authenticte the user
  30.     username = request.POST.get('username')
  31.     password = request.POST.get('password')
  32.  
  33.     user = authenticate(request, username=username, password=password)
  34.  
  35.     if user is not None:
  36.         login(request,user)
  37.         if user.appuser.user_type == 'TEACHER':
  38.             return redirect('/teacher_dashboard/')
  39.         else:
  40.             return redirect('/student_dashboard/')
  41.     else:
  42.         return redirect('/login_form/')
  43.  
  44.  
  45. def logout_action(request):
  46. #logout here
  47.     logout(request)
  48.  
  49.     return redirect('/')
  50.  
  51.  
  52. def student_register_form(request):
  53.     return render(request,'app/student_register_form.html')
  54.  
  55.  
  56. def student_register_action(request):
  57.     # authenticte the user
  58.     username = request.POST.get('username')
  59.     password = request.POST.get('password')
  60.     first_name = request.POST.get('first_name')
  61.     last_name = request.POST.get('last_name')
  62.     email = request.POST.get('email')
  63.     sem = request.POST.get('sem')
  64.     dept = request.POST.get('dept')
  65.  
  66.  
  67.     user = User.objects.create_user(
  68.             username=username,
  69.             first_name=first_name,
  70.             last_name=last_name,
  71.             password=password,
  72.             email=email)
  73.  
  74.     app_user = AppUser.objects.create(
  75.             user_type='STUDENT',
  76.             user=user)
  77.  
  78.     student = Student.objects.create(
  79.             app_user=app_user,
  80.             sem=sem,
  81.             department=dept)
  82.  
  83.  
  84.     return redirect('/students/')
  85.  
  86.  
  87. def teacher_register_form(request):
  88.     return render(request,'app/teacher_register_form.html')
  89.  
  90.  
  91. def teacher_register_action(request):
  92.     # authenticte the user
  93.     username = request.POST.get('username')
  94.     password = request.POST.get('password')
  95.     first_name = request.POST.get('first_name')
  96.     last_name = request.POST.get('last_name')
  97.     email = request.POST.get('email')
  98.     specialization = request.POST.get('specialization')
  99.     dept = request.POST.get('dept')
  100.  
  101.     user = User.objects.create_user(
  102.             username=username,
  103.             first_name=first_name,
  104.             last_name=last_name,
  105.             password=password,
  106.             email=email)
  107.  
  108.     app_user = AppUser.objects.create(
  109.             user_type='TEACHER',
  110.             user=user)
  111.  
  112.     teacher = Teacher.objects.create(
  113.             app_user=app_user,
  114.             specialization=specialization,
  115.             department=dept)
  116.  
  117.     return redirect('/teachers/')
  118.  
  119. @login_required(login_url='/login_form/')
  120. def teacher_dashboard(request):
  121.     if request.user.appuser.user_type != 'TEACHER':
  122.         return redirect('/')
  123.     return render(request,'app/teacher_dashboard.html')
  124.  
  125. @login_required(login_url='/login_form/')
  126. def student_dashboard(request):
  127.     if request.user.appuser.user_type != 'STUDENT':
  128.         return redirect('/')
  129.     return render(request,'app/student_dashboard.html')
  130.  
  131.  
  132.  
  133. def student_info(request):
  134.     return render(request,'app/student_info.html')
  135.  
  136. def student_info_action(request):
  137.     return redirect('/student_info/')
  138.  
  139.  
  140. def std_attendance(request):
  141.     return render(request,'app/std_attendance.html')
  142.  
  143. def std_attendance_action(request):
  144.     return redirect('/std_attendance/')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top