mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-14 23:10:15 +02:00
Extending Choices for Questions in hrapplications to Allow Multiselect (#911)
An additional field at the question level defines whether the choices for the question are multi-select or not. The template will render the choices with radio buttons or checkboxes depending on multi-select. Multiple selected choices are saved with a line break between them.
This commit is contained in:
parent
c63464c4c9
commit
f961db3130
@ -12,7 +12,7 @@ class ChoiceInline(admin.TabularInline):
|
||||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {'fields': ['title', 'help_text']}),
|
||||
(None, {'fields': ['title', 'help_text', 'multi_select']}),
|
||||
]
|
||||
inlines = [ChoiceInline]
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10 on 2017-10-20 13:51
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('hrapplications', '0005_remove_legacy_models'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='applicationquestion',
|
||||
name='multi_select',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
@ -9,6 +9,7 @@ from allianceauth.eveonline.models import EveCorporationInfo
|
||||
class ApplicationQuestion(models.Model):
|
||||
title = models.CharField(max_length=254, verbose_name='Question')
|
||||
help_text = models.CharField(max_length=254, blank=True, null=True)
|
||||
multi_select = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return "Question: " + self.title
|
||||
|
@ -19,7 +19,7 @@
|
||||
<div cass="text-center">{{ question.help_text }}</div>
|
||||
{% endif %}
|
||||
{% for choice in question.choices.all %}
|
||||
<input type="radio" name="{{ question.pk }}" id="id_{{ question.pk }}" value="{{ choice.choice_text }}" />
|
||||
<input type={% if question.multi_select == False %}"radio"{% else %}"checkbox"{% endif %} name="{{ question.pk }}" id="id_{{ question.pk }}" value="{{ choice.choice_text }}" />
|
||||
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
|
||||
{% empty %}
|
||||
<textarea class="form-control" cols="30" id="id_{{ question.pk }}" name="{{ question.pk }}" rows="4"></textarea>
|
||||
|
@ -62,8 +62,8 @@ def hr_application_create_view(request, form_id=None):
|
||||
application.save()
|
||||
for question in app_form.questions.all():
|
||||
response = ApplicationResponse(question=question, application=application)
|
||||
response.answer = request.POST.get(str(question.pk),
|
||||
"Failed to retrieve answer provided by applicant.")
|
||||
response.answer = "\n".join(request.POST.getlist(str(question.pk),
|
||||
""))
|
||||
response.save()
|
||||
logger.info("%s created %s" % (request.user, application))
|
||||
return redirect('hrapplications:view')
|
||||
|
Loading…
x
Reference in New Issue
Block a user