Пример #1
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')
Пример #2
0
def send_message_id(request, number):
	if request.user.is_authenticated():
		try:
			myuser =  user_info.objects.get(username=request.user.username)
			message = MyInbox.objects.get(id=number)
		except:
			return HttpResponse(request.user.username)
	else:
		return redirect('register')	
	if request.method == 'POST':
		send_to = user_info.objects.get(username=request.POST['send_to'])
		title = request.POST['title']
		message = request.POST.get("message")
		date =  datetime.date.today()
		
		new_inbox = MyInbox(sent_by = myuser.username, received_by = send_to, date = date, title = title, message = message)
		new_inbox.save()
	
		new_outbox = MyOutbox(sent_by = myuser, received_by = send_to.username, date = date, title = title, message = message)
		new_outbox.save()
		return render (request, 'send_message.html', {"myuser": myuser, "send_message": "Your message has been sent."})
	else:
		return render (request, 'send_message.html', {"myuser": myuser, "message": message})
Пример #3
0
def generate_inbox_message(sent_by, received_by, date, title, message):
	new_inbox = MyInbox(sent_by = sent_by, received_by = received_by, date = date, title = title, message = message)
	new_inbox.save()
Пример #4
0
def approve_student_for_class(request, string):
	if request.user.is_authenticated():
		class_num = string
		try:
			myclass = MyClass.objects.get(class_number = class_num, teacher = request.user.username) 
		except:
			return HttpResponse("This page does not exist or you do not have access to this page. Please check your url and try again.")
		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)
			auth_user = AuthUser.objects.get(student_name = moreinfo, class_name = myclass)
			if myaction == 'remove_student':
				auth_user.authorized = False
				auth_user.delete()
				
				moreinfo.class_list.remove(myclass)
				moreinfo.save()
				
				roster = ClassRoster.objects.get(in_class = myclass)
				roster.student.remove(moreinfo)
				roster.save()
				
				#deletes assignments when student is removed
				for each_assignment in Assignment.objects.all():
					if each_assignment.to_student.username == edit_user.username and each_assignment.to_class == myclass:
						each_assignment.delete()

				date = datetime.date.today()
				title = "Removed from Class " + myclass.class_number
				message = "Your have been removed from " + myclass.class_number + " by the instructor."
				new_inbox = MyInbox(sent_by = "ADMIN", received_by = moreinfo, date = date, title = title, message = message)
				new_inbox.save()

				return render (request, "approve_student_for_class.html", {"info": user_info.objects.all(), "auth": AuthUser.objects.all(), "instance_class": myclass})
			elif myaction == 'add_student':
				mygroup = Group.objects.get(name='Student')
				edit_user.groups.add(mygroup)	
				edit_user.save()
				moreinfo.authenticate = True
				auth_user.authorized = True
				moreinfo.save()
				auth_user.save()
				
				date = datetime.date.today()
				title = "Account Approved."
				message = "Your have been added to " + myclass.class_number + "."
				new_inbox = MyInbox(sent_by = "ADMIN", received_by = moreinfo, date = date, title = title, message = message)
				new_inbox.save()

				#adds assignments when student is added to class
				for each_assignment in Assignment.objects.all():
					if each_assignment.to_student.username == myclass.teacher and each_assignment.to_class == myclass:
						new_assignment_instance = Assignment(assign_date = each_assignment.assign_date, due_date = each_assignment.due_date, to_student = moreinfo, to_class = myclass, assignment_name = each_assignment.assignment_name, max_score = each_assignment.max_score, real_score = 0, retry_limit = each_assignment.retry_limit)
						new_assignment_instance.save()		
				return render (request, "approve_student_for_class.html", {"info": user_info.objects.all(), "auth": AuthUser.objects.all(), "instance_class": myclass})
			else:
				return HttpResponse("Hi")
		else:
				return render (request, "approve_student_for_class.html", {"info": user_info.objects.all(), "auth": AuthUser.objects.all(), "instance_class": myclass})
	else:
		return redirect('register')