Skip to content

Commit 33c0ca0

Browse files
committed
Add filters for operational learning and refine summary content
Add learning_type filter, validated_organization
1 parent 142f5a9 commit 33c0ca0

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

per/admin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ def break_to_rows(many2many, many2many_validated, is_validated, idx):
309309

310310
class OpsLearningCacheResponseAdmin(TranslationAdmin):
311311
search_fields = (
312-
"response",
313312
"id",
313+
"used_ops_learning__appeal_code__aid",
314314
)
315315
list_display = (
316316
"__str__",
@@ -319,6 +319,7 @@ class OpsLearningCacheResponseAdmin(TranslationAdmin):
319319
"insights3_title",
320320
"status",
321321
)
322+
list_filter = ("status",)
322323
used_ops_learning_in = "used_ops_learning_in"
323324
autocomplete_fields = ("used_ops_learning",)
324325
exclude = (
@@ -337,7 +338,7 @@ def regenerate_summary(self, request, queryset):
337338
generate_summary.delay(
338339
ops_learning_summary_id=obj.id,
339340
filter_data=obj.used_filters,
340-
translation_lazy=requested_lang != "en",
341+
translation_lazy=requested_lang == "en",
341342
# NOTE: Regenerating the summary will overwrite the cache
342343
overwrite_prompt_cache=True,
343344
)

per/drf_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,9 @@ class Meta:
707707
"is_validated": ("exact",),
708708
"learning": ("exact", "icontains"),
709709
"learning_validated": ("exact", "icontains"),
710+
"type_validated": ("exact", "in"),
710711
"organization_validated": ("exact",),
712+
"organization_validated__title": ("exact", "in"),
711713
"appeal_code": ("exact", "in"),
712714
"appeal_code__code": ("exact", "icontains", "in"),
713715
"appeal_code__num_beneficiaries": ("exact", "gt", "gte", "lt", "lte"),
@@ -884,12 +886,11 @@ def summary(self, request):
884886
return response.Response(OpsLearningSummarySerializer(ops_learning_summary_instance).data)
885887

886888
requested_lang = django_get_language()
887-
translation_lazy = requested_lang != "en"
888889
transaction.on_commit(
889890
lambda: generate_summary.delay(
890891
ops_learning_summary_id=ops_learning_summary_instance.id,
891892
filter_data=filter_data,
892-
translation_lazy=translation_lazy,
893+
translation_lazy=requested_lang == "en",
893894
)
894895
)
895896
return response.Response(OpsLearningSummarySerializer(ops_learning_summary_instance).data)

per/ops_learning_summary.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def _modify_summary(summary: dict) -> dict:
819819
continue
820820
if confidence_level in value["content"].lower():
821821
parts = re.split(rf"(?i)\b{confidence_level}\b", value["content"])
822-
value["content"] = parts[0]
822+
value["content"] = parts[0].strip() + "."
823823
value["confidence level"] = parts[1][1:].strip()
824824

825825
return summary
@@ -834,7 +834,7 @@ def _modify_summary(summary: dict) -> dict:
834834
def _get_or_create_summary(
835835
cls, prompt: str, prompt_hash: str, type: OpsLearningPromptResponseCache.PromptType, overwrite_prompt_cache: bool = False
836836
) -> dict:
837-
instance, created = OpsLearningPromptResponseCache.objects.get_or_create(
837+
instance, created = OpsLearningPromptResponseCache.objects.update_or_create(
838838
prompt_hash=prompt_hash,
839839
type=type,
840840
defaults={"prompt": prompt},
@@ -845,7 +845,7 @@ def _get_or_create_summary(
845845
2. If overwrite_prompt_cache is True, it regenerates the summary
846846
3. If new obj is created, it generates the summary
847847
"""
848-
if overwrite_prompt_cache or created or not bool(instance.response):
848+
if overwrite_prompt_cache or created or bool(instance.response) is False:
849849
summary = cls.generate_summary(prompt, type)
850850
instance.response = summary
851851
instance.save(update_fields=["response"])
@@ -984,6 +984,11 @@ def get_or_create_secondary_summary(
984984
type=OpsLearningPromptResponseCache.PromptType.SECONDARY,
985985
overwrite_prompt_cache=overwrite_prompt_cache,
986986
)
987+
if overwrite_prompt_cache:
988+
logger.info("Clearing the cache for secondary summary.")
989+
# NOTE: find a better way to update the cache
990+
OpsLearningComponentCacheResponse.objects.filter(filter_response=ops_learning_summary_instance).delete()
991+
OpsLearningSectorCacheResponse.objects.filter(filter_response=ops_learning_summary_instance).delete()
987992

988993
# Saving into the database
989994
cls.secondary_response_save_to_db(

0 commit comments

Comments
 (0)