'django.middleware.cache.FetchFromCacheMiddleware',
'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
'pybb.middleware.PybbMiddleware',
- 'forum.middleware.ForumMiddleware'
+ 'forum.middleware.ForumMiddleware',
+ 'wtem.middleware.ThreadLocalMiddleware'
) if x is not None)
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')
class SubmissionAdmin(admin.ModelAdmin):
+ list_display = ('__unicode__', 'todo',)
readonly_fields = readonly_fields
def get_form(self, request, obj, **kwargs):
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_'):
--- /dev/null
+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