Skip to content

Commit 8efe8ce

Browse files
committed
add DJ checks
1 parent 23986fd commit 8efe8ce

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

evap/evaluation/models.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ class Visibility(models.IntegerChoices):
194194

195195
objects = QuestionnaireManager()
196196

197-
def clean(self):
198-
if self.type == self.Type.CONTRIBUTOR and self.is_locked:
199-
raise ValidationError({"is_locked": _("Contributor questionnaires cannot be locked.")})
200-
201197
class Meta:
202198
ordering = ["type", "order", "pk"]
203199
verbose_name = _("questionnaire")
@@ -206,6 +202,10 @@ class Meta:
206202
def __str__(self):
207203
return self.name
208204

205+
def clean(self):
206+
if self.type == self.Type.CONTRIBUTOR and self.is_locked:
207+
raise ValidationError({"is_locked": _("Contributor questionnaires cannot be locked.")})
208+
209209
def __lt__(self, other):
210210
return (self.type, self.order, self.pk) < (other.type, other.order, other.pk)
211211

@@ -1470,7 +1470,7 @@ class TextAnswer(Answer):
14701470

14711471
answer = models.TextField(verbose_name=_("answer"))
14721472
# If the text answer was changed during review, original_answer holds the original text. Otherwise, it's null.
1473-
original_answer = models.TextField(verbose_name=_("original answer"), blank=True, null=True)
1473+
original_answer = models.TextField(verbose_name=_("original answer"), blank=True, null=True) # noqa: DJ001
14741474

14751475
class ReviewDecision(models.TextChoices):
14761476
"""
@@ -1613,9 +1613,6 @@ class Infotext(models.Model):
16131613
content_en = models.TextField(verbose_name=_("content (english)"), blank=True)
16141614
content = translate(en="content_en", de="content_de")
16151615

1616-
def is_empty(self):
1617-
return not (self.title or self.content)
1618-
16191616
class Page(models.TextChoices):
16201617
STUDENT_INDEX = ("student_index", "Student index page")
16211618
CONTRIBUTOR_INDEX = ("contributor_index", "Contributor index page")
@@ -1640,6 +1637,9 @@ class Meta:
16401637
),
16411638
)
16421639

1640+
def is_empty(self):
1641+
return not (self.title or self.content)
1642+
16431643

16441644
class UserProfileManager(BaseUserManager):
16451645
def create_user(self, *, email, password=None, first_name=None, last_name=None):

evap/evaluation/models_logging.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ class LoggedModel(models.Model):
128128
class Meta:
129129
abstract = True
130130

131+
def save(self, *args, **kw):
132+
# Are we creating a new instance?
133+
# https://docs.djangoproject.com/en/3.0/ref/models/instances/#customizing-model-loading
134+
if self._state.adding:
135+
# we need to attach a logentry to an existing object, so we save this newly created instance first
136+
super().save(*args, **kw)
137+
self.log_instance_create()
138+
else:
139+
# when saving an existing instance, we get changes by comparing to the version from the database
140+
# therefore we save the instance after building the logentry
141+
self.log_instance_change()
142+
super().save(*args, **kw)
143+
131144
def __init__(self, *args, **kwargs):
132145
super().__init__(*args, **kwargs)
133146
self._logentry = None
@@ -239,19 +252,6 @@ def _update_log(self, changes, action_type: InstanceActionType, store_in_db=True
239252
if store_in_db:
240253
self._logentry.save()
241254

242-
def save(self, *args, **kw):
243-
# Are we creating a new instance?
244-
# https://docs.djangoproject.com/en/3.0/ref/models/instances/#customizing-model-loading
245-
if self._state.adding:
246-
# we need to attach a logentry to an existing object, so we save this newly created instance first
247-
super().save(*args, **kw)
248-
self.log_instance_create()
249-
else:
250-
# when saving an existing instance, we get changes by comparing to the version from the database
251-
# therefore we save the instance after building the logentry
252-
self.log_instance_change()
253-
super().save(*args, **kw)
254-
255255
def delete(self, *args, **kw):
256256
self.log_instance_delete()
257257
self.related_logentries().delete()

evap/staff/importers/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ class InputRow(ABC):
179179
# MyPy is currently broken with abstract properties: https://github.com/python/mypy/issues/8996
180180
column_count: int
181181

182+
@abstractmethod
182183
def __init__(self, location: ExcelFileLocation, *cells: Iterable[str]):
183-
# this can be an abstractmethod from python3.10 on, before it doesn't work with the derived dataclasses
184-
raise NotImplementedError # pragma: no cover
184+
pass
185185

186186
@classmethod
187187
def from_cells(cls, location: ExcelFileLocation, cells: Iterable[str]):

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ extend_skip_glob = ["**/migrations/*"]
2929
# * Formsets use PascalCase
3030

3131
target-version = "py310"
32-
select = ["F", "E", "B", "W", "N", "UP", "YTT", "FIX", "ASYNC", "A"]
32+
select = ["F", "E", "B", "W", "N", "UP", "YTT", "FIX", "ASYNC", "A", "DJ"]
3333
ignore = [
3434
"E501", # line-too-long: black does code formatting for us
3535
"FIX004", # hacks should be possible
3636
"A003",
37+
"DJ008",
3738
]
3839

3940
ignore-init-module-imports = true

0 commit comments

Comments
 (0)