Skip to content

Commit

Permalink
make to string for Marker more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Aug 12, 2024
1 parent 5a4c572 commit a49346d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 12 additions & 3 deletions crowdsourcer/management/commands/import_volunteers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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(
Expand All @@ -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")
Expand Down
10 changes: 9 additions & 1 deletion crowdsourcer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a49346d

Please sign in to comment.