Permalink
Browse files

continue improve the teach_aid feature.

  • Loading branch information...
1 parent 6f62239 commit a64b6eb62e5caffb809d81cfba4264e39917c0e1 @JasonLai256 committed May 12, 2012
Showing with 254 additions and 39 deletions.
  1. BIN dump.db
  2. +69 −25 taCore/views.py
  3. +185 −14 templates/taCore/teach_aid.html
View
BIN dump.db
Binary file not shown.
View
@@ -6,7 +6,7 @@
from django.contrib.auth.models import User
from django.contrib.auth import logout
from django.template import RequestContext
-from django.core.exceptions import ObjectDoesNotExist
+from django.core.exceptions import ObjectDoesNotExist, ValidationError
from taCore.forms import *
from taCore.models import *
@@ -69,6 +69,7 @@ def teather_page(request, username):
@login_required
def teach_aid(request, courseid):
query = request.GET.get('query')
+ select = request.GET.get('select')
course = get_object_or_404(Course, id=courseid)
students = []
for cls in course.classes.all():
@@ -81,86 +82,129 @@ def teach_aid(request, courseid):
appra = Appraisal.objects.get(slug=slug)
except ObjectDoesNotExist:
_create_appraisal(slug, course, stu)
+ comments = [comment for comment in appra.comment_set.all()]
res = {
'stu_name': stu.user.first_name,
'stu_id': stu.user.username,
'appr_counter': appra.appr_counter,
'excellence_counter': appra.excellence_counter,
'good_counter': appra.good_counter,
'bad_counter': appra.bad_counter,
+ 'absent_counter': appra.absent_counter,
+ 'leave_counter': appra.leave_counter,
+ 'come_late_counter': appra.come_late_counter,
'last_appr': appra.last_appr,
'slug': appra.slug,
- 'comments': appra.comment_set.all(),
+ 'comments': comments,
}
appraisals.append(res)
appraisals = _make_order(appraisals, query)
+ group = _select_apprs(appraisals, select)
variables = RequestContext(request, {
'appraisals': appraisals,
'amount': len(appraisals),
'courseid': courseid,
'coursename': course.name,
+ 'selected_group': group,
})
return render_to_response('taCore/teach_aid.html', variables)
def _create_appraisal(slug, course, stu):
appr = Appraisal(slug=slug, course=course, student=stu)
appr.save()
+def _select_apprs(appraisals, select):
+ """selector format is like 'query-number', `query` is the content for the
+ select, `num` is the number of seleting appraisal.
+ """
+ if not select:
+ return
+ query, num = select.rsplit('-', 1)
+ num = int(num)
+ if query == 'random':
+ from random import shuffle
+ shuffle(appraisals)
+ else:
+ appraisals = _make_order(appraisals, query)
+ return appraisals[:num]
+
def _make_order(appraisals, query):
+ apprs = None
if not query:
- pass
+ apprs = appraisals
elif query == "name":
- appraisals.sort(key=lambda e: e['stu_name'])
+ apprs = sorted(appraisals,key=lambda e: e['stu_name'])
elif query == "last-excellence":
pass
- elif query == "last_good":
+ elif query == "last-good":
pass
- elif query == "last_bad":
+ elif query == "last-bad":
pass
elif query == "most-count":
- pass
+ apprs = sorted(appraisals,key=lambda e: e['appr_counter'])
+ apprs.reverse()
elif query == "most-excellence":
- pass
+ apprs = sorted(appraisals,key=lambda e: e['excellence_counter'])
+ apprs.reverse()
elif query == "most-good":
- pass
+ apprs = sorted(appraisals,key=lambda e: e['good_counter'])
+ apprs.reverse()
elif query == "most-bad":
- pass
- elif query == "no-count":
- pass
+ apprs = sorted(appraisals,key=lambda e: e['bad_counter'])
+ apprs.reverse()
+ elif query == "most-absent":
+ apprs = sorted(appraisals,key=lambda e: e['absent_counter'])
+ apprs.reverse()
+ elif query == "most-leave":
+ apprs = sorted(appraisals,key=lambda e: e['leave_counter'])
+ apprs.reverse()
+ elif query == "most-come-late":
+ apprs = sorted(appraisals,key=lambda e: e['come_late_counter'])
+ apprs.reverse()
+ elif query == "least-count":
+ apprs = sorted(appraisals,key=lambda e: e['appr_counter'])
elif query == "most-comment":
- pass
+ apprs = sorted(appraisals,key=lambda e: len(e['comments']))
+ apprs.reverse()
elif query == "":
pass
elif query == "":
pass
- return appraisals
+ else:
+ apprs = appraisals
+ return apprs
@login_required
def appraisal_poll(request, slug):
poll = request.POST['appraisal']
+ comm = request.POST['comment']
+
appra = get_object_or_404(Appraisal, slug=slug)
if poll == 'excellence':
appra.excellence_counter += 1
- appra.last_appr = 'excellence'
elif poll == 'good':
appra.good_counter += 1
- appra.last_appr = 'good'
elif poll == 'bad':
appra.bad_counter += 1
- appra.last_appr = 'bad'
+ elif poll == 'absent':
+ appra.absent_counter += 1
+ elif poll == 'leave':
+ appra.leave_counter += 1
+ elif poll == 'come_late':
+ appra.come_late_counter += 1
else:
- pass
-
+ raise ValidationError('invalid radio field name.')
+ appra.last_appr = poll
appra.appr_counter += 1
+ appra.save()
- return redirect_to('')
+ if comm:
+ comment = Comment(comment=comm, appraisal=appra)
+ comment.save()
-@login_required
-def appraisal_comment(request, slug):
- cmt = request.POST['comment']
- cmt = Comment(comment=cmt)
- appra = get_object_or_404(Appraisal, slug=slug)
+ courseid = str(appra.course.id)
+ return HttpResponseRedirect('/teach-aid/'+courseid)
Oops, something went wrong.

0 comments on commit a64b6eb

Please sign in to comment.