From 8300a1a6644d33deaf5ad0dcbc51755db3c21f00 Mon Sep 17 00:00:00 2001 From: raylu Date: Thu, 12 May 2011 19:10:44 -0400 Subject: Add lab view --- pyc/grader/models.py | 4 +++- pyc/grader/views.py | 8 +++++++- pyc/templates/base.html | 10 ++++++++++ pyc/templates/index.html | 19 +++++++++---------- pyc/templates/lab.html | 20 ++++++++++++++++++++ pyc/urls.py | 4 ++-- 6 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 pyc/templates/base.html create mode 100644 pyc/templates/lab.html diff --git a/pyc/grader/models.py b/pyc/grader/models.py index 651ba6e..bf92598 100644 --- a/pyc/grader/models.py +++ b/pyc/grader/models.py @@ -12,5 +12,7 @@ class Submission(models.Model): user = models.ForeignKey(User) time = models.DateTimeField() grade = models.IntegerField() + class Meta: + unique_together = (('lab', 'user'),) def __unicode__(self): - return "%d, %s" % (self.lab, self.user) + return "%d, %s" % (self.lab.id, self.user) diff --git a/pyc/grader/views.py b/pyc/grader/views.py index 35dba57..bba6b8f 100644 --- a/pyc/grader/views.py +++ b/pyc/grader/views.py @@ -1,4 +1,10 @@ from django.shortcuts import render_to_response +from grader.models import Lab def index(request): - return render_to_response('index.html') + return render_to_response('index.html', {'labs' : Lab.objects.all()}) + +def lab(request, lab_id): + lab = Lab.objects.get(pk=lab_id) + submissions = lab.submission_set.filter(user__is_staff=False).order_by('-grade', '-time') + return render_to_response('lab.html', {'lab' : lab, 'submissions' : submissions}) diff --git a/pyc/templates/base.html b/pyc/templates/base.html new file mode 100644 index 0000000..65aa2f2 --- /dev/null +++ b/pyc/templates/base.html @@ -0,0 +1,10 @@ + + + + + pyc + + +{% block body %}{% endblock %} + + diff --git a/pyc/templates/index.html b/pyc/templates/index.html index 87bb880..6707fca 100644 --- a/pyc/templates/index.html +++ b/pyc/templates/index.html @@ -1,10 +1,9 @@ - - - - - pyc - - -woo - - +{% extends 'base.html' %} +{% block body %} +Labs: +
    +{% for lab in labs %} +
  1. {{ lab.name }}
  2. +{% endfor %} +
+{% endblock %} diff --git a/pyc/templates/lab.html b/pyc/templates/lab.html new file mode 100644 index 0000000..f07a082 --- /dev/null +++ b/pyc/templates/lab.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} +{% block body %} +Lab {{ lab.id }} due {{ lab.due }} at 11:59:59 PDT (UTC-7): +
{{ lab.name }} + + + + + + + +{% for s in submissions %} + + + + + +{% endfor %} +
UserGradeTime
{{ s.user }}{{ s.grade }}{{ s.time }}
+{% endblock %} diff --git a/pyc/urls.py b/pyc/urls.py index 92c79c9..b65970e 100644 --- a/pyc/urls.py +++ b/pyc/urls.py @@ -4,8 +4,8 @@ from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', - url(r'^$', 'pyc.grader.views.index', name='index'), - # url(r'^pyc/', include('pyc.foo.urls')), + url(r'^$', 'grader.views.index', name='index'), + url(r'^lab/(?P\d+)/$', 'grader.views.lab'), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), -- cgit v1.2.3