From 62d7a1e48c2f3202685ecf95ced3c8cb1a7a3147 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 24 Jun 2020 12:01:45 +0100 Subject: [PATCH 01/11] fix: Set defaults if customisation app not loaded --- breccia_mapper/settings.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/breccia_mapper/settings.py b/breccia_mapper/settings.py index e536c0f..d2424c7 100644 --- a/breccia_mapper/settings.py +++ b/breccia_mapper/settings.py @@ -376,16 +376,20 @@ else: # Import customisation app settings if present -CUSTOMISATION_NAME = None -TEMPLATE_NAME_INDEX = 'index.html' -TEMPLATE_WELCOME_EMAIL_NAME = 'welcome-email' - try: - from custom.settings import (CUSTOMISATION_NAME, TEMPLATE_NAME_INDEX, - TEMPLATE_WELCOME_EMAIL_NAME) + from custom.settings import ( + CUSTOMISATION_NAME, + TEMPLATE_NAME_INDEX, + TEMPLATE_WELCOME_EMAIL_NAME + ) logger.info("Loaded customisation app: %s", CUSTOMISATION_NAME) INSTALLED_APPS.append('custom') -except ImportError as e: - logger.info("No customisation app loaded: %s", e) +except ImportError as exc: + logger.info("No customisation app loaded: %s", exc) + + # Set default values if no customisations loaded + CUSTOMISATION_NAME = None + TEMPLATE_NAME_INDEX = 'index.html' + TEMPLATE_WELCOME_EMAIL_NAME = 'welcome-email' From 9a84f77ec420075fa1da9029b61e8f9487233cd5 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 24 Jun 2020 13:40:02 +0100 Subject: [PATCH 02/11] fix: Don't insert form CSS/JS when no form --- breccia_mapper/templates/base.html | 148 +++++++++++++++-------------- 1 file changed, 76 insertions(+), 72 deletions(-) diff --git a/breccia_mapper/templates/base.html b/breccia_mapper/templates/base.html index 3d2ddc0..b69fd7b 100644 --- a/breccia_mapper/templates/base.html +++ b/breccia_mapper/templates/base.html @@ -1,8 +1,8 @@ {% load bootstrap4 %} {% if 'use_i18n'|bootstrap_setting %} - {% load i18n %} - {% get_current_language as LANGUAGE_CODE %} +{% load i18n %} +{% get_current_language as LANGUAGE_CODE %} {% endif %} @@ -25,28 +25,29 @@ crossorigin="anonymous" /> {% load staticfiles %} - + {% if 'javascript_in_head'|bootstrap_setting %} - {% if 'include_jquery'|bootstrap_setting %} - {# jQuery JavaScript if it is in head #} - {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} - {% endif %} - - {# Bootstrap JavaScript if it is in head #} - {% bootstrap_javascript %} + {% if 'include_jquery'|bootstrap_setting %} + {# jQuery JavaScript if it is in head #} + {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} {% endif %} - {{ form.media.css }} + {# Bootstrap JavaScript if it is in head #} + {% bootstrap_javascript %} + {% endif %} + + {% if form %} + {{ form.media.css }} + {% endif %} {% block extra_head %}{% endblock %} -
- {% block navbar %} +
+ {% block navbar %}
- {% endblock %} + {% endblock %} - {# Global banner if config.NOTICE_TEXT is set using Constance #} - {% if config.NOTICE_TEXT %} + {# Global banner if config.NOTICE_TEXT is set using Constance #} + {% if config.NOTICE_TEXT %} - {% endif %} + {% endif %} - {% if request.user.is_authenticated and not request.user.has_person %} + {% if request.user.is_authenticated and not request.user.has_person %} - {% endif %} + {% endif %} - {% block before_content %}{% endblock %} + {% block before_content %}{% endblock %} -
- {# Display Django messages as Bootstrap alerts #} - {% bootstrap_messages %} +
+ {# Display Django messages as Bootstrap alerts #} + {% bootstrap_messages %} - {% block content %}{% endblock %} -
+ {% block content %}{% endblock %} +
-
- {% block after_content %}{% endblock %} +
+ {% block after_content %}{% endblock %} +
-
-
-
- {{ settings.PROJECT_LONG_NAME }} -
-
+
+
+ {{ settings.PROJECT_LONG_NAME }} +
+
-{% if not 'javascript_in_head'|bootstrap_setting %} + {% if not 'javascript_in_head'|bootstrap_setting %} {% if 'include_jquery'|bootstrap_setting %} - {# jQuery JavaScript if it is in body #} - {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} + {# jQuery JavaScript if it is in body #} + {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} {% endif %} {# Bootstrap JavaScript if it is in body #} {% bootstrap_javascript %} -{% endif %} + {% endif %} -{{ form.media.js }} + {% if form %} + {{ form.media.js }} + {% endif %} -{% block extra_script %}{% endblock %} + {% block extra_script %}{% endblock %} From 26bf55b4b4318f2f5011c7382d037c8de7f43cd0 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 24 Jun 2020 13:47:12 +0100 Subject: [PATCH 03/11] fix: Remove Person.core_member field See #33 --- export/serializers/people.py | 11 ++++++----- people/forms.py | 15 +++++++-------- .../0019_remove_person_core_member.py | 17 +++++++++++++++++ people/models/person.py | 3 --- 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 people/migrations/0019_remove_person_core_member.py diff --git a/export/serializers/people.py b/export/serializers/people.py index 196f295..0174827 100644 --- a/export/serializers/people.py +++ b/export/serializers/people.py @@ -22,14 +22,13 @@ class PersonSerializer(base.FlattenedModelSerializer): fields = [ 'id', 'name', - 'core_member', 'gender', 'age_group', 'nationality', 'country_of_residence', ] - - + + class RelationshipSerializer(base.FlattenedModelSerializer): source = SimplePersonSerializer() target = SimplePersonSerializer() @@ -45,7 +44,7 @@ class RelationshipSerializer(base.FlattenedModelSerializer): class RelationshipAnswerSetSerializer(base.FlattenedModelSerializer): relationship = RelationshipSerializer() - + class Meta: model = models.RelationshipAnswerSet fields = [ @@ -71,7 +70,9 @@ class RelationshipAnswerSetSerializer(base.FlattenedModelSerializer): try: # Add relationship question answers to data for answer in instance.question_answers.all(): - rep[answer.question.slug.replace('-', '_')] = answer.slug.replace('-', '_') + rep[answer.question.slug.replace('-', + '_')] = answer.slug.replace( + '-', '_') except AttributeError: pass diff --git a/people/forms.py b/people/forms.py index 5877ce5..1d234f6 100644 --- a/people/forms.py +++ b/people/forms.py @@ -16,7 +16,6 @@ class PersonForm(forms.ModelForm): model = models.Person fields = [ 'name', - 'core_member', 'gender', 'age_group', 'nationality', @@ -32,13 +31,13 @@ class PersonForm(forms.ModelForm): 'country_of_residence': Select2Widget(), 'themes': Select2MultipleWidget(), } - - + + class DynamicAnswerSetBase(forms.Form): field_class = forms.ModelChoiceField field_widget = None field_required = True - + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -73,8 +72,8 @@ class RelationshipAnswerSetForm(forms.ModelForm, DynamicAnswerSetBase): self.instance.question_answers.add(value) return self.instance - - + + class NetworkFilterForm(DynamicAnswerSetBase): """ Form to provide filtering on the network view. @@ -82,9 +81,9 @@ class NetworkFilterForm(DynamicAnswerSetBase): field_class = forms.ModelMultipleChoiceField field_widget = Select2MultipleWidget field_required = False - + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - + # Add date field to select relationships at a particular point in time self.fields['date'] = forms.DateField(required=False) diff --git a/people/migrations/0019_remove_person_core_member.py b/people/migrations/0019_remove_person_core_member.py new file mode 100644 index 0000000..ee02484 --- /dev/null +++ b/people/migrations/0019_remove_person_core_member.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.10 on 2020-06-24 11:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0018_require_user_email'), + ] + + operations = [ + migrations.RemoveField( + model_name='person', + name='core_member', + ), + ] diff --git a/people/models/person.py b/people/models/person.py index f7910f9..0854c8a 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -122,9 +122,6 @@ class Person(models.Model): #: Name of the person name = models.CharField(max_length=255, blank=False, null=False) - #: Is this person a member of the core project team? - core_member = models.BooleanField(default=False, blank=False, null=False) - #: People with whom this person has relationship - via intermediate :class:`Relationship` model relationship_targets = models.ManyToManyField( 'self', From ab371394290134b8b17c8bd1fd9cec131abd2112 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 24 Jun 2020 15:09:23 +0100 Subject: [PATCH 04/11] feat: Add date started at organisation See #33 --- export/serializers/people.py | 2 ++ people/forms.py | 16 ++++++++++++++++ .../0020_person_organisation_started_date.py | 18 ++++++++++++++++++ people/models/person.py | 4 ++++ 4 files changed, 40 insertions(+) create mode 100644 people/migrations/0020_person_organisation_started_date.py diff --git a/export/serializers/people.py b/export/serializers/people.py index 0174827..4710dc5 100644 --- a/export/serializers/people.py +++ b/export/serializers/people.py @@ -26,6 +26,8 @@ class PersonSerializer(base.FlattenedModelSerializer): 'age_group', 'nationality', 'country_of_residence', + 'organisation', + 'organisation_started_date', ] diff --git a/people/forms.py b/people/forms.py index 1d234f6..267c2c2 100644 --- a/people/forms.py +++ b/people/forms.py @@ -2,6 +2,8 @@ Forms for creating / updating models belonging to the 'people' app. """ from django import forms +from django.forms.widgets import SelectDateWidget +from django.utils import timezone from django_select2.forms import Select2Widget, Select2MultipleWidget @@ -21,6 +23,7 @@ class PersonForm(forms.ModelForm): 'nationality', 'country_of_residence', 'organisation', + 'organisation_started_date', 'job_title', 'discipline', 'role', @@ -31,6 +34,19 @@ class PersonForm(forms.ModelForm): 'country_of_residence': Select2Widget(), 'themes': Select2MultipleWidget(), } + help_texts = { + 'organisation_started_date': + 'If you don\'t know the exact date, an approximate date is okay.', + } + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # Defaults to showing 10 years in future - show past years instead + num_years_display = 60 + this_year = timezone.datetime.now().year + self.fields['organisation_started_date'].widget = SelectDateWidget( + years=range(this_year, this_year - num_years_display, -1)) class DynamicAnswerSetBase(forms.Form): diff --git a/people/migrations/0020_person_organisation_started_date.py b/people/migrations/0020_person_organisation_started_date.py new file mode 100644 index 0000000..e12a3a9 --- /dev/null +++ b/people/migrations/0020_person_organisation_started_date.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2020-06-24 12:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0019_remove_person_core_member'), + ] + + operations = [ + migrations.AddField( + model_name='person', + name='organisation_started_date', + field=models.DateField(null=True, verbose_name='Date started at this organisation'), + ), + ] diff --git a/people/models/person.py b/people/models/person.py index 0854c8a..56c88ea 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -172,6 +172,10 @@ class Person(models.Model): blank=True, null=True) + #: When did this person start at their current organisation? + organisation_started_date = models.DateField( + 'Date started at this organisation', blank=False, null=True) + #: Job title this person holds within their organisation job_title = models.CharField(max_length=255, blank=True, null=False) From 57349a60074acc01fbb253cfe30fddb3f7f80842 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 24 Jun 2020 15:10:00 +0100 Subject: [PATCH 05/11] fix: Add changes to detail page missing See #33 --- people/templates/people/person/detail.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/people/templates/people/person/detail.html b/people/templates/people/person/detail.html index 349aaf5..d2dcd9c 100644 --- a/people/templates/people/person/detail.html +++ b/people/templates/people/person/detail.html @@ -38,6 +38,11 @@ {% if person.organisation %}
Organisation
{{ person.organisation }}
+ + {% if person.organisation_started_date %} +
Started Date
+
{{ person.organisation_started_date }}
+ {% endif %} {% endif %} {% if person.job_title %} From b84076ec3bbdd3e00d748f6d1a228d742bffc045 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 24 Jun 2020 16:29:50 +0100 Subject: [PATCH 06/11] refactor: Make Person.discipline free text See #33 --- people/forms.py | 2 +- .../0021_refactor_person_disciplines.py | 61 +++++++++++++++++++ people/models/person.py | 22 +------ people/templates/people/person/detail.html | 6 +- 4 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 people/migrations/0021_refactor_person_disciplines.py diff --git a/people/forms.py b/people/forms.py index 267c2c2..482a086 100644 --- a/people/forms.py +++ b/people/forms.py @@ -25,7 +25,7 @@ class PersonForm(forms.ModelForm): 'organisation', 'organisation_started_date', 'job_title', - 'discipline', + 'disciplines', 'role', 'themes', ] diff --git a/people/migrations/0021_refactor_person_disciplines.py b/people/migrations/0021_refactor_person_disciplines.py new file mode 100644 index 0000000..5f7da69 --- /dev/null +++ b/people/migrations/0021_refactor_person_disciplines.py @@ -0,0 +1,61 @@ +# Generated by Django 2.2.10 on 2020-06-24 14:19 + +from django.db import migrations, models + + +def migrate_forward(apps, schema_editor): + Person = apps.get_model('people', 'Person') + + for person in Person.objects.all(): + try: + person.disciplines = person.discipline.name + person.save() + + except AttributeError: + pass + + +def migrate_backward(apps, schema_editor): + Person = apps.get_model('people', 'Person') + Discipline = apps.get_model('people', 'Discipline') + + for person in Person.objects.all(): + try: + discipline_str = person.disciplines.split(',')[0] + + except AttributeError: + pass + + else: + # Returns None if not found - doesn't raise exception + discipline = Discipline.objects.filter(name=discipline_str).first() + + if not discipline: + discipline = Discipline.objects.create( + name=discipline_str, + code=discipline_str + if len(discipline_str) < 15 else discipline_str[:15]) + + person.discipline = discipline + person.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0020_person_organisation_started_date'), + ] + + operations = [ + migrations.AddField( + model_name='person', + name='disciplines', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.RunPython(migrate_forward, migrate_backward), + migrations.RemoveField( + model_name='person', + name='discipline', + ), + migrations.DeleteModel(name='Discipline', ), + ] diff --git a/people/models/person.py b/people/models/person.py index 56c88ea..6127f66 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -19,7 +19,6 @@ __all__ = [ 'User', 'Organisation', 'Role', - 'Discipline', 'Theme', 'Person', ] @@ -82,19 +81,6 @@ class Role(models.Model): return self.name -class Discipline(models.Model): - """ - Discipline within which a :class:`Person` works. - """ - name = models.CharField(max_length=255, blank=False, null=False) - - #: Short code using system such as JACS 3 - code = models.CharField(max_length=15, blank=True, null=False) - - def __str__(self) -> str: - return self.name - - class Theme(models.Model): """ Project theme within which a :class:`Person` works. @@ -179,12 +165,8 @@ class Person(models.Model): #: Job title this person holds within their organisation job_title = models.CharField(max_length=255, blank=True, null=False) - #: Discipline within which this person works - discipline = models.ForeignKey(Discipline, - on_delete=models.PROTECT, - related_name='people', - blank=True, - null=True) + #: Discipline(s) within which this person works + disciplines = models.CharField(max_length=255, blank=True, null=True) #: Role this person holds within the project role = models.ForeignKey(Role, diff --git a/people/templates/people/person/detail.html b/people/templates/people/person/detail.html index d2dcd9c..134f27c 100644 --- a/people/templates/people/person/detail.html +++ b/people/templates/people/person/detail.html @@ -55,9 +55,9 @@
{{ person.role }}
{% endif %} - {% if person.dispipline %} -
Discipline
-
{{ person.discipline }}
+ {% if person.disciplines %} +
Discipline(s)
+
{{ person.disciplines }}
{% endif %} {% if person.themes.exists %} From aafb6c0a21981df26e5ab4d96a67c46638a5a607 Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 25 Jun 2020 11:11:14 +0100 Subject: [PATCH 07/11] fix: Remove Person.name from CSV export See #35 --- export/serializers/people.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/export/serializers/people.py b/export/serializers/people.py index 4710dc5..b9308b2 100644 --- a/export/serializers/people.py +++ b/export/serializers/people.py @@ -12,7 +12,8 @@ class SimplePersonSerializer(serializers.ModelSerializer): model = models.Person fields = [ 'id', - 'name', + # Name is excluded from exports + # See https://github.com/Southampton-RSG/breccia-mapper/issues/35 ] @@ -21,7 +22,8 @@ class PersonSerializer(base.FlattenedModelSerializer): model = models.Person fields = [ 'id', - 'name', + # Name is excluded from exports + # See https://github.com/Southampton-RSG/breccia-mapper/issues/35 'gender', 'age_group', 'nationality', From 0e4234cb3567810740669a62f365bb14daf73d60 Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 25 Jun 2020 11:38:26 +0100 Subject: [PATCH 08/11] fix: Hide person details from non-admin users See #35 --- people/templates/people/person/detail.html | 105 +++++++++++---------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/people/templates/people/person/detail.html b/people/templates/people/person/detail.html index 134f27c..5e49e83 100644 --- a/people/templates/people/person/detail.html +++ b/people/templates/people/person/detail.html @@ -14,61 +14,70 @@
-
- {% if person.gender %} -
Gender
-
{{ person.get_gender_display }}
+ {% if person.user == request.user or request.user.is_superuser %} + {% if person.user != request.user and request.user.is_superuser %} +
+ NB: You are able to see the details of this person because you are an admin. + Regular users are not able to see this information for people other than themselves. +
{% endif %} - {% if person.age_group %} -
Age Group
-
{{ person.get_age_group_display }}
- {% endif %} - - {% if person.nationality %} -
Nationality
-
{{ person.nationality.name }}
- {% endif %} - - {% if person.country_of_residence %} -
Country of Residence
-
{{ person.country_of_residence.name }}
- {% endif %} - - {% if person.organisation %} -
Organisation
-
{{ person.organisation }}
- - {% if person.organisation_started_date %} -
Started Date
-
{{ person.organisation_started_date }}
+
+ {% if person.gender %} +
Gender
+
{{ person.get_gender_display }}
{% endif %} - {% endif %} - {% if person.job_title %} -
Job Title
-
{{ person.job_title }}
- {% endif %} + {% if person.age_group %} +
Age Group
+
{{ person.get_age_group_display }}
+ {% endif %} - {% if person.role %} -
Role
-
{{ person.role }}
- {% endif %} + {% if person.nationality %} +
Nationality
+
{{ person.nationality.name }}
+ {% endif %} - {% if person.disciplines %} -
Discipline(s)
-
{{ person.disciplines }}
- {% endif %} + {% if person.country_of_residence %} +
Country of Residence
+
{{ person.country_of_residence.name }}
+ {% endif %} - {% if person.themes.exists %} -
Project Themes
-
- {% for theme in person.themes.all %} - {{ theme }}{% if not forloop.last %}, {% endif %} - {% endfor %} -
- {% endif %} -
+ {% if person.organisation %} +
Organisation
+
{{ person.organisation }}
+ + {% if person.organisation_started_date %} +
Started Date
+
{{ person.organisation_started_date }}
+ {% endif %} + {% endif %} + + {% if person.job_title %} +
Job Title
+
{{ person.job_title }}
+ {% endif %} + + {% if person.role %} +
Role
+
{{ person.role }}
+ {% endif %} + + {% if person.disciplines %} +
Discipline(s)
+
{{ person.disciplines }}
+ {% endif %} + + {% if person.themes.exists %} +
Project Themes
+
+ {% for theme in person.themes.all %} + {{ theme }}{% if not forloop.last %}, {% endif %} + {% endfor %} +
+ {% endif %} +
+ {% endif %} Update From 387cebd0d48aee46cf59af4cbda5e0f08a208e3b Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 26 Jun 2020 10:54:40 +0100 Subject: [PATCH 09/11] fix: Improve clarity of network form time filter Resolves #34 --- people/forms.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/people/forms.py b/people/forms.py index 482a086..5f7c5a3 100644 --- a/people/forms.py +++ b/people/forms.py @@ -1,6 +1,9 @@ """ Forms for creating / updating models belonging to the 'people' app. """ + +import typing + from django import forms from django.forms.widgets import SelectDateWidget from django.utils import timezone @@ -10,6 +13,17 @@ from django_select2.forms import Select2Widget, Select2MultipleWidget from . import models +def get_date_year_range() -> typing.Iterable[int]: + """ + Get sensible year range for SelectDateWidgets in the past. + + By default these widgets show 10 years in the future. + """ + num_years_display = 60 + this_year = timezone.datetime.now().year + return range(this_year, this_year - num_years_display, -1) + + class PersonForm(forms.ModelForm): """ Form for creating / updating an instance of :class:`Person`. @@ -42,11 +56,8 @@ class PersonForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - # Defaults to showing 10 years in future - show past years instead - num_years_display = 60 - this_year = timezone.datetime.now().year self.fields['organisation_started_date'].widget = SelectDateWidget( - years=range(this_year, this_year - num_years_display, -1)) + years=get_date_year_range()) class DynamicAnswerSetBase(forms.Form): @@ -102,4 +113,7 @@ class NetworkFilterForm(DynamicAnswerSetBase): super().__init__(*args, **kwargs) # Add date field to select relationships at a particular point in time - self.fields['date'] = forms.DateField(required=False) + self.fields['date'] = forms.DateField( + required=False, + widget=SelectDateWidget(years=get_date_year_range()), + help_text='Show relationships as they were on this date') From 8689c1a2045f05902f8ea9cc4063456c985d73bf Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 26 Jun 2020 11:45:21 +0100 Subject: [PATCH 10/11] style: Fix some autoformatting issues --- breccia_mapper/templates/base.html | 178 ++++++++++++++--------------- export/serializers/people.py | 11 +- 2 files changed, 96 insertions(+), 93 deletions(-) diff --git a/breccia_mapper/templates/base.html b/breccia_mapper/templates/base.html index b69fd7b..5eea059 100644 --- a/breccia_mapper/templates/base.html +++ b/breccia_mapper/templates/base.html @@ -28,13 +28,13 @@ {% if 'javascript_in_head'|bootstrap_setting %} - {% if 'include_jquery'|bootstrap_setting %} - {# jQuery JavaScript if it is in head #} - {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} - {% endif %} + {% if 'include_jquery'|bootstrap_setting %} + {# jQuery JavaScript if it is in head #} + {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} + {% endif %} - {# Bootstrap JavaScript if it is in head #} - {% bootstrap_javascript %} + {# Bootstrap JavaScript if it is in head #} + {% bootstrap_javascript %} {% endif %} {% if form %} @@ -48,104 +48,104 @@
{% block navbar %} - + {% endblock %} {# Global banner if config.NOTICE_TEXT is set using Constance #} {% if config.NOTICE_TEXT %} - + {% endif %} {% if request.user.is_authenticated and not request.user.has_person %} - {% endif %} {% block before_content %}{% endblock %} @@ -169,13 +169,13 @@ {% if not 'javascript_in_head'|bootstrap_setting %} - {% if 'include_jquery'|bootstrap_setting %} - {# jQuery JavaScript if it is in body #} - {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} - {% endif %} + {% if 'include_jquery'|bootstrap_setting %} + {# jQuery JavaScript if it is in body #} + {% bootstrap_jquery jquery='include_jquery'|bootstrap_setting %} + {% endif %} - {# Bootstrap JavaScript if it is in body #} - {% bootstrap_javascript %} + {# Bootstrap JavaScript if it is in body #} + {% bootstrap_javascript %} {% endif %} {% if form %} diff --git a/export/serializers/people.py b/export/serializers/people.py index b9308b2..872761b 100644 --- a/export/serializers/people.py +++ b/export/serializers/people.py @@ -46,6 +46,11 @@ class RelationshipSerializer(base.FlattenedModelSerializer): ] +def underscore(slug: str) -> str: + """Replace hyphens with underscores in text.""" + return slug.replace('-', '_') + + class RelationshipAnswerSetSerializer(base.FlattenedModelSerializer): relationship = RelationshipSerializer() @@ -64,7 +69,7 @@ class RelationshipAnswerSetSerializer(base.FlattenedModelSerializer): # Add relationship questions to columns for question in models.RelationshipQuestion.objects.all(): - headers.append(question.slug.replace('-', '_')) + headers.append(underscore(question.slug)) return headers @@ -74,9 +79,7 @@ class RelationshipAnswerSetSerializer(base.FlattenedModelSerializer): try: # Add relationship question answers to data for answer in instance.question_answers.all(): - rep[answer.question.slug.replace('-', - '_')] = answer.slug.replace( - '-', '_') + rep[underscore(answer.question.slug)] = underscore(answer.slug) except AttributeError: pass From a1f9510a8c6832049f3f2437796226f79b37b62c Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 26 Jun 2020 11:58:15 +0100 Subject: [PATCH 11/11] style: Fix minor formatting issue in base template --- breccia_mapper/templates/base.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/breccia_mapper/templates/base.html b/breccia_mapper/templates/base.html index 5eea059..1b93a01 100644 --- a/breccia_mapper/templates/base.html +++ b/breccia_mapper/templates/base.html @@ -1,8 +1,8 @@ {% load bootstrap4 %} {% if 'use_i18n'|bootstrap_setting %} -{% load i18n %} -{% get_current_language as LANGUAGE_CODE %} + {% load i18n %} + {% get_current_language as LANGUAGE_CODE %} {% endif %}