Example #1
0
def topic_reorder(request, course_short_name):
	msg = ''
	topic_ids = request.POST['order'].split(',')
	count = 0
	for topic_id in topic_ids:
		count += 1
		if topic_id == '':
			continue
		try:
			course = Course.objects.get(short_name = course_short_name)
			topic = Topic.objects.get(id = int(topic_id))
			to = None
			try:
				to = TopicOrder.objects.get(course=course, topic=topic)
			except:
				to = TopicOrder(course=course, topic=topic, order=count)
			to.order = count
			#(to, created) = TopicOrder.objects.get_or_create(course=course, topic=topic)
			to.save()
			msg = 'Topic ordering successfull'
		except Exception, x:
			logging.error("could not save TopicOrder object " + x)
			msg = 'Topic ordering failed because ' + x
Example #2
0
def topic_add(request, course_short_name):
	#User has asked for a form to add a topic to this course
	if request.method == 'GET':
		return render_to_response('topic/add.html', {'course_short_name':course_short_name}, context_instance=RequestContext(request))
	#User has posted data to add a topic
	elif request.method == 'POST':
		t = Topic()
		t.title = request.POST['title']
		t.content = request.POST['content']
		c = Course.objects.get(short_name=request.POST['course_short_name'])
		t.course = c
		t.save()
		topic_order = TopicOrder(course=c, topic=t)
		topic_orders = TopicOrder.objects.filter(course=c).order_by('-order')[:1]
		if topic_orders:
			topic_order.order = topic_orders[0].order + 1
		else:
			topic_order.order = 0
		topic_order.save()
		#TODO: Can we make this a REST call to the forum app ??? it will be a better dependency
		forum_url = "/courses/course/topic/show/"+c.short_name+"/"+str(t.pk)
		forum = Forum(url=forum_url)
		forum.save()
		return render_to_response('topic/add.html', {'course_short_name':course_short_name, 'errors':['topic saved']}, context_instance=RequestContext(request))