Пример #1
0
def update_xml(request):
	print "update_xml called"
	#for field in request.META:
	#	print field
	if request.is_ajax():
		#print "ajax method found"
		if request.method == 'GET':
			#print "ajax method called"
			#handle AJAX request here
			#parse input commands

			inputParam = request.GET
			c_id = inputParam.get('c_id', '1')
			q_id = inputParam.get('q_id', '1')
			action = inputParam.get('action', '')
			args = []
			for i in range(1, len(inputParam)-3):
				args.append(inputParam.get('str'+str(i), ''))
			user = request.user
			
			if action == 'sub_course':
				util.new_course(args[0], args[1], args[2], user)
			if action == 'sub_quest':
				util.new_question(c_id, args[0])
			if action == 'sub_resp':
				util.new_response(c_id, q_id, user.username, args[0])

			#args[0] is question text, args[1] is true/false for anonymous
			if action == 'sub_student_quest':
				util.new_student_question(c_id, user.username, args[0], args[1])
			#args[0] for upvote, args[1] for star and answered is student question id
			if action == 'upvote':
				util.add_upvote(c_id, args[0])
			if action == 'star':
				util.set_star(c_id, args[1], args[0])
			if action == 'answered':
				util.set_answered(c_id, args[1], args[0])
			if action == 'reset':
				util.clear_all()
			if action == 'set_open':
				print "set open", c_id, q_id, args[0]
				util.set_open(c_id, q_id, args[0])
			if action == 'set_hidden':
				print "set hidden", c_id, q_id, args[0]
				util.set_hidden(c_id, q_id, args[0])
			if action == 'edit_course':
				util.edit_course(c_id, args[0], args[1], args[2])
			if action == 'enroll':
				util.enroll_student(args[0], user)
			if action == 'unenroll':
				util.unenroll_student(c_id, user)
			if action == 'make_prof':
				util.make_prof(c_id, args[0])
			if action == 'remove_prof':
				util.remove_prof(c_id, args[0])


			
			data = serializers.serialize('xml', models.Response.objects.filter(c_id=c_id).filter(q_id=q_id))
			
			if action == 'get_course':
				data = serializers.serialize('xml', models.Course.objects.filter(pk=c_id))
			if (action == 'get_question' or action == 'set_open' or action == 'set_hidden'):
				data = serializers.serialize('xml', models.Question.objects.filter(c_id=c_id).filter(pk=q_id))
			if action == 'all_questions':
				data = serializers.serialize('xml', models.Question.objects.filter(c_id=c_id))
			if action == 'search':
				strs = args[0].split()
				searched = models.Course.objects.none()
				for s in strs:
					search_name = models.Course.objects.filter(course_name__contains=s)
					search_term = models.Course.objects.filter(course_term__contains=s)
					search_year = models.Course.objects.none()
					if s.isdigit():
						search_year = models.Course.objects.filter(year=int(s))
					searched = searched | search_name | search_term | search_year
				data = serializers.serialize('xml', searched)
			if action == 'search_duplicate':
				searched = models.Course.objects.filter(course_name__contains=args[0], course_term=args[1], year=int(args[2]))
				data = serializers.serialize('xml', searched)
			if action == 'search_duplicate_edit':
				searched = models.Course.objects.filter(course_name__contains=args[0], course_term=args[1], year=int(args[2]))
				data = serializers.serialize('xml', searched)
			if action == 'user_get_course_p':
				groups = user.groups.all()
				courses = models.Course.objects.none();
				for g in groups:
					if g.id % 2 == 0:
						courses = courses | models.Course.objects.filter(professors=g)
				data = serializers.serialize('xml', courses)
			if action == 'user_get_course_s':
				groups = user.groups.all()
				courses = models.Course.objects.none();
				for g in groups:
					if g.id % 2 == 1:
						courses = courses | models.Course.objects.filter(students=g)
				data = serializers.serialize('xml', courses)

			if action == 'student_questions':
				info = models.Student_Question.objects.filter(c_id=c_id).order_by('-pub_date')
				data = serializers.serialize('xml', info)
			print action
			if (action == 'get_results' or action == 'fill_chart'):
				print 'get_results called'
				data = serializers.serialize('xml', util.get_result(c_id, q_id))

		#	print data
			return HttpResponse(data, content_type='application/xml')

	#need to replace this file
	fp = open('./milestone/templates/milestone.html')
	t = template.Template(fp.read())
	fp.close()
	c = template.Context()
	html = t.render(c)
	return HttpResponse(html)
