mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Manage variations for items with exactly two properties
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
{% extends "tixlcontrol/item/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% block inside %}
|
||||||
|
<h2>{% trans "Variations" %}</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
{% for val in properties.1.values.all %}
|
||||||
|
<th>{{ val.value }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for sub in forms %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ sub.0.subval.value }}</td>
|
||||||
|
{% for form in sub %}
|
||||||
|
<td>
|
||||||
|
{% bootstrap_field form.active layout='inline' %}
|
||||||
|
{% bootstrap_field form.default_price layout='inline' %}
|
||||||
|
{{ form.default_price.errors }}
|
||||||
|
</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
{% trans "Save" %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -119,22 +119,46 @@ class ItemVariations(TemplateView, SingleObjectMixin):
|
|||||||
data = self.request.POST if self.request.method == 'POST' else None
|
data = self.request.POST if self.request.method == 'POST' else None
|
||||||
if self.dimension == 1:
|
if self.dimension == 1:
|
||||||
for var in variations:
|
for var in variations:
|
||||||
val = [i[1] for i in sorted([it for it in var.items() if it[0] != 'variation'])]
|
val = [var[self.properties[0].pk]]
|
||||||
if 'variation' in var:
|
if 'variation' in var:
|
||||||
form = ItemVariationForm(
|
form = ItemVariationForm(
|
||||||
data,
|
data,
|
||||||
instance=var['variation'],
|
instance=var['variation'],
|
||||||
prefix=",".join([str(i) for i in val])
|
prefix=val[0].pk,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
form = ItemVariationForm(
|
form = ItemVariationForm(
|
||||||
data,
|
data,
|
||||||
instance=ItemVariation(item=self.object),
|
instance=ItemVariation(item=self.object),
|
||||||
prefix=",".join([str(i) for i in val])
|
prefix=val[0].pk,
|
||||||
)
|
)
|
||||||
form.values = val
|
form.values = val
|
||||||
forms.append(form)
|
forms.append(form)
|
||||||
forms_flat = forms
|
forms_flat = forms
|
||||||
|
elif self.dimension == 2:
|
||||||
|
prop1 = self.properties[0]
|
||||||
|
prop2 = self.properties[1]
|
||||||
|
for val1 in prop1.values.all():
|
||||||
|
thisforms = []
|
||||||
|
for var in [v for v in variations if v[prop1.pk].pk == val1.pk]:
|
||||||
|
val = [i[1] for i in sorted([it for it in var.items() if it[0] != 'variation'])]
|
||||||
|
if 'variation' in var:
|
||||||
|
form = ItemVariationForm(
|
||||||
|
data,
|
||||||
|
instance=var['variation'],
|
||||||
|
prefix=",".join([str(i.pk) for i in val])
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
form = ItemVariationForm(
|
||||||
|
data,
|
||||||
|
instance=ItemVariation(item=self.object),
|
||||||
|
prefix=",".join([str(i.pk) for i in val])
|
||||||
|
)
|
||||||
|
form.values = val
|
||||||
|
form.subval = var[prop1.pk]
|
||||||
|
thisforms.append(form)
|
||||||
|
forms_flat.append(form)
|
||||||
|
forms.append(thisforms)
|
||||||
return forms, forms_flat
|
return forms, forms_flat
|
||||||
|
|
||||||
def main(self, request, *args, **kwargs):
|
def main(self, request, *args, **kwargs):
|
||||||
@@ -171,6 +195,8 @@ class ItemVariations(TemplateView, SingleObjectMixin):
|
|||||||
def get_template_names(self):
|
def get_template_names(self):
|
||||||
if self.dimension == 1:
|
if self.dimension == 1:
|
||||||
return ['tixlcontrol/item/variations_1d.html']
|
return ['tixlcontrol/item/variations_1d.html']
|
||||||
|
elif self.dimension == 2:
|
||||||
|
return ['tixlcontrol/item/variations_2d.html']
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user