Skip to content

Commit 36466c1

Browse files
committed
Track origial language in Field Report
TODO: Migrate FR from manual save to serializer
1 parent 77668a6 commit 36466c1

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

api/drf_views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,9 @@ def save_meta(self, fieldreport, meta, is_update=False):
10021002
for action_taken in meta["actions_taken"]:
10031003
actions = action_taken["actions"]
10041004
del action_taken["actions"]
1005+
action_taken[TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME] = django_get_language()
10051006
actions_taken = ActionsTaken.objects.create(field_report=fieldreport, **action_taken)
1007+
CreateFieldReportSerializer.trigger_field_translation(actions_taken)
10061008
actions_taken.actions.add(*actions)
10071009

10081010
if "contacts" in meta:
@@ -1032,7 +1034,9 @@ def create_event(self, report):
10321034
auto_generated=True,
10331035
auto_generated_source=SOURCES["new_report"],
10341036
visibility=report.visibility,
1037+
**{TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME: django_get_language()},
10351038
)
1039+
CreateFieldReportSerializer.trigger_field_translation(event)
10361040
report.event = event
10371041
report.save()
10381042
return event

api/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ class Meta:
11511151
'disaster_start_date', 'created_at', 'appeals',
11521152
)
11531153

1154+
11541155
class CountryOfFieldReportToReviewSerializer(ModelSerializer):
11551156
class Meta:
11561157
model = CountryOfFieldReportToReview

lang/serializers.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,31 +119,20 @@ def trigger_field_translation(cls, instance):
119119
if getattr(instance, TRANSLATOR_SKIP_FIELD_NAME):
120120
# Skip translation
121121
return
122-
if not settings.TESTING:
123-
transaction.on_commit(
124-
lambda: translate_model_fields.delay(get_model_name(type(instance)), instance.pk)
125-
)
126-
else:
127-
# NOTE: For test case run the process directly (Translator will mock the generated text)
128-
transaction.on_commit(
129-
lambda: translate_model_fields(get_model_name(type(instance)), instance.pk)
130-
)
122+
transaction.on_commit(
123+
lambda: translate_model_fields.delay(get_model_name(type(instance)), instance.pk)
124+
)
131125

132126
@classmethod
133127
def trigger_field_translation_in_bulk(cls, model, instances):
134128
pks = [
135129
instance.pk for instance in instances
136130
if not getattr(instance, TRANSLATOR_SKIP_FIELD_NAME)
137131
]
138-
if not settings.TESTING:
132+
if pks:
139133
transaction.on_commit(
140134
lambda: translate_model_fields_in_bulk.delay(get_model_name(model), pks)
141135
)
142-
else:
143-
# NOTE: For test case run the process directly (Translator will mock the generated text)
144-
transaction.on_commit(
145-
lambda: translate_model_fields_in_bulk(get_model_name(model), pks)
146-
)
147136

148137
@classmethod
149138
def reset_and_trigger_translation_fields(cls, instance, created=False):

main/test_case.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def capture_on_commit_callbacks(cls, *, using=DEFAULT_DB_ALIAS, execute=False):
156156
SUSPEND_SIGNALS=True,
157157
HAYSTACK_CONNECTIONS=TEST_HAYSTACK_CONNECTIONS,
158158
CACHES=TEST_CACHES,
159+
AUTO_TRANSLATION_TRANSLATOR='lang.translation.DummyTranslator',
159160
)
160161
class APITestCase(GoAPITestMixin, test.APITestCase):
161162
def setUp(self):
@@ -172,6 +173,7 @@ def tearDown(self):
172173
SUSPEND_SIGNALS=True,
173174
HAYSTACK_CONNECTIONS=TEST_HAYSTACK_CONNECTIONS,
174175
CACHES=TEST_CACHES,
176+
AUTO_TRANSLATION_TRANSLATOR='lang.translation.DummyTranslator',
175177
)
176178
class SnapshotTestCase(GoAPITestMixin, django_snapshottest.TestCase):
177179
maxDiff = None

0 commit comments

Comments
 (0)