-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from con2/feat/forms-sequence-numbers
feat(forms): add intra-Survey sequence numbers to Responses
- Loading branch information
Showing
12 changed files
with
127 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 5.0.2 on 2024-02-12 18:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def number_existing_responses(apps, schema_editor): | ||
Response = apps.get_model("forms", "Response") | ||
Survey = apps.get_model("forms", "Survey") | ||
|
||
for survey in Survey.objects.all(): | ||
responses = Response.objects.filter( | ||
form__in=survey.languages.all(), | ||
sequence_number=0, | ||
).order_by("created_at") | ||
for i, response in enumerate(responses): | ||
response.sequence_number = i + 1 | ||
response.save(update_fields=["sequence_number"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("forms", "0022_dimension_is_shown_to_respondent"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="response", | ||
name="sequence_number", | ||
field=models.PositiveIntegerField( | ||
default=0, help_text="Sequence number of this response within the use case (eg. survey)." | ||
), | ||
), | ||
migrations.RunPython(number_existing_responses, reverse_code=migrations.RunPython.noop), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.