forked from CGM_Public/pretix_original
Removed CleanerVersion layer [backwards-incompatible!]
This commit is contained in:
@@ -14,7 +14,7 @@ from django.utils.html import format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.forms import VersionedModelForm
|
||||
from pretix.base.forms import I18nModelForm
|
||||
from pretix.base.models import Item, ItemVariation
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ class I18nFormSet(BaseModelFormSet):
|
||||
return form
|
||||
|
||||
|
||||
class TolerantFormsetModelForm(VersionedModelForm):
|
||||
class TolerantFormsetModelForm(I18nModelForm):
|
||||
"""
|
||||
This is equivalent to a normal VersionedModelForm, but works around a problem that
|
||||
This is equivalent to a normal I18nModelForm, but works around a problem that
|
||||
arises when the form is used inside a FormSet with can_order=True and django-formset-js
|
||||
enabled. In this configuration, even empty "extra" forms might have an ORDER value
|
||||
sent and Django marks the form as empty and raises validation errors because the other
|
||||
@@ -105,15 +105,15 @@ def selector(values, prop):
|
||||
# properties they belong to EXCEPT the value for the property prop2.
|
||||
# We'll see later why we need this.
|
||||
return [
|
||||
v.identity for v in sorted(values, key=lambda v: v.prop.identity)
|
||||
if v.prop.identity != prop.identity
|
||||
v.id for v in sorted(values, key=lambda v: v.prop.id)
|
||||
if v.prop.id != prop.id
|
||||
]
|
||||
|
||||
|
||||
def sort(v, prop):
|
||||
# Given a list of variations, this will sort them by their position
|
||||
# on the x-axis
|
||||
return v[prop.identity].sortkey
|
||||
return v[prop.id].sortkey
|
||||
|
||||
|
||||
class VariationsFieldRenderer(forms.widgets.CheckboxFieldRenderer):
|
||||
@@ -175,7 +175,7 @@ class VariationsFieldRenderer(forms.widgets.CheckboxFieldRenderer):
|
||||
final_attrs['checked'] = 'checked'
|
||||
w = self.choice_input_class(
|
||||
self.name, self.value, self.attrs.copy(),
|
||||
(variation['key'], variation[properties[0].identity].value),
|
||||
(variation['key'], variation[properties[0].id].value),
|
||||
i
|
||||
)
|
||||
output.append(format_html('<li>{0}</li>', force_text(w)))
|
||||
@@ -185,15 +185,15 @@ class VariationsFieldRenderer(forms.widgets.CheckboxFieldRenderer):
|
||||
def render_nd(self, output, variations, properties):
|
||||
# prop1 is the property on all the grid's y-axes
|
||||
prop1 = properties[0]
|
||||
prop1v = list(prop1.values.current.all())
|
||||
prop1v = list(prop1.values.all())
|
||||
# prop2 is the property on all the grid's x-axes
|
||||
prop2 = properties[1]
|
||||
prop2v = list(prop2.values.current.all())
|
||||
prop2v = list(prop2.values.all())
|
||||
|
||||
# We now iterate over the cartesian product of all the other
|
||||
# properties which are NOT on the axes of the grid because we
|
||||
# create one grid for any combination of them.
|
||||
for gridrow in product(*[prop.values.current.all() for prop in properties[2:]]):
|
||||
for gridrow in product(*[prop.values.all() for prop in properties[2:]]):
|
||||
if len(gridrow) > 0:
|
||||
output.append('<strong>')
|
||||
output.append(", ".join([str(value.value) for value in gridrow]))
|
||||
@@ -281,7 +281,7 @@ class VariationsField(forms.ModelMultipleChoiceField):
|
||||
variations = self.item.get_all_variations(use_cache=True)
|
||||
return (
|
||||
(
|
||||
v['variation'].identity if 'variation' in v else v.key(),
|
||||
v['variation'].id if 'variation' in v else v.key(),
|
||||
v
|
||||
) for v in variations
|
||||
)
|
||||
@@ -312,10 +312,10 @@ class VariationsField(forms.ModelMultipleChoiceField):
|
||||
|
||||
cleaned_value = self._clean_value(value)
|
||||
|
||||
qs = self.item.variations.current.filter(identity__in=cleaned_value)
|
||||
qs = self.item.variations.filter(id__in=cleaned_value)
|
||||
|
||||
# Re-check for consistency
|
||||
pks = set(force_text(getattr(o, "identity")) for o in qs)
|
||||
pks = set(force_text(getattr(o, "id")) for o in qs)
|
||||
for val in cleaned_value:
|
||||
if force_text(val) not in pks:
|
||||
raise ValidationError(
|
||||
@@ -335,7 +335,7 @@ class VariationsField(forms.ModelMultipleChoiceField):
|
||||
# which uses a very similar method
|
||||
all_variations = self.item.variations.all().prefetch_related("values")
|
||||
variations_cache = {
|
||||
var.to_variation_dict().identify(): var.identity for var in all_variations
|
||||
var.to_variation_dict().identify(): var.id for var in all_variations
|
||||
}
|
||||
|
||||
cleaned_value = []
|
||||
@@ -360,7 +360,7 @@ class VariationsField(forms.ModelMultipleChoiceField):
|
||||
|
||||
# No ItemVariation present, create one!
|
||||
var = ItemVariation()
|
||||
var.item_id = self.item.identity
|
||||
var.item_id = self.item.id
|
||||
var.save()
|
||||
# Add the values to the ItemVariation object
|
||||
try:
|
||||
@@ -371,8 +371,8 @@ class VariationsField(forms.ModelMultipleChoiceField):
|
||||
code='invalid_pk_value',
|
||||
params={'pk': value},
|
||||
)
|
||||
variations_cache[key] = var.identity
|
||||
cleaned_value.append(str(var.identity))
|
||||
variations_cache[key] = var.id
|
||||
cleaned_value.append(str(var.id))
|
||||
else:
|
||||
# An ItemVariation id was given
|
||||
cleaned_value.append(pk)
|
||||
|
||||
@@ -4,11 +4,11 @@ from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pytz import common_timezones
|
||||
|
||||
from pretix.base.forms import SettingsForm, VersionedModelForm
|
||||
from pretix.base.forms import I18nModelForm, SettingsForm
|
||||
from pretix.base.models import Event
|
||||
|
||||
|
||||
class EventCreateForm(VersionedModelForm):
|
||||
class EventCreateForm(I18nModelForm):
|
||||
error_messages = {
|
||||
'duplicate_slug': _("You already used this slug for a different event. Please choose a new one."),
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class EventCreateForm(VersionedModelForm):
|
||||
return slug
|
||||
|
||||
|
||||
class EventUpdateForm(VersionedModelForm):
|
||||
class EventUpdateForm(I18nModelForm):
|
||||
def clean_slug(self):
|
||||
return self.instance.slug
|
||||
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import copy
|
||||
|
||||
from django import forms
|
||||
from django.db import models
|
||||
from django.forms import BooleanField
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.forms import I18nModelForm, VersionedModelForm
|
||||
from pretix.base.forms import I18nModelForm
|
||||
from pretix.base.models import (
|
||||
Item, ItemCategory, ItemVariation, Property, PropertyValue, Question,
|
||||
Quota, Versionable,
|
||||
Quota,
|
||||
)
|
||||
from pretix.control.forms import TolerantFormsetModelForm, VariationsField
|
||||
|
||||
|
||||
class CategoryForm(VersionedModelForm):
|
||||
class CategoryForm(I18nModelForm):
|
||||
class Meta:
|
||||
model = ItemCategory
|
||||
localized_fields = '__all__'
|
||||
@@ -22,7 +21,7 @@ class CategoryForm(VersionedModelForm):
|
||||
]
|
||||
|
||||
|
||||
class PropertyForm(VersionedModelForm):
|
||||
class PropertyForm(I18nModelForm):
|
||||
class Meta:
|
||||
model = Property
|
||||
localized_fields = '__all__'
|
||||
@@ -40,10 +39,10 @@ class PropertyValueForm(TolerantFormsetModelForm):
|
||||
]
|
||||
|
||||
|
||||
class QuestionForm(VersionedModelForm):
|
||||
class QuestionForm(I18nModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['items'].queryset = self.instance.event.items.current.all()
|
||||
self.fields['items'].queryset = self.instance.event.items.all()
|
||||
|
||||
class Meta:
|
||||
model = Question
|
||||
@@ -60,10 +59,6 @@ class QuestionForm(VersionedModelForm):
|
||||
|
||||
|
||||
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):
|
||||
items = kwargs['items']
|
||||
@@ -72,7 +67,7 @@ class QuotaForm(I18nModelForm):
|
||||
self.original_instance = copy.copy(instance) if instance else None
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if hasattr(self, 'instance'):
|
||||
if hasattr(self, 'instance') and self.instance.pk:
|
||||
active_items = set(self.instance.items.all())
|
||||
active_variations = set(self.instance.variations.all())
|
||||
else:
|
||||
@@ -81,36 +76,19 @@ class QuotaForm(I18nModelForm):
|
||||
|
||||
for item in items:
|
||||
if len(item.properties.all()) > 0:
|
||||
self.fields['item_%s' % item.identity] = VariationsField(
|
||||
self.fields['item_%s' % item.id] = VariationsField(
|
||||
item, label=_("Activate for"),
|
||||
required=False,
|
||||
initial=active_variations
|
||||
)
|
||||
self.fields['item_%s' % item.identity].set_item(item)
|
||||
self.fields['item_%s' % item.id].set_item(item)
|
||||
else:
|
||||
self.fields['item_%s' % item.identity] = BooleanField(
|
||||
self.fields['item_%s' % item.id] = BooleanField(
|
||||
label=_("Activate"),
|
||||
required=False,
|
||||
initial=(item in active_items)
|
||||
)
|
||||
|
||||
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_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)
|
||||
|
||||
class Meta:
|
||||
model = Quota
|
||||
localized_fields = '__all__'
|
||||
@@ -120,10 +98,10 @@ class QuotaForm(I18nModelForm):
|
||||
]
|
||||
|
||||
|
||||
class ItemFormGeneral(VersionedModelForm):
|
||||
class ItemFormGeneral(I18nModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['category'].queryset = self.instance.event.categories.current.all()
|
||||
self.fields['category'].queryset = self.instance.event.categories.all()
|
||||
|
||||
class Meta:
|
||||
model = Item
|
||||
@@ -142,7 +120,7 @@ class ItemFormGeneral(VersionedModelForm):
|
||||
]
|
||||
|
||||
|
||||
class ItemVariationForm(VersionedModelForm):
|
||||
class ItemVariationForm(I18nModelForm):
|
||||
class Meta:
|
||||
model = ItemVariation
|
||||
localized_fields = '__all__'
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from pretix.base.forms import VersionedModelForm
|
||||
from pretix.base.forms import I18nModelForm
|
||||
from pretix.base.models import Order
|
||||
|
||||
|
||||
class ExtendForm(VersionedModelForm):
|
||||
class ExtendForm(I18nModelForm):
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = ['expires']
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.forms import VersionedModelForm
|
||||
from pretix.base.forms import I18nModelForm
|
||||
from pretix.base.models import Organizer
|
||||
|
||||
|
||||
class OrganizerForm(VersionedModelForm):
|
||||
class OrganizerForm(I18nModelForm):
|
||||
error_messages = {
|
||||
'duplicate_slug': _("This slug is already in use. Please choose a different one."),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user