From b6afef1098be82da480866e2147beb8c16f58fe4 Mon Sep 17 00:00:00 2001 From: Jan Gaura Date: Wed, 10 Apr 2024 15:45:50 +0200 Subject: [PATCH] Changed `id` to `pk` in model lookups In `common` module. --- common/admin.py | 2 +- common/bulk_import.py | 7 ++----- common/models.py | 8 ++++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/common/admin.py b/common/admin.py index 14659f4e..e5628e31 100644 --- a/common/admin.py +++ b/common/admin.py @@ -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 diff --git a/common/bulk_import.py b/common/bulk_import.py index f4d92eb9..1fc82f0f 100644 --- a/common/bulk_import.py +++ b/common/bulk_import.py @@ -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 @@ -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() diff --git a/common/models.py b/common/models.py index 878acd18..9be1e75e 100644 --- a/common/models.py +++ b/common/models.py @@ -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}" @@ -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" @@ -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'])