Add hidden questions

This commit is contained in:
Raphael Michel
2019-05-09 09:02:21 +02:00
parent 35ddd8dd28
commit e7c4121745
9 changed files with 47 additions and 3 deletions

View File

@@ -38,6 +38,8 @@ identifier string An arbitrary st
ask_during_checkin boolean If ``true``, this question will not be asked while
buying the ticket, but will show up when redeeming
the ticket instead.
hidden boolean If ``true``, the question will only be shown in the
backend.
options list of objects In case of question type ``C`` or ``M``, this lists the
available objects. Only writable during creation,
use separate endpoint to modify this later.
@@ -68,6 +70,10 @@ dependency_value string The value ``dep
Write methods have been added. The attribute ``identifier`` has been added to both the resource itself and the
options resource. The ``position`` attribute has been added to the options resource.
.. versionchanged:: 2.7
The attribute ``hidden`` has been added.
Endpoints
---------
@@ -110,6 +116,7 @@ Endpoints
"position": 1,
"identifier": "WY3TP9SL",
"ask_during_checkin": false,
"hidden": false,
"dependency_question": null,
"dependency_value": null,
"options": [
@@ -177,6 +184,7 @@ Endpoints
"position": 1,
"identifier": "WY3TP9SL",
"ask_during_checkin": false,
"hidden": false,
"dependency_question": null,
"dependency_value": null,
"options": [
@@ -228,6 +236,7 @@ Endpoints
"items": [1, 2],
"position": 1,
"ask_during_checkin": false,
"hidden": false,
"dependency_question": null,
"dependency_value": null,
"options": [
@@ -261,6 +270,7 @@ Endpoints
"position": 1,
"identifier": "WY3TP9SL",
"ask_during_checkin": false,
"hidden": false,
"dependency_question": null,
"dependency_value": null,
"options": [
@@ -332,6 +342,7 @@ Endpoints
"position": 2,
"identifier": "WY3TP9SL",
"ask_during_checkin": false,
"hidden": false,
"dependency_question": null,
"dependency_value": null,
"options": [

View File

@@ -207,7 +207,8 @@ class QuestionSerializer(I18nAwareModelSerializer):
class Meta:
model = Question
fields = ('id', 'question', 'type', 'required', 'items', 'options', 'position',
'ask_during_checkin', 'identifier', 'dependency_question', 'dependency_value')
'ask_during_checkin', 'identifier', 'dependency_question', 'dependency_value',
'hidden')
def validate_identifier(self, value):
Question._clean_identifier(self.context['event'], value, self.instance)

View File

@@ -0,0 +1,21 @@
# Generated by Django 2.2 on 2019-05-09 06:54
from django.db import migrations, models
import django.db.models.deletion
import jsonfallback.fields
import pretix.base.models.fields
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0118_auto_20190423_0839'),
]
operations = [
migrations.AddField(
model_name='question',
name='hidden',
field=models.BooleanField(default=False, help_text='This question will only show up in the backend.', verbose_name='Hidden question'),
),
]

View File

@@ -893,6 +893,8 @@ class Question(LoggedModel):
:param items: A set of ``Items`` objects that this question should be applied to
:param ask_during_checkin: Whether to ask this question during check-in instead of during check-out.
:type ask_during_checkin: bool
:param hidden: Whether to only show the question in the backend
:type hidden: bool
:param identifier: An arbitrary, internal identifier
:type identifier: str
:param dependency_question: This question will only show up if the referenced question is set to `dependency_value`.
@@ -968,6 +970,11 @@ class Question(LoggedModel):
'pretixdesk 0.2 or newer.'),
default=False
)
hidden = models.BooleanField(
verbose_name=_('Hidden question'),
help_text=_('This question will only show up in the backend.'),
default=False
)
dependency_question = models.ForeignKey(
'Question', null=True, blank=True, on_delete=models.SET_NULL, related_name='dependent_questions'
)

View File

@@ -976,7 +976,8 @@ class AbstractPosition(models.Model):
if hasattr(self.item, 'questions_to_ask'):
questions = list(copy.copy(q) for q in self.item.questions_to_ask)
else:
questions = list(copy.copy(q) for q in self.item.questions.filter(ask_during_checkin=False))
questions = list(copy.copy(q) for q in self.item.questions.filter(ask_during_checkin=False,
hidden=False))
else:
questions = list(copy.copy(q) for q in self.item.questions.all())

View File

@@ -82,6 +82,7 @@ class QuestionForm(I18nModelForm):
'type',
'required',
'ask_during_checkin',
'hidden',
'identifier',
'items',
'dependency_question',

View File

@@ -109,6 +109,7 @@
{% bootstrap_field form.help_text layout="control" %}
{% bootstrap_field form.identifier layout="control" %}
{% bootstrap_field form.ask_during_checkin layout="control" %}
{% bootstrap_field form.hidden layout="control" %}
<div class="form-group">
<label class="col-md-3 control-label" for="id_dependency_question">

View File

@@ -15,7 +15,7 @@ class QuestionsViewMixin(BaseQuestionsViewMixin):
def _positions_for_questions(self):
qqs = self.request.event.questions.all()
if self.only_user_visible:
qqs = qqs.filter(ask_during_checkin=False)
qqs = qqs.filter(ask_during_checkin=False, hidden=False)
cart = get_cart(self.request).select_related(
'addon_to'
).prefetch_related(

View File

@@ -1591,6 +1591,7 @@ TEST_QUESTION_RES = {
"required": False,
"items": [],
"ask_during_checkin": False,
"hidden": False,
"identifier": "ABC",
"position": 0,
"dependency_question": None,