Skip to content

Conversation

@sudip-khanal
Copy link
Contributor

@sudip-khanal sudip-khanal commented Sep 22, 2025

Addresses

Changes

  • Add finalize api for dref
  • Add translation task
  • Add finalize api for dref final report
  • Add finalize api for dref operational update

Checklist

Things that should succeed before merging.

  • Updated/ran unit tests
  • Updated CHANGELOG.md

Release

If there is a version update, make sure to tag the repository with the latest version.

@sudip-khanal sudip-khanal mentioned this pull request Sep 22, 2025
2 tasks
@sudip-khanal sudip-khanal force-pushed the feat/update-dref-status branch 2 times, most recently from 89a6cb8 to 7bebad0 Compare September 26, 2025 04:21
@sudip-khanal sudip-khanal force-pushed the feat/add-finalize-dref-api branch from 9384f6a to 6745b93 Compare September 26, 2025 04:24
@susilnem susilnem force-pushed the feat/update-dref-status branch 2 times, most recently from 8de1330 to 9d7c227 Compare October 7, 2025 07:09
Base automatically changed from feat/update-dref-status to project/dref-translation October 7, 2025 07:20
main/lock.py Outdated

OPERATION_LEARNING_SUMMARY = _BASE + "-operation-learning-summary-{0}"
OPERATION_LEARNING_SUMMARY_EXPORT = _BASE + "-operation-learning-summary-export-{0}"
DREF_TRANSLATION = _BASE + "-dref-translation-{0}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to add model table name in the key...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change DREF_TRANSLATION to MODEL_TRANSLATION
"-{db_table_name}-translation-{0}"

dref/utils.py Outdated
"""
Trigger translation task with Redis lock.
"""
with redis_lock(key=RedisLockKey.DREF_TRANSLATION, id=instance.pk) as acquired:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock needs to be in the job function, not the trigger function

Copy link
Member

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

to = {u.email for u in validated_data["users"]}
else:
to = None
# set original language
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a TODO?

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a or here?

# 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a or here?

dref/views.py Outdated
raise serializers.ValidationError(gettext("Cannot be finalized because it is already %s") % dref.get_status_display())
if not is_translation_complete(dref):
trigger_translation(dref)
raise serializers.ValidationError(gettext("Translation is not completed. Please try again later."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add something like "the translation is triggered, so wait and try again" @udaynwa

dref/views.py Outdated
if dref.status in [Dref.Status.FINALIZED, Dref.Status.APPROVED]:
raise serializers.ValidationError(gettext("Cannot be finalized because it is already %s") % dref.get_status_display())
if not is_translation_complete(dref):
trigger_translation(dref)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we triggering related tables translation in another PR?

# Check request language
if current_language not in valid_languages:
raise serializers.ValidationError(
gettext(f"Language must be either '{valid_languages[0]}' or '{valid_languages[1]}'.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gettext(f"Language must be either '{valid_languages[0]}' or '{valid_languages[1]}'.")
gettext(f"Cannot create OperationalUpdate with the current language {current_language}, language must be either '{valid_languages[0]}' or '{valid_languages[1]}'.")

@udaynwa Verify?

gettext(f"Language must be either '{valid_languages[0]}' or '{valid_languages[1]}'.")
)
# Check payload language
language = validated_data.get("starting_language")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
language = validated_data.get("starting_language")
starting_language = validated_data.get("starting_language")

Firstly, We need to check if the language and body stating langauge are same or not!

valid_languages = [dref.starting_language, dref.translation_module_original_language]
# Check request language
if current_language not in valid_languages:
raise serializers.ValidationError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update message

permission_classes=[permissions.IsAuthenticated, DenyGuestUserPermission],
)
def finalize(self, request, pk=None, version=None):
field_report = self.get_object()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
field_report = self.get_object()
final_report = self.get_object()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants