mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
Merge pull request #120 from Southampton-RSG/feat/autofill-negative
Add button to autofill negative responses
This commit is contained in:
@@ -8,6 +8,7 @@ venv/
|
||||
|
||||
Caddyfile
|
||||
docker-compose.yml
|
||||
.env
|
||||
settings.ini
|
||||
mail.log/
|
||||
/roles/
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,6 +15,7 @@ db.sqlite3
|
||||
debug.log*
|
||||
|
||||
# Configuration
|
||||
.env
|
||||
settings.ini
|
||||
deployment-key*
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ class DynamicAnswerSetBase(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.negative_responses = {}
|
||||
field_order = []
|
||||
|
||||
for question in self.question_model.objects.all():
|
||||
@@ -86,6 +87,13 @@ class DynamicAnswerSetBase(forms.Form):
|
||||
self.fields[field_name] = field
|
||||
field_order.append(field_name)
|
||||
|
||||
try:
|
||||
negative_response = question.answers.get(is_negative_response=True)
|
||||
self.negative_responses[field_name] = negative_response.id
|
||||
|
||||
except (self.answer_model.DoesNotExist, self.answer_model.MultipleObjectsReturned):
|
||||
pass
|
||||
|
||||
if question.allow_free_text and not self.as_filters:
|
||||
free_field = forms.CharField(label=f'{question} free text',
|
||||
required=False)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 2.2.10 on 2022-03-31 17:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('people', '0053_organisation_order_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='organisationquestionchoice',
|
||||
name='is_negative_response',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='organisationrelationshipquestionchoice',
|
||||
name='is_negative_response',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='personquestionchoice',
|
||||
name='is_negative_response',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='relationshipquestionchoice',
|
||||
name='is_negative_response',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -114,6 +114,9 @@ class QuestionChoice(models.Model):
|
||||
#: Position of this answer in the list
|
||||
order = models.SmallIntegerField(default=0, blank=False, null=False)
|
||||
|
||||
#: Does this answer represent the negative response?
|
||||
is_negative_response = models.BooleanField(default=False)
|
||||
|
||||
@property
|
||||
def slug(self) -> str:
|
||||
return slugify(self.text)
|
||||
|
||||
67
people/templates/people/includes/relationship_form.html
Normal file
67
people/templates/people/includes/relationship_form.html
Normal file
@@ -0,0 +1,67 @@
|
||||
{% with config.RELATIONSHIP_FORM_HELP as help_text %}
|
||||
{% if help_text %}
|
||||
<div class="alert alert-info mt-3 pb-0">
|
||||
{{ help_text|linebreaks }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
|
||||
<div class="alert alert-info mt-3">
|
||||
If you do not know this person / organisation, you may use this button to autofill appropriate responses.
|
||||
|
||||
<button class="btn btn-warning" onclick="autofillNegative()">Autofill</button>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<form class="form"
|
||||
method="POST">
|
||||
{% csrf_token %}
|
||||
|
||||
{% load bootstrap4 %}
|
||||
{% bootstrap_form form %}
|
||||
|
||||
{% buttons %}
|
||||
<button class="btn btn-success" type="submit">Submit</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
|
||||
{{ form.negative_responses|json_script:"negative-response-data" }}
|
||||
|
||||
<script type="application/javascript">
|
||||
// Polyfill for `Object.entries` on IE
|
||||
if (!Object.entries) {
|
||||
Object.entries = function( obj ){
|
||||
var ownProps = Object.keys( obj ),
|
||||
i = ownProps.length,
|
||||
resArray = new Array(i); // preallocate the Array
|
||||
while (i--)
|
||||
resArray[i] = [ownProps[i], obj[ownProps[i]]];
|
||||
|
||||
return resArray;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Autofill form with negative responses if no relationship exists.
|
||||
*/
|
||||
function autofillNegative() {
|
||||
var data = JSON.parse(document.getElementById("negative-response-data").textContent);
|
||||
|
||||
var fields = Object.entries(data)
|
||||
for (var i = 0, n = fields.length; i < n; i++) {
|
||||
var field = fields[i]
|
||||
|
||||
var options = document.getElementById("id_" + field[0]).options
|
||||
for (var j = 0, m = options.length; j < m; j++) {
|
||||
var option = options[j]
|
||||
if (option.value === field[1].toString()) {
|
||||
option.selected = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ form.negative_responses }}
|
||||
@@ -15,26 +15,6 @@
|
||||
|
||||
<h1>Add Relationship</h1>
|
||||
|
||||
{% with config.RELATIONSHIP_FORM_HELP as help_text %}
|
||||
{% if help_text %}
|
||||
<div class="alert alert-info mt-3 pb-0">
|
||||
{{ help_text|linebreaks }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<hr>
|
||||
|
||||
<form class="form"
|
||||
method="POST">
|
||||
{% csrf_token %}
|
||||
|
||||
{% load bootstrap4 %}
|
||||
{% bootstrap_form form %}
|
||||
|
||||
{% buttons %}
|
||||
<button class="btn btn-success" type="submit">Submit</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
{% include 'people/includes/relationship_form.html' %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -18,27 +18,7 @@
|
||||
|
||||
<h1>Update Relationship</h1>
|
||||
|
||||
{% with config.RELATIONSHIP_FORM_HELP as help_text %}
|
||||
{% if help_text %}
|
||||
<div class="alert alert-info mt-3 pb-0">
|
||||
{{ help_text|linebreaks }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<hr>
|
||||
|
||||
<form class="form"
|
||||
method="POST">
|
||||
{% csrf_token %}
|
||||
|
||||
{% load bootstrap4 %}
|
||||
{% bootstrap_form form %}
|
||||
|
||||
{% buttons %}
|
||||
<button class="btn btn-success" type="submit">Submit</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
{% include 'people/includes/relationship_form.html' %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -42,5 +42,5 @@ six==1.14.0
|
||||
snowballstemmer==2.0.0
|
||||
soupsieve==1.9.5
|
||||
sqlparse==0.3.0
|
||||
typed-ast==1.4.1
|
||||
typed-ast
|
||||
wrapt==1.11.2
|
||||
|
||||
Reference in New Issue
Block a user