Skip to content

Commit

Permalink
add DJ checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadus committed Nov 13, 2023
1 parent 23986fd commit 8efe8ce
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
16 changes: 8 additions & 8 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ class Visibility(models.IntegerChoices):

objects = QuestionnaireManager()

def clean(self):
if self.type == self.Type.CONTRIBUTOR and self.is_locked:
raise ValidationError({"is_locked": _("Contributor questionnaires cannot be locked.")})

class Meta:
ordering = ["type", "order", "pk"]
verbose_name = _("questionnaire")
Expand All @@ -206,6 +202,10 @@ class Meta:
def __str__(self):
return self.name

def clean(self):
if self.type == self.Type.CONTRIBUTOR and self.is_locked:
raise ValidationError({"is_locked": _("Contributor questionnaires cannot be locked.")})

def __lt__(self, other):
return (self.type, self.order, self.pk) < (other.type, other.order, other.pk)

Expand Down Expand Up @@ -1470,7 +1470,7 @@ class TextAnswer(Answer):

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

class ReviewDecision(models.TextChoices):
"""
Expand Down Expand Up @@ -1613,9 +1613,6 @@ class Infotext(models.Model):
content_en = models.TextField(verbose_name=_("content (english)"), blank=True)
content = translate(en="content_en", de="content_de")

def is_empty(self):
return not (self.title or self.content)

class Page(models.TextChoices):
STUDENT_INDEX = ("student_index", "Student index page")
CONTRIBUTOR_INDEX = ("contributor_index", "Contributor index page")
Expand All @@ -1640,6 +1637,9 @@ class Meta:
),
)

def is_empty(self):
return not (self.title or self.content)


class UserProfileManager(BaseUserManager):
def create_user(self, *, email, password=None, first_name=None, last_name=None):
Expand Down
26 changes: 13 additions & 13 deletions evap/evaluation/models_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ class LoggedModel(models.Model):
class Meta:
abstract = True

def save(self, *args, **kw):
# Are we creating a new instance?
# https://docs.djangoproject.com/en/3.0/ref/models/instances/#customizing-model-loading
if self._state.adding:
# we need to attach a logentry to an existing object, so we save this newly created instance first
super().save(*args, **kw)
self.log_instance_create()
else:
# when saving an existing instance, we get changes by comparing to the version from the database
# therefore we save the instance after building the logentry
self.log_instance_change()
super().save(*args, **kw)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._logentry = None
Expand Down Expand Up @@ -239,19 +252,6 @@ def _update_log(self, changes, action_type: InstanceActionType, store_in_db=True
if store_in_db:
self._logentry.save()

def save(self, *args, **kw):
# Are we creating a new instance?
# https://docs.djangoproject.com/en/3.0/ref/models/instances/#customizing-model-loading
if self._state.adding:
# we need to attach a logentry to an existing object, so we save this newly created instance first
super().save(*args, **kw)
self.log_instance_create()
else:
# when saving an existing instance, we get changes by comparing to the version from the database
# therefore we save the instance after building the logentry
self.log_instance_change()
super().save(*args, **kw)

def delete(self, *args, **kw):
self.log_instance_delete()
self.related_logentries().delete()
Expand Down
4 changes: 2 additions & 2 deletions evap/staff/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ class InputRow(ABC):
# MyPy is currently broken with abstract properties: https://github.com/python/mypy/issues/8996
column_count: int

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

Check warning on line 184 in evap/staff/importers/base.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/importers/base.py#L184

Added line #L184 was not covered by tests

@classmethod
def from_cells(cls, location: ExcelFileLocation, cells: Iterable[str]):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ extend_skip_glob = ["**/migrations/*"]
# * Formsets use PascalCase

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

ignore-init-module-imports = true
Expand Down

0 comments on commit 8efe8ce

Please sign in to comment.