mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Removed CleanerVersion layer [backwards-incompatible!]
This commit is contained in:
@@ -5,11 +5,9 @@ from django import forms
|
||||
from django.core.files import File
|
||||
from django.core.files.storage import default_storage
|
||||
from django.core.files.uploadedfile import UploadedFile
|
||||
from django.db import models
|
||||
from django.forms.models import BaseModelForm, ModelFormMetaclass
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from versions.models import Versionable
|
||||
|
||||
from pretix.base.i18n import I18nFormField
|
||||
from pretix.base.models import Event
|
||||
@@ -30,44 +28,6 @@ class BaseI18nModelForm(BaseModelForm):
|
||||
field.widget.enabled_langcodes = event.settings.get('locales')
|
||||
|
||||
|
||||
class VersionedBaseModelForm(BaseI18nModelForm):
|
||||
"""
|
||||
This is a helperclass to construct VersionedModelForm
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
instance = kwargs.get('instance', None)
|
||||
self.original_instance = copy.copy(instance) if instance else None
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
if self.instance.pk is not None and isinstance(self.instance, Versionable):
|
||||
if self.has_changed() and self.original_instance:
|
||||
new = self.instance
|
||||
old = self.original_instance
|
||||
clone = old.clone()
|
||||
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)
|
||||
|
||||
|
||||
class VersionedModelForm(six.with_metaclass(ModelFormMetaclass, VersionedBaseModelForm)):
|
||||
"""
|
||||
This is a modified version of I18nModelForm which differs from I18nModelForm in
|
||||
only one way: It executes the .clone() method of an object before saving it back to
|
||||
the database, if the model is a sub-class of versions.models.Versionable. You can
|
||||
safely use this as a base class for all your model forms, it will work out correctly
|
||||
with both versioned and non-versioned models.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class I18nModelForm(six.with_metaclass(ModelFormMetaclass, BaseI18nModelForm)):
|
||||
"""
|
||||
This is a modified version of Django's ModelForm which differs from ModelForm in
|
||||
|
||||
Reference in New Issue
Block a user