Esempio n. 1
0
def create_a_class(request):
	#Checks user group rights
	if not request.user.groups.filter(name='Admin') and not request.user.groups.filter(name = 'Teacher'):
		return HttpResponse("You do not have permission to access this page.")
	#Checks authentication
	elif request.user.is_authenticated():
		#If authenticated, checks method type
		if request.method == 'POST':
			myclass_name = request.POST['class_name']
			myclass_number = request.POST['class_number']
			myclass_semester = request.POST['class_semester']
			creating_teacher = request.user.username
			new_class = MyClass(class_name = myclass_name, class_number = myclass_number, semester = myclass_semester, teacher = creating_teacher)
			new_class.save()				

			#Tries to create new roster
			try:
				newroster = ClassRoster(in_class = new_class, class_name = new_class.class_name, class_number = new_class.class_number, teacher=request.user.username) 
				newroster.save()
			except:
				return HttpResponse("...")

			#Updates teacher profile to add new class
			teacher_update = user_info.objects.get(username=request.user.username)
			teacher_update.class_list.add(new_class)
			teacher_update.save()

			return render (request, "create_a_class.html", {"info": user_info.objects.all()})			
		else:
			return render (request, "create_a_class.html", {"info": user_info.objects.all()})
	else:
		return redirect('register')
Esempio n. 2
0
def auth_myuser(request):
	if not request.user.groups.filter(name='Admin'):	
		return HttpResponse("You do not have permission to access this page.")
	elif request.user.is_authenticated():
		if request.method == 'POST':
			myaction = request.POST['action']
			myname = request.POST['user']
			edit_user = User.objects.get(username=myname)
			moreinfo = user_info.objects.get(username=myname)
			if myaction == 'remove_teacher':
				mygroup = Group.objects.get(name='Teacher')
				edit_user.groups.remove(mygroup)	
				edit_user.save()
				moreinfo.authenticate = False
				moreinfo.save()
				return render (request, "authenticate.html", {"info": user_info.objects.all()})
			elif myaction == 'add_teacher':
				mygroup = Group.objects.get(name='Teacher')
				edit_user.groups.add(mygroup)	
				edit_user.save()
				moreinfo.authenticate = True
				newclass = MyClass(class_name = moreinfo.init_class_name, class_number = moreinfo.init_class_number, semester = moreinfo.init_class_semester, teacher = moreinfo.username, authenticate = True)
				newclass.save()
				newroster = ClassRoster(in_class = newclass, class_name = newclass.class_name, class_number = newclass.class_number, teacher=moreinfo.username) 
				newroster.save()
				newroster.student.add(moreinfo)
				moreinfo.save()
				
				date = datetime.date.today()
				title = "Account Approved."
				message = "Your account has been approved and is now operable."
				new_inbox = MyInbox(sent_by = "ADMIN", received_by = moreinfo, date = date, title = title, message = message)
				new_inbox.save()

				moreinfo.class_list.add(newclass)

				return render (request, "authenticate.html", {"info": user_info.objects.all()})
			else:
				return HttpResponse("Hi")
		else:
			return render (request, "authenticate.html", {"info": user_info.objects.all()})
	else:
		return redirect('register')