diff --git a/symposion/reviews/management/commands/assign_reviewers.py b/symposion/reviews/management/commands/assign_reviewers.py new file mode 100644 index 00000000..334eab30 --- /dev/null +++ b/symposion/reviews/management/commands/assign_reviewers.py @@ -0,0 +1,17 @@ +import csv +import os +import random + +from django.contrib.auth import models +from django.core.management.base import BaseCommand + +from symposion.reviews.models import ReviewAssignment +from symposion.proposals.models import ProposalBase + + +class Command(BaseCommand): + + def handle(self, *args, **options): + for proposal in ProposalBase.objects.filter(cancelled=0): + print "Creating assignments for %s" % (proposal.title,) + ReviewAssignment.create_assignments(proposal) diff --git a/symposion/reviews/models.py b/symposion/reviews/models.py index a6ac5657..64d6db8d 100644 --- a/symposion/reviews/models.py +++ b/symposion/reviews/models.py @@ -43,6 +43,8 @@ class ReviewAssignment(models.Model): AUTO_ASSIGNED_INITIAL = 0 OPT_IN = 1 AUTO_ASSIGNED_LATER = 2 + + NUM_REVIEWERS = 3 ORIGIN_CHOICES = [ (AUTO_ASSIGNED_INITIAL, "auto-assigned, initial"), @@ -66,7 +68,10 @@ class ReviewAssignment(models.Model): speaker.user_id for speaker in speakers if speaker.user_id is not None - ] + ] + [ + assignment.user_id + for assignment in ReviewAssignment.objects.filter( + proposal_id=proposal.id)] ).filter( groups__name="reviewers", ).filter( @@ -74,9 +79,11 @@ class ReviewAssignment(models.Model): ).annotate( num_assignments=models.Count("reviewassignment") ).order_by( - "num_assignments", + "num_assignments", "?", ) - for reviewer in reviewers[:3]: + num_assigned_reviewers = ReviewAssignment.objects.filter( + proposal_id=proposal.id, opted_out=0).count() + for reviewer in reviewers[:max(0, cls.NUM_REVIEWERS - num_assigned_reviewers)]: cls._default_manager.create( proposal=proposal, user=reviewer,