1 from django.core.management.base import BaseCommand, CommandError
2 from django.db.models import Count
3 from django.contrib.auth.models import User
5 from contact.models import Contact
6 from wtem.models import Submission
9 class Command(BaseCommand):
11 def handle(self, *args, **options):
12 how_many = int(args[0])
13 examiner_names = args[1:]
15 users = User.objects.filter(username__in = examiner_names)
16 submissions_query = Submission.objects.annotate(examiners_count = Count('examiners'))
18 submissions = submissions_query \
19 .filter(examiners_count__lt=2)[0:how_many]
21 for submission in submissions:
22 submission.examiners.add(*users)
24 self.stdout.write('added to %s:%s' % (submission.id, submission.email))
26 count_by_examiners = dict()
27 for submission in submissions_query.all():
28 count_by_examiners[submission.examiners_count] = \
29 count_by_examiners.get(submission.examiners_count, 0) + 1
30 self.stdout.write('%s' % count_by_examiners)