From e180c7f00b6da9381232559d5e4696faa27f961a Mon Sep 17 00:00:00 2001 From: Taavi Burns Date: Fri, 21 Jun 2013 22:50:16 -0400 Subject: [PATCH] Adds a manage.py script to assign reviewers to talks. Requires that a 'reviewers' group exist, and that there are people assigned to it (otherwise it won't find any reviewers to add!). It will assign up to 3 reviewers, where those reviewers are NOT one of the speakers, and that reviewer has not opted out of reviewing that talk. It will choose random reviewers from those with the fewest existing not-opted-out assignments. --- .../management/commands/assign_reviewers.py | 17 +++++++++++++++++ symposion/reviews/models.py | 13 ++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 symposion/reviews/management/commands/assign_reviewers.py 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,