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:
@@ -1,8 +1,12 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Registration
|
||||
from .models import Registration, RegistrationStatus
|
||||
|
||||
|
||||
class RegistrationStatusInline(admin.StackedInline):
|
||||
model = RegistrationStatus
|
||||
|
||||
|
||||
@admin.register(Registration)
|
||||
class RegistrationAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
inlines = [RegistrationStatusInline]
|
||||
|
||||
39
dav_registration/migrations/0006_auto_20201203_1144.py
Normal file
39
dav_registration/migrations/0006_auto_20201203_1144.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2020-12-03 10:44
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dav_registration', '0005_auto_20201015_1738'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='RegistrationStatus',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('answered', models.BooleanField(default=False, verbose_name='Durch Tourleitung beantwortet')),
|
||||
('accepted', models.NullBooleanField(verbose_name='Zusage erteilt')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Anmeldungsstatus',
|
||||
'verbose_name_plural': 'Anmeldungsstati',
|
||||
'ordering': ['updated_at'],
|
||||
},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='registration',
|
||||
name='answered',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='registrationstatus',
|
||||
name='registration',
|
||||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='status', to='dav_registration.Registration'),
|
||||
),
|
||||
]
|
||||
@@ -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