-
Notifications
You must be signed in to change notification settings - Fork 7
Add finalize dref api #2558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sudip-khanal
wants to merge
14
commits into
project/dref-translation
Choose a base branch
from
feat/add-finalize-dref-api
base: project/dref-translation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add finalize dref api #2558
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0ddafb6
refactor(dref): refactor is published to staus
sudip-khanal 9e969d2
feat(dref): add dref finalize api
sudip-khanal 55d133b
feat(dref): add finalize api for Dref operational update and final re…
sudip-khanal 3c7741c
fix(dref): update finalize API logic
sudip-khanal 703936d
feat(dref): add translation completion check
sudip-khanal f658455
feat(dref): migrate original_language field with 'en' for existing re…
sudip-khanal 8fa4716
fix(dref): update finalize api and translation check logic
sudip-khanal ce100f5
feat(dref): add translation retrigger logic in finalize API
sudip-khanal 7da4e3c
chore(dref): remove skip_fields from dref translation
sudip-khanal c4b29f0
fix(dref): set original_language from current active language for dre…
sudip-khanal 9153b9f
fix(dref): rename original_language field to starting_language
sudip-khanal 6c74eae
fixup! fix(dref): rename original_language field to starting_language
sudip-khanal 4a70d41
chore(translation): update and sync translation files across all locale
sudip-khanal aa8b32c
fix: redis lock handling and update translation check method
sudip-khanal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
43 changes: 43 additions & 0 deletions
43
dref/migrations/0086_alter_dref_status_alter_dreffinalreport_status_and_more.py
This file contains hidden or 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,43 @@ | ||
| # Generated by Django 4.2.19 on 2025-10-11 11:56 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def update_original_language(apps, schema_editor): | ||
| """ | ||
| Populate the original_language field with 'en' for all existing records. | ||
| """ | ||
| models = [ | ||
| "Dref", | ||
| "DrefOperationalUpdate", | ||
| "DrefFinalReport", | ||
| ] | ||
| for model_name in models: | ||
| Model = apps.get_model("dref", model_name) | ||
| Model.objects.filter(original_language__isnull=True).update(original_language="en") | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('dref', '0085_remove_dref_is_published_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='dref', | ||
| name='status', | ||
| field=models.IntegerField(choices=[(1, 'Draft'), (2, 'Finalized'), (3, 'Approved')], default=1, verbose_name='status'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='dreffinalreport', | ||
| name='status', | ||
| field=models.IntegerField(choices=[(1, 'Draft'), (2, 'Finalized'), (3, 'Approved')], default=1, verbose_name='status'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='drefoperationalupdate', | ||
| name='status', | ||
| field=models.IntegerField(choices=[(1, 'Draft'), (2, 'Finalized'), (3, 'Approved')], default=1, verbose_name='status'), | ||
| ), | ||
| migrations.RunPython(update_original_language,reverse_code=migrations.RunPython.noop) | ||
| ] |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| from django.contrib.auth.models import User | ||
| from django.db import models, transaction | ||
| from django.utils import timezone | ||
| from django.utils.translation import gettext | ||
| from django.utils.translation import get_language, gettext | ||
| from django.utils.translation import gettext_lazy as _ | ||
| from drf_spectacular.utils import extend_schema_field | ||
| from rest_framework import serializers | ||
|
|
@@ -205,6 +205,7 @@ class MiniDrefSerializer(serializers.ModelSerializer): | |
| unpublished_final_report_count = serializers.SerializerMethodField() | ||
| operational_update_details = serializers.SerializerMethodField() | ||
| final_report_details = serializers.SerializerMethodField() | ||
| original_language = serializers.CharField(read_only=True) | ||
|
|
||
| class Meta: | ||
| model = Dref | ||
|
|
@@ -235,6 +236,7 @@ class Meta: | |
| "status", | ||
| "status_display", | ||
| "date_of_approval", | ||
| "original_language", | ||
| ] | ||
|
|
||
| @extend_schema_field(MiniOperationalUpdateActiveSerializer(many=True)) | ||
|
|
@@ -348,22 +350,29 @@ def get_image_url(self, identifiedneed) -> str: | |
|
|
||
|
|
||
| class MiniOperationalUpdateSerializer(ModelSerializer): | ||
| status_display = serializers.CharField(source="get_status_display", read_only=True) | ||
|
|
||
| class Meta: | ||
| model = DrefOperationalUpdate | ||
| fields = [ | ||
| "id", | ||
| "title", | ||
| "operational_update_number", | ||
| "status", | ||
| "status_display", | ||
| ] | ||
|
|
||
|
|
||
| class MiniDrefFinalReportSerializer(ModelSerializer): | ||
| status_display = serializers.CharField(source="get_status_display", read_only=True) | ||
|
|
||
| class Meta: | ||
| model = DrefFinalReport | ||
| fields = [ | ||
| "id", | ||
| "title", | ||
| "status", | ||
| "status_display", | ||
| ] | ||
|
|
||
|
|
||
|
|
@@ -426,6 +435,7 @@ class Meta: | |
| "created_by", | ||
| "budget_file_preview", | ||
| "is_dref_imminent_v2", | ||
| "original_language", | ||
| ) | ||
| exclude = ( | ||
| "cover_image", | ||
|
|
@@ -603,6 +613,8 @@ def validate_budget_file_preview(self, budget_file_preview): | |
| return budget_file_preview | ||
|
|
||
| def create(self, validated_data): | ||
| current_lang = get_language() | ||
| validated_data["original_language"] = current_lang | ||
| validated_data["created_by"] = self.context["request"].user | ||
| validated_data["is_active"] = True | ||
| type_of_dref = validated_data.get("type_of_dref") | ||
|
|
@@ -639,6 +651,8 @@ def create(self, validated_data): | |
| to = {u.email for u in validated_data["users"]} | ||
| else: | ||
| to = None | ||
| # set original language | ||
|
||
| validated_data["original_language"] = current_lang | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dref = super().create(validated_data) | ||
| if to: | ||
| transaction.on_commit(lambda: send_dref_email.delay(dref.id, list(to), "New")) | ||
|
|
@@ -723,6 +737,7 @@ class Meta: | |
| "operational_update_number", | ||
| "modified_by", | ||
| "created_by", | ||
| "original_language", | ||
| ) | ||
| exclude = ( | ||
| "images", | ||
|
|
@@ -776,6 +791,7 @@ def validate_images_file(self, images): | |
|
|
||
| def create(self, validated_data): | ||
| dref = validated_data["dref"] | ||
| current_language = get_language() | ||
susilnem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dref_operational_update = DrefOperationalUpdate.objects.filter(dref=dref).order_by("-operational_update_number").first() | ||
| validated_data["created_by"] = self.context["request"].user | ||
| if not dref_operational_update: | ||
|
|
@@ -899,7 +915,7 @@ def create(self, validated_data): | |
| validated_data["is_man_made_event"] = dref.is_man_made_event | ||
| validated_data["event_text"] = dref.event_text | ||
| validated_data["did_national_society"] = dref.did_national_society | ||
|
|
||
| validated_data["original_language"] = current_language | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| operational_update = super().create(validated_data) | ||
| # XXX: Copy files from DREF (Only nested serialized fields) | ||
| nested_serialized_file_fields = [ | ||
|
|
@@ -1112,6 +1128,7 @@ class Meta: | |
| "created_by", | ||
| "financial_report_preview", | ||
| "is_dref_imminent_v2", | ||
| "original_language", | ||
| ) | ||
| exclude = ( | ||
| "images", | ||
|
|
@@ -1222,13 +1239,15 @@ def create(self, validated_data): | |
| # here check if there is operational update for corresponding dref | ||
| # if yes copy from the latest operational update | ||
| # else copy from dref | ||
| current_language = get_language() | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dref = validated_data["dref"] | ||
| dref_operational_update = ( | ||
| DrefOperationalUpdate.objects.filter(dref=dref, status=Dref.Status.APPROVED) | ||
| .order_by("-operational_update_number") | ||
| .first() | ||
| ) | ||
| validated_data["created_by"] = self.context["request"].user | ||
| validated_data["original_language"] = current_language | ||
| # NOTE: Checks and common fields for the new dref final reports of new dref imminents | ||
| if dref.type_of_dref == Dref.DrefType.IMMINENT and dref.is_dref_imminent_v2: | ||
| validated_data["is_dref_imminent_v2"] = True | ||
|
|
@@ -1526,6 +1545,7 @@ class CompletedDrefOperationsSerializer(serializers.ModelSerializer): | |
| status_display = serializers.CharField(source="get_status_display", read_only=True) | ||
| application_type = serializers.SerializerMethodField() | ||
| application_type_display = serializers.SerializerMethodField() | ||
| original_language = serializers.CharField(read_only=True) | ||
|
|
||
| class Meta: | ||
| model = DrefFinalReport | ||
|
|
@@ -1543,6 +1563,7 @@ class Meta: | |
| "dref", | ||
| "status", | ||
| "status_display", | ||
| "original_language", | ||
| ) | ||
|
|
||
| def get_application_type(self, obj) -> str: | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason on why we are modifying existing migration file?
How we are planning to run this in local and already deployed instances