-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1228 from Amsterdam-Music-Lab/aj/custom-questions-db
Creating custom questions from admin
- Loading branch information
Showing
20 changed files
with
450 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.forms import ModelForm, ValidationError, ChoiceField, BaseInlineFormSet | ||
|
||
|
||
class QuestionForm(ModelForm): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
if kwargs.get('instance') is None: | ||
|
||
self.fields['type'].help_text = "Click 'Save and continue editing' to customize" | ||
|
||
else: | ||
|
||
if not kwargs.get('instance').editable: | ||
self.fields["key"].disabled = True | ||
|
||
type = self.fields.get("type", None) | ||
if type: | ||
self.fields["type"].disabled = True | ||
|
||
class Meta: | ||
help_texts = { | ||
"scale_steps" : "Non-empty choices field overrides this value", | ||
"min_values" : "Only affects CHECKBOXES view" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
backend/question/migrations/0004_add_custom_question_fields_and_modeltranslation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Generated by Django 4.2.15 on 2024-10-13 12:22 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('question', '0003_rename_experiment_questionseries_block'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='question', | ||
name='explainer', | ||
field=models.TextField(blank=True, default=''), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='explainer_en', | ||
field=models.TextField(blank=True, default='', null=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='explainer_nl', | ||
field=models.TextField(blank=True, default='', null=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='explainer_pt', | ||
field=models.TextField(blank=True, default='', null=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='is_skippable', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='max_length', | ||
field=models.IntegerField(default=64), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='max_value', | ||
field=models.FloatField(default=120), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='min_value', | ||
field=models.FloatField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='min_values', | ||
field=models.IntegerField(default=1), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='profile_scoring_rule', | ||
field=models.CharField(blank=True, choices=[('LIKERT', 'LIKERT'), ('REVERSE_LIKERT', 'REVERSE_LIKERT'), ('CATEGORIES_TO_LIKERT', 'CATEGORIES_TO_LIKERT')], default='', max_length=128), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='question_en', | ||
field=models.CharField(max_length=1024, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='question_nl', | ||
field=models.CharField(max_length=1024, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='question_pt', | ||
field=models.CharField(max_length=1024, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='scale_steps', | ||
field=models.IntegerField(choices=[(5, 5), (7, 7)], default=7), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='type', | ||
field=models.CharField(choices=[('', '---------'), ('BooleanQuestion', 'BooleanQuestion'), ('ChoiceQuestion', 'ChoiceQuestion'), ('NumberQuestion', 'NumberQuestion'), ('TextQuestion', 'TextQuestion'), ('LikertQuestion', 'LikertQuestion'), ('LikertQuestionIcon', 'LikertQuestionIcon'), ('AutoCompleteQuestion', 'AutoCompleteQuestion')], default='', max_length=128), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='view', | ||
field=models.CharField(choices=[('BUTTON_ARRAY', 'BUTTON_ARRAY'), ('CHECKBOXES', 'CHECKBOXES'), ('RADIOS', 'RADIOS'), ('DROPDOWN', 'DROPDOWN')], default='', max_length=128), | ||
), | ||
migrations.AlterField( | ||
model_name='question', | ||
name='key', | ||
field=models.SlugField(max_length=128, primary_key=True, serialize=False), | ||
), | ||
migrations.CreateModel( | ||
name='Choice', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('key', models.SlugField(max_length=128)), | ||
('text', models.CharField()), | ||
('text_en', models.CharField(null=True)), | ||
('text_nl', models.CharField(null=True)), | ||
('text_pt', models.CharField(null=True)), | ||
('index', models.PositiveIntegerField()), | ||
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='question.question')), | ||
], | ||
options={ | ||
'ordering': ['index'], | ||
}, | ||
), | ||
] |
40 changes: 40 additions & 0 deletions
40
backend/question/migrations/0005_recreate_default_questions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.db import migrations | ||
from question.questions import create_default_questions | ||
from question.models import QuestionInSeries, Question | ||
|
||
|
||
def recreate_default_questions(apps, schema_editor): | ||
|
||
# Save info of all QuestionInSeries objects, because they will be deleted when recreating questions | ||
qis_all = QuestionInSeries.objects.all() | ||
qis_all_list = [] | ||
for qis in qis_all: | ||
qis_all_list.append({'question_series':qis.question_series, "question_key":qis.question.key, "index":qis.index}) | ||
|
||
create_default_questions(overwrite=True) | ||
|
||
# Recreate QuestionInSeries objects with new question objects | ||
for qis in qis_all_list: | ||
QuestionInSeries.objects.create( | ||
question_series=qis["question_series"], | ||
question=Question.objects.get(key=qis["question_key"]), | ||
index=qis["index"] | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('question', '0004_add_custom_question_fields_and_modeltranslation'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(recreate_default_questions, reverse_code=migrations.RunPython.noop), | ||
] | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.