Skip to content

Commit

Permalink
Changed id to pk in model lookups
Browse files Browse the repository at this point in the history
In `common` module.
  • Loading branch information
geordi committed Apr 11, 2024
1 parent a1fefd0 commit b6afef1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BaseByTeacherFilter(admin.SimpleListFilter):

def lookups(self, request, model_admin):
teachers = User.objects.filter(groups__name='teachers')
items = ( (t.id, t.username) for t in teachers )
items = ( (t.pk, t.username) for t in teachers )

return items

Expand Down
7 changes: 2 additions & 5 deletions common/bulk_import.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import datetime
import re
from common import inbus
from .inbus import inbus
from common.utils import is_teacher, user_from_login
import serde
from dataclasses import dataclass
from django.contrib.auth.models import User, Group
from common.models import Class, Semester, Subject
from io import StringIO
from lxml.html import parse
from typing import List, Dict, Generator
import traceback

Expand Down Expand Up @@ -83,7 +80,7 @@ def run(concrete_activities: List[ConcreteActivity], subj: Dict[str, str], semes
class_in_db[c].save()

# Students
students_in_class = inbus.inbus.students_in_concrete_activity(ca.concreteActivityId)
students_in_class = inbus.students_in_concrete_activity(ca.concreteActivityId)

for student in students_in_class:
login = student.login.upper()
Expand Down
8 changes: 4 additions & 4 deletions common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def all_sources(self) -> List[SourcePath]:
return sources

def __str__(self):
return f"#{self.id} {self.student.username} {self.assignment.task.name} (task_id={self.assignment.task_id}) #{self.submit_num}"
return f"#{self.pk} {self.student.username} {self.assignment.task.name} (task_id={self.assignment.task_id}) #{self.submit_num}"

def notification_str(self):
return f"{self.assignment.task.name} #{self.submit_num}"
Expand All @@ -292,7 +292,7 @@ class Comment(models.Model):
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"comment #{self.id}"
return f"comment #{self.pk}"

def notification_str(self):
return "comment"
Expand Down Expand Up @@ -342,12 +342,12 @@ def ensure_student(student):
student_submit_stats['max_points'] = submit.max_points
student_submit_stats['assigned_points'] = submit.assigned_points
student_submit_stats['accepted_submit_num'] = submit.submit_num
student_submit_stats['accepted_submit_id'] = submit.id
student_submit_stats['accepted_submit_id'] = submit.pk

if submit.assigned_points is not None:
student_submit_stats['submits_with_assigned_pts'] += 1
student_submit_stats['assigned_points'] = submit.assigned_points
student_submit_stats['accepted_submit_num'] = submit.submit_num
student_submit_stats['accepted_submit_id'] = submit.id
student_submit_stats['accepted_submit_id'] = submit.pk

return sorted(results.values(), key=lambda s: s['student'])

0 comments on commit b6afef1

Please sign in to comment.