]> git.parisson.com Git - teleforma.git/commitdiff
Handle issue with script corrector assignment
authortest test <yoanl@pilotsystems.net>
Thu, 15 Jul 2021 11:36:36 +0000 (13:36 +0200)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Thu, 15 Jul 2021 11:36:36 +0000 (13:36 +0200)
teleforma/exam/admin.py
teleforma/exam/models.py
teleforma/management/commands/teleforma-exam-set-correctors.py [new file with mode: 0644]

index 36f007a6b2e3853474d8facc245b6cbbf9295165..44f30d99a79a92d878b4305b5d6a71d57ecbd879 100644 (file)
@@ -17,8 +17,15 @@ class QuotaAdmin(admin.ModelAdmin):
     list_filter = ['course__title', 'period', 'session']
     search_fields = ['corrector__username', 'corrector__last_name']
 
+    def render_change_form(self, request, context, *args, **kwargs):
+         context['adminform'].form.fields['corrector'].queryset = User.objects.filter(is_active=True).filter(Q(corrector__isnull=False) | Q(is_superuser=True))
+         return super(QuotaAdmin, self).render_change_form(request, context, *args, **kwargs)
+
     def corrector_name(self, instance):
-        return instance.corrector.last_name + ' ' + instance.corrector.first_name
+        if instance.corrector:
+            return instance.corrector.last_name + ' ' + instance.corrector.first_name
+        else:
+            return "Aucun"
 
 
 class ScriptPageInline(admin.StackedInline):
index b4e3ad740a7877a70885f20cef46a62f03185976..24ad71b2babbd96b4e9ce0d8e4543d28682fc4aa 100755 (executable)
@@ -142,7 +142,7 @@ class Quota(models.Model):
     course = models.ForeignKey(Course, related_name="quotas", verbose_name=_(
         'course'), null=True, blank=True, on_delete=models.SET_NULL)
     corrector = models.ForeignKey(User, related_name="quotas", verbose_name=_(
-        'corrector'), null=True, blank=True, on_delete=models.SET_NULL)
+        'corrector'), null=True, blank=False, on_delete=models.SET_NULL)
     period = models.ForeignKey(Period, related_name='quotas', verbose_name=_(
         'period'), null=True, blank=True, on_delete=models.SET_NULL)
     session = models.CharField(
diff --git a/teleforma/management/commands/teleforma-exam-set-correctors.py b/teleforma/management/commands/teleforma-exam-set-correctors.py
new file mode 100644 (file)
index 0000000..89cea1b
--- /dev/null
@@ -0,0 +1,18 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
+from teleforma.exam.models import *
+import logging
+import codecs
+
+
+class Command(BaseCommand):
+    help = "Set corrector to unassigned pending scripts"
+
+    def handle(self, *args, **options):
+        scripts = Script.objects.filter(corrector=None, status='3')
+        for script in scripts:
+            script.auto_set_corrector()
+            print(f"set corrector {script.corrector} for script {script.id}")
\ No newline at end of file