-
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 3 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
| 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 | ||
|
|
@@ -35,6 +35,7 @@ | |
| ) | ||
| from dref.utils import get_dref_users | ||
| from lang.serializers import ModelSerializer | ||
| from main.translation import TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME | ||
| from main.writable_nested_serializers import NestedCreateMixin, NestedUpdateMixin | ||
| from utils.file_check import validate_file_type | ||
|
|
||
|
|
@@ -348,26 +349,33 @@ 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", | ||
| ] | ||
|
|
||
|
|
||
| class DrefSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSerializer): | ||
| class DrefSerializer(NestedUpdateMixin, NestedCreateMixin, serializers.ModelSerializer): | ||
| SUB_TOTAL_COST = 75000 | ||
| SURGE_DEPLOYMENT_COST = 10000 | ||
| SURGE_INDIRECT_COST = 5800 | ||
|
|
@@ -426,6 +434,7 @@ class Meta: | |
| "created_by", | ||
| "budget_file_preview", | ||
| "is_dref_imminent_v2", | ||
| "original_language", | ||
| ) | ||
| exclude = ( | ||
| "cover_image", | ||
|
|
@@ -602,6 +611,12 @@ def validate_budget_file_preview(self, budget_file_preview): | |
| validate_file_type(budget_file_preview) | ||
| return budget_file_preview | ||
|
|
||
| def _set_original_language(self, validated_data): | ||
| current_lang = get_language() | ||
| validated_data["original_language"] = current_lang | ||
| validated_data[TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME] = current_lang | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return validated_data | ||
|
|
||
| def create(self, validated_data): | ||
| validated_data["created_by"] = self.context["request"].user | ||
| validated_data["is_active"] = True | ||
|
|
@@ -619,7 +634,7 @@ def create(self, validated_data): | |
| # Event Description | ||
| validated_data["event_scope"] = None | ||
| validated_data["identified_gaps"] = None | ||
| # Targeted Population | ||
| # Targeted Populationtranslate_model_fields_to_english | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| validated_data["women"] = None | ||
| validated_data["men"] = None | ||
| validated_data["girls"] = None | ||
|
|
@@ -630,6 +645,8 @@ def create(self, validated_data): | |
| validated_data["communication"] = None | ||
| dref_assessment_report = super().create(validated_data) | ||
| dref_assessment_report.needs_identified.clear() | ||
| # set original language | ||
| validated_data = self._set_original_language(validated_data) | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return dref_assessment_report | ||
| # NOTE: Setting flag for only newly created DREF of type IMMINENT | ||
| if type_of_dref == Dref.DrefType.IMMINENT: | ||
|
|
@@ -639,6 +656,8 @@ def create(self, validated_data): | |
| to = {u.email for u in validated_data["users"]} | ||
| else: | ||
| to = None | ||
| # set original language | ||
|
||
| validated_data = self._set_original_language(validated_data) | ||
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")) | ||
|
|
@@ -648,6 +667,14 @@ def update(self, instance, validated_data): | |
| validated_data["modified_by"] = self.context["request"].user | ||
| modified_at = validated_data.pop("modified_at", None) | ||
| type_of_dref = validated_data.get("type_of_dref") | ||
| current_lang = get_language() | ||
| original_lang = instance.translation_module_original_language | ||
| if instance.status == Dref.Status.FINALIZED: | ||
| if current_lang != "en": | ||
| raise serializers.ValidationError(gettext("Finalized records can only be updated in English.")) | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| elif current_lang != original_lang: | ||
| raise serializers.ValidationError(gettext("Only original language is supported: %s" % original_lang)) | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if modified_at is None: | ||
| raise serializers.ValidationError({"modified_at": "Modified At is required!"}) | ||
| if type_of_dref and type_of_dref == Dref.DrefType.ASSESSMENT: | ||
|
|
@@ -692,7 +719,7 @@ def update(self, instance, validated_data): | |
| return dref | ||
|
|
||
|
|
||
| class DrefOperationalUpdateSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSerializer): | ||
| class DrefOperationalUpdateSerializer(NestedUpdateMixin, NestedCreateMixin, serializers.ModelSerializer): | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MAX_NUMBER_OF_IMAGES = 4 | ||
| national_society_actions = NationalSocietyActionSerializer(many=True, required=False) | ||
| needs_identified = IdentifiedNeedSerializer(many=True, required=False) | ||
|
|
@@ -723,6 +750,7 @@ class Meta: | |
| "operational_update_number", | ||
| "modified_by", | ||
| "created_by", | ||
| "original_language", | ||
| ) | ||
| exclude = ( | ||
| "images", | ||
|
|
@@ -776,6 +804,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 +928,8 @@ 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
|
||
| validated_data[TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME] = 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 = [ | ||
|
|
@@ -1069,6 +1099,15 @@ def create(self, validated_data): | |
| def update(self, instance, validated_data): | ||
| validated_data["modified_by"] = self.context["request"].user | ||
| modified_at = validated_data.pop("modified_at", None) | ||
|
|
||
| current_lang = get_language() | ||
| original_lang = instance.translation_module_original_language | ||
| if instance.status == Dref.Status.FINALIZED: | ||
| if current_lang != "en": | ||
| raise serializers.ValidationError(gettext("Finalized records can only be updated in English.")) | ||
| elif current_lang != original_lang: | ||
| raise serializers.ValidationError(gettext("Only original language is supported: %s" % original_lang)) | ||
|
|
||
| if modified_at is None: | ||
| raise serializers.ValidationError({"modified_at": "Modified At is required!"}) | ||
|
|
||
|
|
@@ -1078,7 +1117,7 @@ def update(self, instance, validated_data): | |
| return super().update(instance, validated_data) | ||
|
|
||
|
|
||
| class DrefFinalReportSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSerializer): | ||
| class DrefFinalReportSerializer(NestedUpdateMixin, NestedCreateMixin, serializers.ModelSerializer): | ||
| MAX_NUMBER_OF_PHOTOS = 4 | ||
| SUB_TOTAL_COST = 75000 | ||
| national_society_actions = NationalSocietyActionSerializer(many=True, required=False) | ||
|
|
@@ -1112,6 +1151,7 @@ class Meta: | |
| "created_by", | ||
| "financial_report_preview", | ||
| "is_dref_imminent_v2", | ||
| "original_language", | ||
| ) | ||
| exclude = ( | ||
| "images", | ||
|
|
@@ -1222,13 +1262,16 @@ 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 | ||
| validated_data[TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME] = 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 | ||
|
|
@@ -1511,6 +1554,13 @@ def create(self, validated_data): | |
|
|
||
| def update(self, instance, validated_data): | ||
| modified_at = validated_data.pop("modified_at", None) | ||
| current_lang = get_language() | ||
susilnem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| original_lang = instance.translation_module_original_language | ||
| if instance.status == Dref.Status.FINALIZED: | ||
| if current_lang != "en": | ||
| raise serializers.ValidationError(gettext("Finalized records can only be updated in English.")) | ||
| elif current_lang != original_lang: | ||
| raise serializers.ValidationError(gettext("Only original language is supported: %s" % original_lang)) | ||
| if modified_at is None: | ||
| raise serializers.ValidationError({"modified_at": "Modified At is required!"}) | ||
| if modified_at and instance.modified_at and modified_at < instance.modified_at: | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.