generate keys
[edumed.git] / wtem / admin.py
index 56a687d..acab816 100644 (file)
@@ -10,6 +10,7 @@ from django.http import HttpResponse
 from django.template.loader import render_to_string
 from django.utils.safestring import mark_safe
 
+from wtem.models import Confirmation, CompetitionState
 from .middleware import get_current_request
 from .models import Submission, Assignment, Attachment, exercises
 
@@ -155,8 +156,7 @@ class SubmissionAdmin(admin.ModelAdmin):
     def get_form(self, request, obj=None, **kwargs):
         return get_form(request, obj)
 
-    @staticmethod
-    def submitted_by(instance):
+    def submitted_by(self, instance):
         if instance.contact:
             return '<a href="%s">%s</a>' % (
                 reverse('admin:contact_contact_change', args=[instance.contact.id]),
@@ -166,16 +166,14 @@ class SubmissionAdmin(admin.ModelAdmin):
     submitted_by.allow_tags = True
     submitted_by.short_description = "Zgłoszony/a przez"
 
-    @staticmethod
-    def todo(submission):
+    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()])
     todo.short_description = 'Twoje nieocenione zadania'
 
-    @staticmethod
-    def examiners_repr(submission):
+    def examiners_repr(self, submission):
         return ', '.join([u.username for u in submission.examiners.all()])
     examiners_repr.short_description = 'Przypisani do zgłoszenia'
 
@@ -209,7 +207,6 @@ class SubmissionAdmin(admin.ModelAdmin):
         return qs
 
     def get_urls(self):
-        urls = super(SubmissionAdmin, self).get_urls()
         return patterns(
             '',
             url(r'^report/$', self.admin_site.admin_view(report_view), name='wtem_admin_report')
@@ -227,6 +224,9 @@ class SubmissionsSet:
                     examiners = self.examiners_by_exercise.setdefault(exercise_id, [])
                     if user not in examiners:
                         examiners.append(user)
+            if submission.contact:
+                contact_body = submission.contact.body
+                submission.school = '%s %s' % (contact_body.get('school'), contact_body.get('school_address'))
 
 
 def report_view(request):
@@ -238,5 +238,22 @@ def report_view(request):
     response['Content-Disposition'] = 'attachment; filename="wyniki.csv"'
     return response
 
+
+class ConfirmationAdmin(admin.ModelAdmin):
+    list_display = ('email', 'first_name', 'last_name', 'readable_contact', 'school_phone', 'readable_age', 'confirmed')
+    readonly_fields = ('contact', 'readable_contact', 'readable_age', 'school_phone', 'key', 'confirmed')
+    list_filter = ('confirmed',)
+    list_select_related = ('contact',)
+    search_fields = ('last_name', 'email', 'contact__contact')
+
+    def resend_mail(self, request, queryset):
+        for confirmation in queryset:
+            confirmation.send_mail()
+    resend_mail.short_description = "Wyślij kod ponownie"
+
+    actions = [resend_mail]
+
 admin.site.register(Submission, SubmissionAdmin)
 admin.site.register(Assignment)
+admin.site.register(Confirmation, ConfirmationAdmin)
+admin.site.register(CompetitionState)