Fix migrations for trashbin feature
Some checks failed
buildbot/tox Build done.

This commit is contained in:
2020-12-08 19:08:21 +01:00
parent e501ada83f
commit d60f1d9993
6 changed files with 71 additions and 37 deletions

View File

@@ -72,7 +72,7 @@ class Registration(models.Model):
verbose_name=_('Einwilligung zur Datenspeicherung'))
purge_at = models.DateTimeField(_('Zeitpunkt der Datenlöschung'))
answered_2migrate = models.BooleanField(default=False, verbose_name=_('Durch Tourleitung beantwortet'))
answered_obsolete = models.BooleanField(default=False, verbose_name=_('Durch Tourleitung beantwortet'))
@staticmethod
def pk2hexstr(pk):
@@ -156,24 +156,6 @@ Anmerkung:
logger.info('Registration stored: %s', self)
signals.registration_created.send(sender=self.__class__, registration=self)
def answered(self, accepted):
if accepted is not True and accepted is not False:
raise ValueError('boolean parameter expected')
if hasattr(self, 'status'):
status = self.status
else:
status = RegistrationStatus(registration=self)
status.accepted = accepted
status.answered = True
status.save()
def accepted(self):
return self.answered(accepted=True)
def rejected(self):
return self.answered(accepted=False)
@classmethod
def calc_purge_at(cls, event):
if event.alt_last_day:
@@ -217,11 +199,24 @@ class RegistrationStatus(models.Model):
return '{} (Updated: {})'.format(self.registration, self.updated_at.strftime('%d.%m.%Y %H:%M:%S'))
def clean(self):
if self.answered and self.accepted is None:
raise ValidationError({'accepted': 'if answered is true, accepted must not be none'})
elif not self.answered and self.accepted is not None:
raise ValidationError({'answered': 'if answered is false, accepted must be none'})
if self.accepted is not None and self.answered is not True:
raise ValidationError({'answered': 'if accepted is not None, answered must be True'})
def save(self, **kwargs):
self.full_clean()
super(RegistrationStatus, self).save(**kwargs)
def set_accepted(self):
self.accepted = True
self.answered = True
self.save()
def set_rejected(self):
self.accepted = False
self.answered = True
self.save()
def reset(self):
self.accepted = None
self.answered = False
self.save()