-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
management command to fill in missing Marker objects
we need these now for various things and we did not in the past so add them in for users who are missing them. Fixes #153
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django.contrib.auth.models import User | ||
from django.core.management.base import BaseCommand | ||
|
||
from crowdsourcer.models import Assigned, Marker, MarkingSession, ResponseType | ||
|
||
YELLOW = "\033[33m" | ||
NOBOLD = "\033[0m" | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Make sure all user's have a related Marker" | ||
|
||
rts = ["First Mark", "Right of Reply", "Audit"] | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--session", required=True, action="store", help="Marking session to use" | ||
) | ||
|
||
def handle(self, *args, **kwargs): | ||
users = User.objects.filter(marker__isnull=True) | ||
|
||
session_label = kwargs["session"] | ||
|
||
session = MarkingSession.objects.get(label=session_label) | ||
|
||
for user in users: | ||
assigned = list( | ||
Assigned.objects.filter(user=user) | ||
.values_list("response_type__type", flat=True) | ||
.distinct() | ||
) | ||
|
||
num_rts = len(assigned) | ||
if num_rts == 0: | ||
rt_type = "First Mark" | ||
elif len(assigned) == 1: | ||
rt_type = assigned[0] | ||
else: | ||
for rt in self.rts: | ||
if rt in assigned: | ||
rt_type = rt | ||
|
||
if rt_type is None: | ||
rt_type = "First Mark" | ||
|
||
m = Marker.objects.create( | ||
user=user, | ||
response_type=ResponseType.objects.get(type=rt_type), | ||
) | ||
m.marking_session.add(session) | ||
|
||
print(f"Added markers to {users.count()} users") |