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

@@ -27,11 +27,6 @@ class Migration(migrations.Migration):
'ordering': ['updated_at'],
},
),
migrations.RenameField(
model_name='registration',
old_name='answered',
new_name='answered_2migrate',
),
migrations.AddField(
model_name='registrationstatus',
name='registration',

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-12-08 17:53
from __future__ import unicode_literals
from django.db import migrations
def migrate_registration_status(apps, schema_editor):
Registration = apps.get_model('dav_registration', 'Registration')
RegistrationStatus = apps.get_model('dav_registration', 'RegistrationStatus')
db_alias = schema_editor.connection.alias
for r in Registration.objects.using(db_alias).all():
s = RegistrationStatus(registration=r)
s.answered = r.answered
s.save()
class Migration(migrations.Migration):
dependencies = [
('dav_registration', '0006_auto_20201203_1144'),
]
operations = [
migrations.RunPython(migrate_registration_status),
]

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-12-08 18:06
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dav_registration', '0007_auto_20201208_1853'),
]
operations = [
migrations.RenameField(
model_name='registration',
old_name='answered',
new_name='answered_obsolete',
),
]

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()