mirror of
https://github.com/pretix/pretix.git
synced 2025-12-10 01:12:28 +00:00
Compare commits
1 Commits
dependent-
...
sort-prope
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90d12506f4 |
@@ -555,8 +555,7 @@ class QuestionSerializer(I18nAwareModelSerializer):
|
||||
|
||||
def validate_dependency_question(self, value):
|
||||
if value:
|
||||
if value.type not in (Question.TYPE_CHOICE, Question.TYPE_BOOLEAN, Question.TYPE_CHOICE_MULTIPLE,
|
||||
Question.TYPE_COUNTRYCODE):
|
||||
if value.type not in (Question.TYPE_CHOICE, Question.TYPE_BOOLEAN, Question.TYPE_CHOICE_MULTIPLE):
|
||||
raise ValidationError('Question dependencies can only be set to boolean or choice questions.')
|
||||
if value == self.instance:
|
||||
raise ValidationError('A question cannot depend on itself.')
|
||||
|
||||
@@ -1061,7 +1061,6 @@ class BaseQuestionsForm(forms.Form):
|
||||
return (
|
||||
('True' in qvals and dval)
|
||||
or ('False' in qvals and not dval)
|
||||
or (parentq.type == Question.TYPE_COUNTRYCODE and str(dval) in qvals)
|
||||
or (isinstance(dval, QuestionOption) and dval.identifier in qvals)
|
||||
or (isinstance(dval, (list, QuerySet)) and any(qval in [o.identifier for o in dval] for qval in qvals))
|
||||
)
|
||||
|
||||
@@ -1623,7 +1623,6 @@ class AbstractPosition(RoundingCorrectionMixin, models.Model):
|
||||
return (
|
||||
('True' in qvals and self.answ[parentid].answer == 'True')
|
||||
or ('False' in qvals and self.answ[parentid].answer == 'False')
|
||||
or (parentq.type == Question.TYPE_COUNTRYCODE and self.answ[parentid].answer in qvals)
|
||||
or (any(qval in [o.identifier for o in self.answ[parentid].options.all()] for qval in qvals))
|
||||
)
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ class QuestionForm(I18nModelForm):
|
||||
self.fields['items'].queryset = self.instance.event.items.all()
|
||||
self.fields['items'].required = True
|
||||
self.fields['dependency_question'].queryset = self.instance.event.questions.filter(
|
||||
type__in=(Question.TYPE_BOOLEAN, Question.TYPE_CHOICE, Question.TYPE_CHOICE_MULTIPLE, Question.TYPE_COUNTRYCODE),
|
||||
type__in=(Question.TYPE_BOOLEAN, Question.TYPE_CHOICE, Question.TYPE_CHOICE_MULTIPLE),
|
||||
ask_during_checkin=False
|
||||
)
|
||||
if self.instance.pk:
|
||||
|
||||
@@ -143,7 +143,6 @@
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<script type="text/plain" id="dependency_value_val">{{ form.instance.dependency_values|escapejson_dumps }}</script>
|
||||
<script type="text/plain" id="countries">{{ countries|escapejson_dumps }}</script>
|
||||
{% bootstrap_field form.dependency_values layout="inline" form_group_class="inner" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -91,6 +91,8 @@
|
||||
<div class="col-sm-12">
|
||||
<button type="button" class="btn btn-default" data-formset-add>
|
||||
<i class="fa fa-plus"></i> {% trans "Add a new value" %}</button>
|
||||
<button type="button" class="btn btn-default" data-formset-sort>
|
||||
<i class="fa fa-sort-alpha-asc"></i> {% trans "Sort alphabetically" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -87,7 +87,6 @@ from pretix.control.signals import item_forms, item_formsets
|
||||
from pretix.helpers.models import modelcopy
|
||||
|
||||
from ...helpers.compat import CompatDeleteView
|
||||
from ...helpers.countries import CachedCountries
|
||||
from . import ChartContainingView, CreateView, PaginationMixin, UpdateView
|
||||
|
||||
|
||||
@@ -658,7 +657,6 @@ class QuestionMixin:
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
ctx['formset'] = self.formset
|
||||
ctx['countries'] = [{"id": k, "name": str(c)} for k, c in dict(CachedCountries().countries).items()]
|
||||
return ctx
|
||||
|
||||
|
||||
|
||||
@@ -1058,7 +1058,6 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
return (
|
||||
('True' in qvals and answ[parentid].answer == 'True')
|
||||
or ('False' in qvals and answ[parentid].answer == 'False')
|
||||
or (parentq.type == Question.TYPE_COUNTRYCODE and answ[parentid].answer in qvals)
|
||||
or (any(qval in [o.identifier for o in answ[parentid].options.all()] for qval in qvals))
|
||||
)
|
||||
|
||||
|
||||
@@ -80,6 +80,23 @@ var form_handlers = function (el) {
|
||||
el.find("[data-formset]").on("formAdded", "div", function (event) {
|
||||
form_handlers($(event.target));
|
||||
});
|
||||
el.find("[data-formset] [data-formset-sort]").on("click", function (event) {
|
||||
// Sort forms alphabetically by their first field
|
||||
var $formset = $(this).closest("[data-formset]");
|
||||
var $forms = $formset.find("[data-formset-form]").not("[data-formset-form-deleted]")
|
||||
var compareForms = function(form_a, form_b) {
|
||||
var a = $(form_a).find('input:not([name*=-ORDER]):not([name*=-DELETE]):not([name*=-id])').val();
|
||||
var b = $(form_b).find('input:not([name*=-ORDER]):not([name*=-DELETE]):not([name*=-id])').val();
|
||||
return a.localeCompare(b);
|
||||
}
|
||||
$forms = $forms.sort(compareForms);
|
||||
$forms.each(function(i, form) {
|
||||
var $order = $(form).find('[name*=-ORDER]');
|
||||
$order.val(i + 1);
|
||||
});
|
||||
// Trigger visual reorder
|
||||
$formset.find("[name*=-ORDER]").first().trigger("change");
|
||||
});
|
||||
|
||||
// Vouchers
|
||||
el.find("#voucher-bulk-codes-generate").click(function () {
|
||||
|
||||
@@ -114,7 +114,6 @@ $(function () {
|
||||
var $val = $("#id_dependency_values");
|
||||
var $dq = $("#id_dependency_question");
|
||||
var oldval = JSON.parse($("#dependency_value_val").text());
|
||||
var countries = JSON.parse($("#countries").text());
|
||||
function update_dependency_options() {
|
||||
$val.parent().find(".loading-indicator").remove();
|
||||
$("#id_dependency_values option").remove();
|
||||
@@ -136,10 +135,6 @@ $(function () {
|
||||
if (data.type === "B") {
|
||||
$val.append($("<option>").attr("value", "True").text(gettext("Yes")));
|
||||
$val.append($("<option>").attr("value", "False").text(gettext("No")));
|
||||
} else if (data.type === "CC") {
|
||||
for (var c of countries) {
|
||||
$val.append($("<option>").attr("value", c.id).text(c.name));
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < data.options.length; i++) {
|
||||
var opt = data.options[i];
|
||||
|
||||
@@ -11,7 +11,7 @@ function questions_toggle_dependent(ev) {
|
||||
var $dependency_el;
|
||||
|
||||
if ($("select[name=" + dependency_name + "]").length) {
|
||||
// dependency is type C or CC
|
||||
// dependency is type C
|
||||
$dependency_el = $("select[name=" + dependency_name + "]");
|
||||
if (!$dependency_el.closest(".form-group").hasClass("dependency-hidden")) { // do not show things that depend on hidden things
|
||||
return q_should_be_shown($dependency_el) && $.inArray($dependency_el.val(), dependency_values) > -1;
|
||||
|
||||
Reference in New Issue
Block a user