mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Fixed versioning in the Quota admin
This commit is contained in:
@@ -31,7 +31,7 @@ class Versionable(BaseVersionable):
|
|||||||
"""
|
"""
|
||||||
This behaves like clone(), but misses all the Many2Many-relation-handling. This is
|
This behaves like clone(), but misses all the Many2Many-relation-handling. This is
|
||||||
a performance optimization for cases in which we have to handle the Many2Many relations
|
a performance optimization for cases in which we have to handle the Many2Many relations
|
||||||
by handy anyways.
|
by hand anyways.
|
||||||
"""
|
"""
|
||||||
if not self.pk:
|
if not self.pk:
|
||||||
raise ValueError('Instance must be saved before it can be cloned')
|
raise ValueError('Instance must be saved before it can be cloned')
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import copy
|
||||||
|
from django.db import models
|
||||||
from django.forms import BooleanField
|
from django.forms import BooleanField
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from pretix.base.forms import VersionedModelForm, I18nModelForm
|
from pretix.base.forms import VersionedModelForm, I18nModelForm
|
||||||
@@ -46,9 +48,16 @@ class QuestionForm(VersionedModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class QuotaForm(I18nModelForm):
|
class QuotaForm(I18nModelForm):
|
||||||
|
"""
|
||||||
|
The form for quotas does not derive from VersionedModelForm as it does not
|
||||||
|
perform a 'full clone' as part of a performance optimization
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
items = kwargs['items']
|
items = kwargs['items']
|
||||||
del kwargs['items']
|
del kwargs['items']
|
||||||
|
instance = kwargs.get('instance', None)
|
||||||
|
self.original_instance = copy.copy(instance) if instance else None
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if hasattr(self, 'instance'):
|
if hasattr(self, 'instance'):
|
||||||
@@ -75,8 +84,19 @@ class QuotaForm(I18nModelForm):
|
|||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
if self.instance.pk is not None and isinstance(self.instance, Versionable):
|
if self.instance.pk is not None and isinstance(self.instance, Versionable):
|
||||||
if self.has_changed():
|
if self.has_changed() and self.original_instance:
|
||||||
self.instance = self.instance.clone_shallow()
|
new = self.instance
|
||||||
|
old = self.original_instance
|
||||||
|
clone = old.clone_shallow()
|
||||||
|
for f in type(self.instance)._meta.get_fields():
|
||||||
|
if f.name not in (
|
||||||
|
'id', 'identity', 'version_start_date', 'version_end_date',
|
||||||
|
'version_birth_date'
|
||||||
|
) and not isinstance(f, (
|
||||||
|
models.ManyToOneRel, models.ManyToManyRel, models.ManyToManyField
|
||||||
|
)):
|
||||||
|
setattr(clone, f.name, getattr(new, f.name))
|
||||||
|
self.instance = clone
|
||||||
return super().save(commit)
|
return super().save(commit)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
Reference in New Issue
Block a user