From a49346d093c666f93cf0016cc40b33a4ab836fed Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 12 Aug 2024 14:41:03 +0100 Subject: [PATCH] make to string for Marker more robust --- .../management/commands/import_volunteers.py | 15 ++++++++++++--- crowdsourcer/models.py | 10 +++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crowdsourcer/management/commands/import_volunteers.py b/crowdsourcer/management/commands/import_volunteers.py index 3a00331..c58b85b 100644 --- a/crowdsourcer/management/commands/import_volunteers.py +++ b/crowdsourcer/management/commands/import_volunteers.py @@ -202,6 +202,7 @@ def handle( u, _ = User.objects.update_or_create( username=email, defaults={ + "is_active": True, "email": email, "first_name": row["first_name"], "last_name": row["last_name"], @@ -240,7 +241,9 @@ def handle( # self.stdout.write(f"no section assigned for {row['email']}") continue - existing_assignments = Assigned.objects.filter(user=u) + existing_assignments = Assigned.objects.filter( + user=u, marking_session=session + ) if existing_assignments.count() > 0: self.stdout.write( f"{YELLOW}Existing assignments: {row['email']}{NOBOLD}" @@ -289,7 +292,11 @@ def handle( if options["make_assignments"] is True: for council in councils_to_assign: a, created = Assigned.objects.update_or_create( - user=u, section=s, authority=council, marking_session=session + user=u, + section=s, + authority=council, + marking_session=session, + response_type=rt, ) council_count = PublicAuthority.objects.filter( @@ -304,7 +311,9 @@ def handle( else: self.stdout.write(f"{GREEN}All councils and sections assigned{NOBOLD}") - volunteer_count = User.objects.all().count() + volunteer_count = User.objects.filter( + marker__marking_session=session, marker__response_type=rt + ).count() assigned_count = ( Assigned.objects.filter(user__is_superuser=False) .distinct("user_id") diff --git a/crowdsourcer/models.py b/crowdsourcer/models.py index 932e413..56adf73 100644 --- a/crowdsourcer/models.py +++ b/crowdsourcer/models.py @@ -335,7 +335,15 @@ class Assigned(models.Model): history = HistoricalRecords() def __str__(self): - return f"{self.user.email}, {self.section.title}, {self.response_type.type}, {self.marking_session.label}" + parts = [self.user.email, self.marking_session.label] + if self.authority is not None: + parts.append(self.authority.name) + if self.section is not None: + parts.append(self.section.title) + if self.response_type is not None: + parts.append(self.response_type.type) + + return ", ".join(parts) @classmethod def is_user_assigned(cls, user, **kwargs):