Пример #2
0
def update_xml(request):
	print "update_xml called"
	#for field in request.META:
	#	print field
	if request.is_ajax():
		#print "ajax method found"
		if request.method == 'GET':
			#print "ajax method called"
			#handle AJAX request here
			#parse input commands

			inputParam = request.GET
			c_id = inputParam.get('c_id', '1')
			q_id = inputParam.get('q_id', '1')
			action = inputParam.get('action', '')
			args = []
			for i in range(1, len(inputParam)-3):
				args.append(inputParam.get('str'+str(i), ''))
			user = request.user
			
			professor, student_allow, student, other, all = range(5)
			user_status = other
			if models.Course.objects.all():
				user_status = util.get_userstatus(c_id, q_id, user)
			data = serializers.serialize('xml', models.Course.objects.none())
			
			if (user_status == professor):
				if action == 'edit_course': util.edit_course(c_id, args[0], args[1], args[2])
				if action == 'sub_quest': util.new_question(c_id, args[0])
				if action == 'set_open': util.set_open(c_id, q_id, args[0])
				if action == 'set_hidden': util.set_hidden(c_id, q_id, args[0])
				if action == 'star': util.set_star(c_id, args[1], args[0])
				if action == 'answered': util.set_answered(c_id, args[1], args[0])
				if action == 'reset': util.clear_all()
				if action == 'make_prof': util.make_prof(c_id, args[0])
				if action == 'remove_prof': util.remove_prof(c_id, args[0])
				
			if (user_status == professor or user_status == student_allow):
				if action == 'get_resp': data = serializers.serialize('xml', util.get_resp(c_id,q_id))
				if (action == 'get_result' or action == 'make_pie'):
					data = serializers.serialize('xml', util.get_result(c_id, q_id))
				
			if (user_status == student_allow or user_status == student):
				if action == 'sub_resp': util.new_response(c_id, q_id, user.username, args[0])
				if action == 'sub_squest': util.new_student_question(c_id, user.username, args[0])
				if action == 'upvote': util.add_upvote(c_id, args[0], user)
				if action == 'unenroll': util.unenroll_student(c_id, user)
				
			if user_status != other:
				if action == 'get_course': data = serializers.serialize('xml', util.get_course(c_id))
				if action == 'all_quest': data = serializers.serialize('xml', util.all_quest(c_id))
				if action == 'stu_quest': data = serializers.serialize('xml', models.Student_Question.objects.filter(c_id=c_id).order_by('-pub_date'))
				if (action == 'get_quest' or action == 'set_open' or action == 'set_hidden'):
					data = serializers.serialize('xml', util.get_quest(c_id, q_id))
			
			if user_status < all:
				if action == 'sub_course' : util.new_course(args[0], args[1], args[2], user)
				if action == 'enroll': util.enroll_student(args[0], user)
				if action == 'search': data = serializers.serialize('xml', util.search(args[0]))
				if action == 'ucourse_p': data = serializers.serialize('xml', util.get_course_p(user))
				if action == 'ucourse_s': data = serializers.serialize('xml', util.get_course_s(user))
				if action == 'search_duplicate':
					searched = models.Course.objects.filter(course_name__contains=args[0], course_term=args[1], year=int(args[2]))
					data = serializers.serialize('xml', searched)
				if action == 'search_duplicate_edit':
					searched = models.Course.objects.filter(course_name__contains=args[0], course_term=args[1], year=int(args[2]))
					data = serializers.serialize('xml', searched)

			print data
			return HttpResponse(data, content_type='application/xml')

	#need to replace this file
	fp = open('./milestone/templates/milestone.html')
	t = template.Template(fp.read())
	fp.close()
	c = template.Context()
	html = t.render(c)
	return HttpResponse(html)