From b6b567337c2dcdf8fb959b36fbb589d8ac9ff9eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 6 Nov 2013 17:01:33 +0100 Subject: [PATCH] Showing exercices left to mark in admin list view of Submissions --- edumed/settings.d/40-middleware.py | 3 ++- wtem/admin.py | 8 ++++++++ wtem/middleware.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 wtem/middleware.py diff --git a/edumed/settings.d/40-middleware.py b/edumed/settings.d/40-middleware.py index 998b707..4dcd91d 100644 --- a/edumed/settings.d/40-middleware.py +++ b/edumed/settings.d/40-middleware.py @@ -24,5 +24,6 @@ MIDDLEWARE_CLASSES = tuple(x for x in ( 'django.middleware.cache.FetchFromCacheMiddleware', 'fnpdjango.middleware.SetRemoteAddrFromXRealIP', 'pybb.middleware.PybbMiddleware', - 'forum.middleware.ForumMiddleware' + 'forum.middleware.ForumMiddleware', + 'wtem.middleware.ThreadLocalMiddleware' ) if x is not None) diff --git a/wtem/admin.py b/wtem/admin.py index 672666b..037ed37 100644 --- a/wtem/admin.py +++ b/wtem/admin.py @@ -8,6 +8,7 @@ from django.utils import simplejson 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') @@ -54,6 +55,7 @@ def get_form(request, submission): class SubmissionAdmin(admin.ModelAdmin): + list_display = ('__unicode__', 'todo',) 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" + 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_'): diff --git a/wtem/middleware.py b/wtem/middleware.py new file mode 100644 index 0000000..d9bd308 --- /dev/null +++ b/wtem/middleware.py @@ -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 -- 2.20.1