Skip to content

Assigned reviewers

hypha.apply.funds.models.assigned_reviewers

AssignedReviewersQuerySet

Bases: QuerySet

review_order

review_order()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def review_order(self):
    review_order = [
        STAFF_GROUP_NAME,
        COMMUNITY_REVIEWER_GROUP_NAME,
        REVIEWER_GROUP_NAME,
    ]

    ordering = [
        models.When(type__name=review_type, then=models.Value(i))
        for i, review_type in enumerate(review_order)
    ]
    return (
        self.exclude(
            # Remove people from the list who are opinionated but
            # didn't submit a review, they appear elsewhere
            Q(opinions__isnull=False)
            & Q(Q(review__isnull=True) | Q(review__is_draft=True))
        )
        .annotate(
            type_order=models.Case(
                *ordering,
                output_field=models.IntegerField(),
            ),
            has_review=models.Case(
                models.When(review__isnull=True, then=models.Value(1)),
                models.When(review__is_draft=True, then=models.Value(1)),
                default=models.Value(0),
                output_field=models.IntegerField(),
            ),
        )
        .order_by(
            "type_order",
            "has_review",
            F("role__order").asc(nulls_last=True),
        )
        .select_related(
            "reviewer",
            "role",
        )
    )

with_roles

with_roles()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def with_roles(self):
    return self.filter(role__isnull=False)

without_roles

without_roles()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def without_roles(self):
    return self.filter(role__isnull=True)

reviewed

reviewed()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def reviewed(self):
    return self.filter(
        Q(opinions__opinion=AGREE)
        | Q(Q(review__isnull=False) & Q(review__is_draft=False))
    ).distinct()

draft_reviewed

draft_reviewed()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def draft_reviewed(self):
    return self.filter(
        Q(Q(review__isnull=False) & Q(review__is_draft=True))
    ).distinct()

not_reviewed

not_reviewed()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def not_reviewed(self):
    return self.filter(
        Q(review__isnull=True) | Q(review__is_draft=True),
        Q(opinions__isnull=True) | Q(opinions__opinion=DISAGREE),
    ).distinct()

never_tried_to_review

never_tried_to_review()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def never_tried_to_review(self):
    # Different from not reviewed as draft reviews allowed
    return self.filter(
        review__isnull=True,
        opinions__isnull=True,
    )

staff

staff()
Source code in hypha/apply/funds/models/assigned_reviewers.py
def staff(self):
    return self.filter(type__name=STAFF_GROUP_NAME)

get_or_create_for_user

get_or_create_for_user(submission, reviewer)
Source code in hypha/apply/funds/models/assigned_reviewers.py
def get_or_create_for_user(self, submission, reviewer):
    groups = set(reviewer.groups.values_list("name", flat=True)) & set(
        REVIEW_GROUPS
    )
    if len(groups) > 1:
        if COMMUNITY_REVIEWER_GROUP_NAME in groups:
            groups = {COMMUNITY_REVIEWER_GROUP_NAME}
        elif reviewer.is_apply_staff:
            groups = {STAFF_GROUP_NAME}
        else:
            groups = {REVIEWER_GROUP_NAME}
    elif not groups:
        if reviewer.is_staff or reviewer.is_superuser:
            groups = {STAFF_GROUP_NAME}
        else:
            groups = {REVIEWER_GROUP_NAME}

    group = Group.objects.get(name=groups.pop())

    return self.get_or_create(
        submission=submission,
        reviewer=reviewer,
        defaults={"type": group},
    )

get_or_create_staff

get_or_create_staff(submission, reviewer)
Source code in hypha/apply/funds/models/assigned_reviewers.py
def get_or_create_staff(self, submission, reviewer):
    return self.get_or_create(
        submission=submission,
        reviewer=reviewer,
        type=Group.objects.get(name=STAFF_GROUP_NAME),
    )

bulk_create_reviewers

bulk_create_reviewers(reviewers, submission)
Source code in hypha/apply/funds/models/assigned_reviewers.py
def bulk_create_reviewers(self, reviewers, submission):
    group = Group.objects.get(name=REVIEWER_GROUP_NAME)
    self.bulk_create(
        [
            self.model(
                submission=submission,
                role=None,
                reviewer=reviewer,
                type=group,
            )
            for reviewer in reviewers
        ],
        ignore_conflicts=True,
    )

update_role

update_role(role, reviewer, *submissions)
Source code in hypha/apply/funds/models/assigned_reviewers.py
def update_role(self, role, reviewer, *submissions):
    # Remove role who didn't review
    self.filter(
        submission__in=submissions, role=role
    ).never_tried_to_review().delete()
    # Anyone else we remove their role
    self.filter(submission__in=submissions, role=role).update(role=None)
    # Create/update the new role reviewers
    group = Group.objects.get(name=STAFF_GROUP_NAME)
    for submission in submissions:
        self.update_or_create(
            submission=submission,
            reviewer=reviewer,
            defaults={"role": role, "type": group},
        )

AssignedReviewers

Bases: Model

wagtail_reference_index_ignore class-attribute instance-attribute

wagtail_reference_index_ignore = True

reviewer class-attribute instance-attribute

reviewer = ForeignKey(AUTH_USER_MODEL, on_delete=CASCADE, limit_choices_to=LIMIT_TO_REVIEWER_GROUPS)

type class-attribute instance-attribute

type = ForeignKey('auth.Group', on_delete=PROTECT)

submission class-attribute instance-attribute

submission = ForeignKey('funds.ApplicationSubmission', related_name='assigned', on_delete=CASCADE)

role class-attribute instance-attribute

role = ForeignKey('funds.ReviewerRole', related_name='+', on_delete=SET_NULL, null=True)

objects class-attribute instance-attribute

objects = as_manager()

Meta

unique_together class-attribute instance-attribute
unique_together = (('submission', 'role'), ('submission', 'reviewer'))