Skip to content

Commit

Permalink
Solved issues with failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed Nov 30, 2022
1 parent 929726f commit 5493835
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions oppia/models/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,24 @@ def update_participants_by_role(self, role):
from profile.utils import get_customfields_filter

role_criteria = CohortCritera.objects.filter(cohort=self, role=role)

participants = User.objects
applicable_criteria = 0
participants = User.objects.all()
# as Django's filter() function is accumulative, we can concatenate them as an AND expression
for criteria in role_criteria:
customfield = CustomField.objects.filter(id=criteria.user_profile_field).first()
if not customfield:
continue
value = criteria.user_profile_value
participants = participants.filter(
get_customfields_filter(value, customfield))

for participant in participants:
if not Participant.objects.filter(cohort=self, user=participant, role=role).exists():
Participant.objects.create(cohort=self, user=participant, role=role)

return len(participants)
participants = participants.filter(get_customfields_filter(value, customfield))
applicable_criteria += 1

if applicable_criteria > 0:
for participant in participants:
if not Participant.objects.filter(cohort=self, user=participant, role=role).exists():
Participant.objects.create(cohort=self, user=participant, role=role)
return len(participants)
else:
return 0


class CourseCohort(models.Model):
Expand Down

0 comments on commit 5493835

Please sign in to comment.