mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
category_type refactoring
This commit is contained in:
@@ -220,21 +220,31 @@ class ItemCategory(LoggedModel):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
name = self.internal_name or self.name
|
name = self.internal_name or self.name
|
||||||
if self.is_addon:
|
category_type = self.get_category_type_display()
|
||||||
return _('{category} (Add-On products)').format(category=str(name))
|
if category_type:
|
||||||
if self.cross_selling_mode is not None:
|
return _('{category} ({category_type})').format(category=str(name), category_type=category_type)
|
||||||
return _('{category} ({category_type})').format(category=str(name), category_type=self.get_cross_selling_mode_display())
|
|
||||||
return str(name)
|
return str(name)
|
||||||
|
|
||||||
def get_category_type_display(self):
|
def get_category_type_display(self):
|
||||||
if self.is_addon:
|
if self.is_addon:
|
||||||
return _('Add-On products')
|
return _('Add-On products')
|
||||||
|
elif self.cross_selling_mode:
|
||||||
|
return self.get_cross_selling_mode_display()
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def category_type(self):
|
def category_type(self):
|
||||||
return 'addon' if self.is_addon else 'normal'
|
return 'addon' if self.is_addon else self.cross_selling_mode or 'normal'
|
||||||
|
|
||||||
|
@category_type.setter
|
||||||
|
def category_type(self, new_value):
|
||||||
|
if new_value == 'addon':
|
||||||
|
self.is_addon = True
|
||||||
|
self.cross_selling_mode = None
|
||||||
|
else:
|
||||||
|
self.is_addon = False
|
||||||
|
self.cross_selling_mode = None if new_value == 'normal' else new_value
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
super().delete(*args, **kwargs)
|
super().delete(*args, **kwargs)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class CategoryForm(I18nModelForm):
|
|||||||
_('Combined category'), _('Products in this category are regular products displayed on the front page, '
|
_('Combined category'), _('Products in this category are regular products displayed on the front page, '
|
||||||
'but are additionally shown in the cross-selling step, according to the configuration below.'))),),
|
'but are additionally shown in the cross-selling step, according to the configuration below.'))),),
|
||||||
))
|
))
|
||||||
self.fields['category_type'].initial = 'addon' if self.instance.is_addon else (self.instance.cross_selling_mode or 'normal')
|
self.fields['category_type'].initial = self.instance.category_type
|
||||||
|
|
||||||
self.fields['cross_selling_condition'].widget.attrs['data-display-dependency'] = '#id_category_type_2,#id_category_type_3'
|
self.fields['cross_selling_condition'].widget.attrs['data-display-dependency'] = '#id_category_type_2,#id_category_type_3'
|
||||||
self.fields['cross_selling_condition'].widget.attrs['data-disable-dependent'] = 'true'
|
self.fields['cross_selling_condition'].widget.attrs['data-disable-dependent'] = 'true'
|
||||||
@@ -131,14 +131,7 @@ class CategoryForm(I18nModelForm):
|
|||||||
if d.get('category_type') == 'only' or d.get('category_type') == 'both':
|
if d.get('category_type') == 'only' or d.get('category_type') == 'both':
|
||||||
if not d.get('cross_selling_condition'):
|
if not d.get('cross_selling_condition'):
|
||||||
raise ValidationError({'cross_selling_condition': [_('This field is required')]})
|
raise ValidationError({'cross_selling_condition': [_('This field is required')]})
|
||||||
self.instance.cross_selling_mode = d.get('category_type')
|
self.instance.category_type = d.get('category_type')
|
||||||
else:
|
|
||||||
self.instance.cross_selling_mode = None
|
|
||||||
if d.get('category_type') == 'only' or d.get('category_type') == 'both' or d.get('category_type') == 'normal':
|
|
||||||
self.instance.is_addon = False
|
|
||||||
elif d.get('category_type') == 'addon':
|
|
||||||
self.instance.is_addon = True
|
|
||||||
d['category_type'] = 'normal'
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,11 +42,7 @@
|
|||||||
<strong><a href="{% url "control:event.items.categories.edit" organizer=request.event.organizer.slug event=request.event.slug category=c.id %}">{{ c.internal_name|default:c.name }}</a></strong>
|
<strong><a href="{% url "control:event.items.categories.edit" organizer=request.event.organizer.slug event=request.event.slug category=c.id %}">{{ c.internal_name|default:c.name }}</a></strong>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if c.is_addon %}{% trans "Add-on product category" %}
|
{{ c.get_category_type_display }}
|
||||||
{% elif c.cross_selling_mode is None %}{% trans "Normal category" %}
|
|
||||||
{% elif c.cross_selling_mode == 'both' %}{% trans "Combined category" %}
|
|
||||||
{% elif c.cross_selling_mode == 'only' %}{% trans "Cross-selling category" %}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right flip">
|
<td class="text-right flip">
|
||||||
<button title="{% trans "Move up" %}" formaction="{% url "control:event.items.categories.up" organizer=request.event.organizer.slug event=request.event.slug category=c.id %}" class="btn btn-default btn-sm sortable-up"{% if forloop.counter0 == 0 and not page_obj.has_previous %} disabled{% endif %}><i class="fa fa-arrow-up"></i></button>
|
<button title="{% trans "Move up" %}" formaction="{% url "control:event.items.categories.up" organizer=request.event.organizer.slug event=request.event.slug category=c.id %}" class="btn btn-default btn-sm sortable-up"{% if forloop.counter0 == 0 and not page_obj.has_previous %} disabled{% endif %}><i class="fa fa-arrow-up"></i></button>
|
||||||
|
|||||||
Reference in New Issue
Block a user