Skip to content

Commit 3968997

Browse files
Merge pull request #386 from RSE-Sheffield/fix/save-demography
Don't populate pages using default config
2 parents fd2b128 + 0224179 commit 3968997

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 5.1.4 on 2025-09-19 08:19
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("home", "0011_rename_created_on_project_created_at"),
10+
("survey", "0020_alter_survey_project_alter_survey_survey_body_path"),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name="survey",
16+
name="consent_config",
17+
),
18+
migrations.RemoveField(
19+
model_name="survey",
20+
name="demography_config",
21+
),
22+
]

survey/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ def consent_config_default(self) -> dict:
8787
with self.consent_config_path.open() as file:
8888
return json.load(file)
8989

90+
@property
91+
def consent_config(self) -> dict:
92+
"""
93+
This survey's welcome/consent question configuration.
94+
"""
95+
# Get the first section
96+
return dict(sections=[self.survey_config["sections"][0]])
97+
98+
@property
99+
def demography_config(self) -> dict:
100+
"""
101+
This survey's demographics question configuration.
102+
"""
103+
# Get the final section
104+
return dict(sections=[self.survey_config["sections"][-1]])
105+
90106
@property
91107
def demography_config_default(self) -> dict:
92108
"""

survey/services/survey.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ def update_consent_demography_config(
8888
if survey.has_responses:
8989
raise PermissionDenied("Cannot modify survey with responses")
9090

91-
survey.consent_config = consent_config
92-
survey.demography_config = demography_config
9391
survey.survey_body_path = survey_body_path
9492

9593
survey.update(consent_config=consent_config, demography_config=demography_config)
@@ -111,8 +109,8 @@ def duplicate_survey(self, user: User, survey: Survey):
111109
self.update_consent_demography_config(
112110
user,
113111
new_survey,
114-
consent_config=survey.consent_config_default,
115-
demography_config=survey.demography_config_default,
112+
consent_config=survey.consent_config,
113+
demography_config=survey.demography_config,
116114
survey_body_path=survey.survey_body_path,
117115
)
118116

survey/templates/survey/survey_configure.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<i class="bx bxs-buildings"></i> <a href="{% url 'myorganisation' %}">My Organisation</a>
1313
</li>
1414
<li class="breadcrumb-item" aria-current="page">
15-
<i class="bx bxs-folder-open"></i> <a href="{% url 'project' survey.project.id %}">Project: {{ survey.project.name }}</a>
15+
<i class="bx bxs-folder-open"></i> <a
16+
href="{% url 'project' survey.project.id %}">Project: {{ survey.project.name }}</a>
1617
</li>
1718
<li class="breadcrumb-item" aria-current="page">
1819
<i class="bx bxs-chart"></i> <a href="{% url 'survey' survey.id %}"> Survey: {{ survey.name }}</a>
@@ -35,8 +36,8 @@ <h3>Configure {{ survey.name }}</h3>
3536
></div>
3637
</div>
3738
{{ csrf | json_script:"csrf" }}
38-
{{ survey.consent_config_default | json_script:"consentConfig" }}
39-
{{ survey.demography_config_default | json_script:"demographyConfig" }}
39+
{{ survey.consent_config | json_script:"consentConfig" }}
40+
{{ survey.demography_config | json_script:"demographyConfig" }}
4041
{{ survey.survey_config | json_script:"configData" }}
4142
{% vite_client %}
4243
{% vite_asset "src/main.ts" %}

0 commit comments

Comments
 (0)