mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-10 17:16:22 +01: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:
@@ -16,7 +16,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', '0002_choices_for_questions'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='applicationquestion',
|
||||
name='multi_select',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -13,6 +13,7 @@ from authentication.models import AuthServicesInfo
|
||||
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
|
||||
|
||||
@@ -71,8 +71,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('auth_hrapplications_view')
|
||||
|
||||
Reference in New Issue
Block a user