Add a kind of trashbin for registrations and participants
All checks were successful
buildbot/tox Build done.
All checks were successful
buildbot/tox Build done.
This commit is contained in:
@@ -72,8 +72,6 @@ class Registration(models.Model):
|
||||
verbose_name=_('Einwilligung zur Datenspeicherung'))
|
||||
purge_at = models.DateTimeField(_('Zeitpunkt der Datenlöschung'))
|
||||
|
||||
answered = models.BooleanField(_('Durch Tourleitung beantwortet'), default=False)
|
||||
|
||||
@staticmethod
|
||||
def pk2hexstr(pk):
|
||||
return hex(pk * 113)[2:] # 113 has no meaning, but it produce nice looking hex codes.
|
||||
@@ -151,9 +149,29 @@ Anmerkung:
|
||||
super(Registration, self).save(**kwargs)
|
||||
|
||||
if creating:
|
||||
status = RegistrationStatus(registration=self)
|
||||
status.save()
|
||||
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:
|
||||
@@ -179,3 +197,29 @@ Anmerkung:
|
||||
purge_date = july_nextyear
|
||||
|
||||
return timezone.make_aware(datetime.datetime.combine(purge_date, midnight))
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class RegistrationStatus(models.Model):
|
||||
registration = models.OneToOneField(Registration, on_delete=models.CASCADE, related_name='status')
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
answered = models.BooleanField(_('Durch Tourleitung beantwortet'), default=False)
|
||||
accepted = models.NullBooleanField(_('Zusage erteilt'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Anmeldungsstatus')
|
||||
verbose_name_plural = _('Anmeldungsstati')
|
||||
ordering = ['updated_at']
|
||||
|
||||
def __str__(self):
|
||||
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'})
|
||||
|
||||
def save(self, **kwargs):
|
||||
self.full_clean()
|
||||
super(RegistrationStatus, self).save(**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user