-
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
base: project/dref-translation
Are you sure you want to change the base?
Add finalize dref api #2558
Changes from 8 commits
0ddafb6
9e969d2
55d133b
3c7741c
703936d
f658455
8fa4716
ce100f5
7da4e3c
c4b29f0
9153b9f
6c74eae
4a70d41
aa8b32c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
| ] | ||
|
|
||
|
|
||
|
|
@@ -475,7 +484,7 @@ def validate(self, data): | |
| if self.instance and self.instance.status == Dref.Status.APPROVED: | ||
| raise serializers.ValidationError("Approved Dref can't be changed. Please contact Admin") | ||
| if self.instance and DrefFinalReport.objects.filter(dref=self.instance, status=Dref.Status.APPROVED).exists(): | ||
| raise serializers.ValidationError(gettext("Can't Update %s dref for approved Field Report" % self.instance.id)) | ||
| raise serializers.ValidationError(gettext("Can't Update %s dref for approved Final Report" % self.instance.id)) | ||
| if operation_timeframe and is_assessment_report and operation_timeframe > 30: | ||
| raise serializers.ValidationError( | ||
| gettext("Operation timeframe can't be greater than %s for assessment_report" % self.MAX_OPERATION_TIMEFRAME) | ||
|
|
@@ -639,6 +648,7 @@ def create(self, validated_data): | |
| to = {u.email for u in validated_data["users"]} | ||
| else: | ||
| to = None | ||
| # set original language | ||
|
||
| dref = super().create(validated_data) | ||
| if to: | ||
| transaction.on_commit(lambda: send_dref_email.delay(dref.id, list(to), "New")) | ||
|
|
@@ -776,6 +786,11 @@ def validate_images_file(self, images): | |
|
|
||
| def create(self, validated_data): | ||
| dref = validated_data["dref"] | ||
| language = validated_data.get("original_language") | ||
| if language != dref.original_language and language != dref.translation_module_original_language: | ||
|
||
| raise serializers.ValidationError( | ||
| gettext(f"Language must be either '{dref.original_language}' or '{dref.translation_module_original_language}'.") | ||
| ) | ||
| 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 +914,6 @@ 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 | ||
|
|
||
| operational_update = super().create(validated_data) | ||
| # XXX: Copy files from DREF (Only nested serialized fields) | ||
| nested_serialized_file_fields = [ | ||
|
|
@@ -1223,6 +1237,11 @@ def create(self, validated_data): | |
| # if yes copy from the latest operational update | ||
| # else copy from dref | ||
| dref = validated_data["dref"] | ||
| language = validated_data.get("original_language") | ||
| if language != dref.original_language and language != dref.translation_module_original_language: | ||
|
||
| raise serializers.ValidationError( | ||
| gettext(f"Language must be either '{dref.original_language}' or '{dref.translation_module_original_language}'.") | ||
| ) | ||
| dref_operational_update = ( | ||
| DrefOperationalUpdate.objects.filter(dref=dref, status=Dref.Status.APPROVED) | ||
| .order_by("-operational_update_number") | ||
|
|
@@ -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: | ||
|
|
||
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