Showing exercices left to mark in admin list view of Submissions
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 6 Nov 2013 16:01:33 +0000 (17:01 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 15 Jan 2014 10:18:54 +0000 (11:18 +0100)
edumed/settings.d/40-middleware.py
wtem/admin.py
wtem/middleware.py [new file with mode: 0644]

index 998b707..4dcd91d 100644 (file)
@@ -24,5 +24,6 @@ MIDDLEWARE_CLASSES = tuple(x for x in (
     'django.middleware.cache.FetchFromCacheMiddleware',
     'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
     'pybb.middleware.PybbMiddleware',
     'django.middleware.cache.FetchFromCacheMiddleware',
     'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
     'pybb.middleware.PybbMiddleware',
-    'forum.middleware.ForumMiddleware'
+    'forum.middleware.ForumMiddleware',
+    'wtem.middleware.ThreadLocalMiddleware'
 ) if x is not None)
 ) if x is not None)
index 672666b..037ed37 100644 (file)
@@ -8,6 +8,7 @@ from django.utils import simplejson
 from django.core.urlresolvers import reverse
 
 from .models import Submission, Assignment
 from django.core.urlresolvers import reverse
 
 from .models import Submission, Assignment
+from .middleware import get_current_request
 
 
 f = file(os.path.dirname(__file__) + '/fixtures/exercises.json')
 
 
 f = file(os.path.dirname(__file__) + '/fixtures/exercises.json')
@@ -54,6 +55,7 @@ def get_form(request, submission):
 
 
 class SubmissionAdmin(admin.ModelAdmin):
 
 
 class SubmissionAdmin(admin.ModelAdmin):
+    list_display = ('__unicode__', 'todo',)
     readonly_fields = readonly_fields
 
     def get_form(self, request, obj, **kwargs):
     readonly_fields = readonly_fields
 
     def get_form(self, request, obj, **kwargs):
@@ -69,6 +71,12 @@ class SubmissionAdmin(admin.ModelAdmin):
     submitted_by.allow_tags = True
     submitted_by.short_description = "Zgłoszony/a przez"
 
     submitted_by.allow_tags = True
     submitted_by.short_description = "Zgłoszony/a przez"
 
+    def todo(self, submission):
+        user = get_current_request().user
+        user_exercises = get_user_exercises(user)
+        user_marks = submission.marks.get(str(user.id), {})
+        return ','.join([str(e['id']) for e in user_exercises if str(e['id']) not in user_marks.keys()])
+
     def save_model(self, request, submission, form, change):
         for name, value in form.cleaned_data.items():
             if name.startswith('markof_'):
     def save_model(self, request, submission, form, change):
         for name, value in form.cleaned_data.items():
             if name.startswith('markof_'):
diff --git a/wtem/middleware.py b/wtem/middleware.py
new file mode 100644 (file)
index 0000000..d9bd308
--- /dev/null
@@ -0,0 +1,15 @@
+try:
+    from threading import local
+except ImportError:
+    from django.utils._threading_local import local
+
+
+_thread_locals = local()
+
+def get_current_request():
+    return getattr(_thread_locals, 'request', None)
+
+
+class ThreadLocalMiddleware:
+    def process_request(self, request):
+        _thread_locals.request = request
\ No newline at end of file