|
|
@@ -1,8 +1,12 @@
|
|
|
from django.shortcuts import render_to_response
|
|
|
from django.template import RequestContext
|
|
|
+from django.contrib.auth.decorators import login_required, user_passes_test
|
|
|
+from django.conf import settings
|
|
|
|
|
|
from grader.models import Lab, Submission
|
|
|
|
|
|
+import os
|
|
|
+
|
|
|
def index(request):
|
|
|
return render_to_response('index.html', {
|
|
|
'labs' : Lab.objects.all(),
|
|
|
@@ -25,15 +29,13 @@ def lab(request, lab_id):
|
|
|
return render_to_response('lab.html', {
|
|
|
'lab' : lab,
|
|
|
'submissions' : submissions,
|
|
|
+ 'staff' : request.user.is_staff
|
|
|
})
|
|
|
|
|
|
-from django.contrib.auth.decorators import login_required
|
|
|
@login_required
|
|
|
def submit(request, lab_id):
|
|
|
from django.http import HttpResponseRedirect
|
|
|
from django.db import IntegrityError
|
|
|
- from django.conf import settings
|
|
|
- import os
|
|
|
from datetime import datetime
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
@@ -74,6 +76,17 @@ def submit(request, lab_id):
|
|
|
'lab_id' : lab_id,
|
|
|
}, context_instance=RequestContext(request))
|
|
|
|
|
|
+@user_passes_test(lambda u: u.is_staff)
|
|
|
+def submission(request, lab_id, user_id):
|
|
|
+ submission = Submission.objects.get(lab__exact=lab_id, user__exact=user_id)
|
|
|
+ filepath = os.path.join(settings.MEDIA_ROOT, submission.file.name)
|
|
|
+ f = open(filepath, 'r')
|
|
|
+ code = f.read()
|
|
|
+ f.close()
|
|
|
+ return render_to_response('submission.html', {
|
|
|
+ 'code' : code,
|
|
|
+ })
|
|
|
+
|
|
|
def grade(file, id):
|
|
|
import subprocess
|
|
|
from os import path
|