X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/cb238bf65280df57db6158d437853475af4f2e18..3e7f52386e8c0b72997a2d1b915d5c3d535c7b8f:/wtem/management/commands/wtem_assign_submissions.py diff --git a/wtem/management/commands/wtem_assign_submissions.py b/wtem/management/commands/wtem_assign_submissions.py index f87b7f4..7ff1af2 100644 --- a/wtem/management/commands/wtem_assign_submissions.py +++ b/wtem/management/commands/wtem_assign_submissions.py @@ -1,24 +1,46 @@ +from optparse import make_option + from django.core.management.base import BaseCommand, CommandError from django.db.models import Count from django.contrib.auth.models import User from contact.models import Contact -from wtem.models import Submission +from wtem.models import Submission, Attachment class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option('--with-attachments-only', + action='store_true', + dest='attachments_only', + default=False, + help='Take into account only submissions with attachments'), + make_option('--without-attachments-only', + action='store_true', + dest='no_attachments_only', + default=False, + help='Take into account only submissions without attachments'), + ) + def handle(self, *args, **options): - how_many = int(args[0]) - examiner_names = args[1:] + + limit_from = int(args[0]) + limit_to = int(args[1]) + examiner_names = args[2:] users = User.objects.filter(username__in = examiner_names) submissions_query = Submission.objects.annotate(examiners_count = Count('examiners')) - submissions = submissions_query \ - .filter(examiners_count__lt=2)[0:how_many] + submissions = submissions_query.exclude(answers = None) + + with_attachment_ids = Attachment.objects.values_list('submission_id', flat=True).all() + if options['attachments_only']: + submissions = submissions.filter(id__in = with_attachment_ids) + if options['no_attachments_only']: + submissions = submissions.exclude(id__in = with_attachment_ids) - for submission in submissions: + for submission in submissions.order_by('id')[limit_from:limit_to]: submission.examiners.add(*users) submission.save() self.stdout.write('added to %s:%s' % (submission.id, submission.email))