From 8d68e1b0c3de5c1b997e213992961ae4fcdcaeb4 Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 5 Mar 2021 12:16:31 +0000 Subject: [PATCH] feat: add hardcoded organisation questions Resolves #91 Resolves #88 --- people/forms.py | 6 +++ .../0041_add_static_org_questions.py | 34 +++++++++++++ people/models/organisation.py | 23 ++++++++- .../templates/people/organisation/detail.html | 48 ++++++++++++++++++- 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 people/migrations/0041_add_static_org_questions.py diff --git a/people/forms.py b/people/forms.py index dcacc85..c2f4447 100644 --- a/people/forms.py +++ b/people/forms.py @@ -87,10 +87,16 @@ class OrganisationAnswerSetForm(forms.ModelForm, DynamicAnswerSetBase): class Meta: model = models.OrganisationAnswerSet fields = [ + 'name', + 'website', + 'countries', + 'hq_country', 'latitude', 'longitude', ] widgets = { + 'countries': Select2MultipleWidget(), + 'hq_country': Select2Widget(), 'latitude': forms.HiddenInput, 'longitude': forms.HiddenInput, } diff --git a/people/migrations/0041_add_static_org_questions.py b/people/migrations/0041_add_static_org_questions.py new file mode 100644 index 0000000..060c76d --- /dev/null +++ b/people/migrations/0041_add_static_org_questions.py @@ -0,0 +1,34 @@ +# Generated by Django 2.2.10 on 2021-03-05 11:53 + +from django.db import migrations, models +import django_countries.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0040_person_organisation_relationship_targets'), + ] + + operations = [ + migrations.AddField( + model_name='organisationanswerset', + name='countries', + field=django_countries.fields.CountryField(blank=True, help_text='Geographical spread - in which countries does this organisation have offices? Select all that apply', max_length=746, multiple=True), + ), + migrations.AddField( + model_name='organisationanswerset', + name='hq_country', + field=django_countries.fields.CountryField(blank=True, help_text='In which country does this organisation have its main location?', max_length=2), + ), + migrations.AddField( + model_name='organisationanswerset', + name='name', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AddField( + model_name='organisationanswerset', + name='website', + field=models.URLField(blank=True, max_length=255), + ), + ] diff --git a/people/models/organisation.py b/people/models/organisation.py index 74cdc57..7200ca6 100644 --- a/people/models/organisation.py +++ b/people/models/organisation.py @@ -3,6 +3,7 @@ import logging from django.db import models from django.urls import reverse +from django_countries.fields import CountryField from .question import AnswerSet, Question, QuestionChoice @@ -60,10 +61,28 @@ class OrganisationAnswerSet(AnswerSet): blank=False, null=False) - #: Latitude for displaying location on a map + name = models.CharField(max_length=255, blank=True, null=False) + + website = models.URLField(max_length=255, blank=True, null=False) + + #: Which countries does this organisation operate in? + countries = CountryField( + multiple=True, + blank=True, + null=False, + help_text=( + 'Geographical spread - in which countries does this organisation ' + 'have offices? Select all that apply')) + + #: Which country is this organisation based in? + hq_country = CountryField( + blank=True, + null=False, + help_text=( + 'In which country does this organisation have its main location?')) + latitude = models.FloatField(blank=True, null=True) - #: Longitude for displaying location on a map longitude = models.FloatField(blank=True, null=True) #: Answers to :class:`OrganisationQuestion`s diff --git a/people/templates/people/organisation/detail.html b/people/templates/people/organisation/detail.html index a1e48d8..66d0198 100644 --- a/people/templates/people/organisation/detail.html +++ b/people/templates/people/organisation/detail.html @@ -29,7 +29,53 @@
- {% include 'people/person/includes/answer_set_full.html' %} + + + + + + + + + + {% if answer_set.website %} + + {% endif %} + + {% if answer_set.countries %} + + {% endif %} + + {% if answer_set.hq_country %} + + {% endif %} + + {% if request.user.is_superuser %} + {% for answer in answer_set.question_answers.all %} + + + + + {% endfor %} + + {% else %} + {% for answer in answer_set.public_answers.all %} + + + + + {% endfor %} + {% endif %} + +
QuestionAnswer
Website + {{ answer_set.website }} +
Countries + {% for country in answer_set.countries %} + {{ country.name }}{% if not forloop.last %},{% endif %} + {% endfor %} +
HQ Country{{ answer_set.hq_country.name }}
{{ answer.question }}{{ answer }}
{{ answer.question }}{{ answer }}
+ +

Last updated: {{ answer_set.timestamp }}