Skip to content

Commit

Permalink
Merge pull request #2054 from IFRCGo/feature/search-page-fix
Browse files Browse the repository at this point in the history
Add fix for search page
  • Loading branch information
thenav56 authored Feb 26, 2024
2 parents 94e520f + e64cc67 commit 04f8e45
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
12 changes: 9 additions & 3 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,19 @@ def get(self, request):
SearchQuerySet()
.models(Personnel)
.filter(
SQ(deploying_country_name__contains=phrase)
(SQ(deploying_country_name__contains=phrase)
| SQ(deployed_to_country_name__contains=phrase)
| SQ(event_name__content=phrase)
| SQ(event_name__content=phrase))
& SQ(end_date__gt=datetime.now())
)
.order_by("-_score")
)
surge_alert_response = (
SearchQuerySet()
.models(SurgeAlert)
.filter(
SQ(event_name__content=phrase) | SQ(country_name__contains=phrase) | SQ(iso3__contains=phrase)
(SQ(event_name__content=phrase) | SQ(country_name__contains=phrase) | SQ(iso3__contains=phrase))
& ~SQ(status='archived')
)
.order_by("-_score")
)
Expand Down Expand Up @@ -223,6 +225,7 @@ def get(self, request):
| SQ(event_name__content=phrase)
)
& ~SQ(visibility="IFRC Only")
& SQ(end_date__gt=datetime.now())
)
.order_by("-_score")
)
Expand All @@ -232,6 +235,7 @@ def get(self, request):
.filter(
(SQ(event_name__content=phrase) | SQ(country_name__contains=phrase) | SQ(iso3__contains=phrase))
& ~SQ(visibility="IFRC Only")
& ~SQ(status='archived')
)
.order_by("-_score")
)
Expand Down Expand Up @@ -278,6 +282,7 @@ def get(self, request):
| SQ(event_name__content=phrase)
)
& SQ(visibility="Public")
& SQ(end_date__gt=datetime.now())
)
.order_by("-_score")
)
Expand All @@ -287,6 +292,7 @@ def get(self, request):
.filter(
(SQ(event_name__content=phrase) | SQ(country_name__contains=phrase) | SQ(iso3__contains=phrase))
& SQ(visibility="Public")
& ~SQ(status='archived')
)
.order_by("-_score")
)
Expand Down
47 changes: 47 additions & 0 deletions per/migrations/0099_migrate_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 3.2.23 on 2024-02-22 05:45
from django.db import migrations
from django.db import models


def migrate_formdata_notes(apps, schema_editor):
FormComponentResponse = apps.get_model("per", "FormComponentResponse")
FormData = apps.get_model("per", "FormData")

qs = FormComponentResponse.objects.annotate(
new_notes=models.Subquery(
# Copy notes from FormData using overview
FormData.objects.filter(
form__overview=models.OuterRef('arearesponse__perassessment__overview'),
question__component=models.OuterRef('component'),
question=74,
).values('notes_en'),
output_field=models.CharField(),
),
).filter(new_notes__isnull=False)

form_component_responses = []
for form_component_response_id, assessment_id, new_notes in qs.values_list(
'id',
models.F('arearesponse__perassessment'),
'new_notes',
):
print(f'- Copying data for {assessment_id=} {form_component_response_id=}')
form_component_responses.append(
FormComponentResponse(
id=form_component_response_id,
notes=new_notes,
)
)

print(f'Total form_component_responses notes copied: {len(form_component_responses)}')
FormComponentResponse.objects.bulk_update(form_component_responses, fields=('notes',))


class Migration(migrations.Migration):
dependencies = [
("per", "0098_fix_reversion_data_20240208_0502"),
]

operations = [
migrations.RunPython(migrate_formdata_notes, reverse_code=migrations.RunPython.noop),
]

0 comments on commit 04f8e45

Please sign in to comment.