mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Moved question<>item relation to the question side
Cleared migration history
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import copy
|
||||
|
||||
from django import forms
|
||||
from django.db import models
|
||||
from django.forms import BooleanField
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@@ -40,6 +41,10 @@ class PropertyValueForm(TolerantFormsetModelForm):
|
||||
|
||||
|
||||
class QuestionForm(VersionedModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['items'].queryset = self.instance.event.items.current.all()
|
||||
|
||||
class Meta:
|
||||
model = Question
|
||||
localized_fields = '__all__'
|
||||
@@ -47,7 +52,11 @@ class QuestionForm(VersionedModelForm):
|
||||
'question',
|
||||
'type',
|
||||
'required',
|
||||
'items'
|
||||
]
|
||||
widgets = {
|
||||
'items': forms.CheckboxSelectMultiple
|
||||
}
|
||||
|
||||
|
||||
class QuotaForm(I18nModelForm):
|
||||
@@ -116,7 +125,6 @@ class ItemFormGeneral(VersionedModelForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['category'].queryset = self.instance.event.categories.current.all()
|
||||
self.fields['properties'].queryset = self.instance.event.properties.current.all()
|
||||
self.fields['questions'].queryset = self.instance.event.questions.current.all()
|
||||
|
||||
class Meta:
|
||||
model = Item
|
||||
@@ -126,13 +134,11 @@ class ItemFormGeneral(VersionedModelForm):
|
||||
'name',
|
||||
'active',
|
||||
'admission',
|
||||
'short_description',
|
||||
'long_description',
|
||||
'description',
|
||||
'picture',
|
||||
'default_price',
|
||||
'tax_rate',
|
||||
'properties',
|
||||
'questions',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
<fieldset>
|
||||
<legend>{% trans "Advanced settings" %}</legend>
|
||||
{% bootstrap_field form.properties layout="horizontal" %}
|
||||
{% bootstrap_field form.questions layout="horizontal" %}
|
||||
</fieldset>
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
|
||||
@@ -3,36 +3,41 @@
|
||||
{% load bootstrap3 %}
|
||||
{% block title %}{% trans "Question" %}{% endblock %}
|
||||
{% block inside %}
|
||||
<h1>{% trans "Question" %}</h1>
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<legend>{% trans "General information" %}</legend>
|
||||
{% bootstrap_field form.question layout="horizontal" %}
|
||||
{% bootstrap_field form.type layout="horizontal" %}
|
||||
{% bootstrap_field form.required layout="horizontal" %}
|
||||
</fieldset>
|
||||
<h1>{% trans "Question" %}</h1>
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<legend>{% trans "General information" %}</legend>
|
||||
{% bootstrap_field form.question layout="horizontal" %}
|
||||
{% bootstrap_field form.type layout="horizontal" %}
|
||||
{% bootstrap_field form.required layout="horizontal" %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{% trans "Apply to products" %}</legend>
|
||||
{% bootstrap_field form.items layout="horizontal" %}
|
||||
</fieldset>
|
||||
<div class="alert alert-info alert-required-boolean">
|
||||
{% blocktrans trimmed %}
|
||||
If you mark a Yes/No question as required, it means that the user has to select Yes and No is not
|
||||
accepted. If you want to allow both options, do not make this field required.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
<div class="form-group submit-group">
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
function alert_required_boolean() {
|
||||
var show = $("#id_type").val() == "B" && $("#id_required").prop("checked");
|
||||
$(".alert-required-boolean").toggle(show);
|
||||
}
|
||||
$("#id_type").change(alert_required_boolean);
|
||||
$("#id_required").change(alert_required_boolean);
|
||||
alert_required_boolean();
|
||||
});
|
||||
$(function () {
|
||||
function alert_required_boolean() {
|
||||
var show = $("#id_type").val() == "B" && $("#id_required").prop("checked");
|
||||
$(".alert-required-boolean").toggle(show);
|
||||
}
|
||||
|
||||
$("#id_type").change(alert_required_boolean);
|
||||
$("#id_required").change(alert_required_boolean);
|
||||
alert_required_boolean();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -466,6 +466,11 @@ class QuestionCreate(EventPermissionRequiredMixin, CreateView):
|
||||
permission = 'can_change_items'
|
||||
context_object_name = 'question'
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['instance'] = Question(event=self.request.event)
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self) -> str:
|
||||
return reverse('control:event.items.questions', kwargs={
|
||||
'organizer': self.request.event.organizer.slug,
|
||||
@@ -473,7 +478,6 @@ class QuestionCreate(EventPermissionRequiredMixin, CreateView):
|
||||
})
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.event = self.request.event
|
||||
messages.success(self.request, _('The new question has been created.'))
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user