Commit 7fd7a9eb authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

content_translation: delete from content_translation table if translated text is empty.

also set _p_changed=True in deletePropertyTranslation().
parent 4f5814b2
<dtml-let content_translation_dict_list="CatalogTool_getContentTranslationDictList(Base_getContentTranslationTargetObject)"> <dtml-let content_translation_dict_list="CatalogTool_getContentTranslationDictList(Base_getContentTranslationTargetObject)">
<dtml-if "content_translation_dict_list"> <dtml-let document_list="[]" delete_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(content_translation_dict_list))">
<dtml-if "content_translation_dict_list[loop_item]['translated_text']">
<dtml-call expr="document_list.append(loop_item)">
<dtml-else>
<dtml-call expr="delete_list.append(loop_item)">
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(document_list) > 0">
REPLACE INTO content_translation REPLACE INTO content_translation
VALUES VALUES
<dtml-in "content_translation_dict_list"> <dtml-in prefix="loop" expr="document_list">
(<dtml-sqlvar "_['sequence-item']['uid']" type=int>, (<dtml-sqlvar "content_translation_dict_list[loop_item]['uid']" type=int>,
<dtml-sqlvar "_['sequence-item']['property_name']" type=string>, <dtml-sqlvar "content_translation_dict_list[loop_item]['property_name']" type=string>,
<dtml-sqlvar "_['sequence-item']['content_language']" type=string>, <dtml-sqlvar "content_translation_dict_list[loop_item]['content_language']" type=string>,
<dtml-sqlvar "_['sequence-item']['translated_text']" type=string> <dtml-sqlvar "content_translation_dict_list[loop_item]['translated_text']" type=string>
) )
<dtml-unless sequence-end>,</dtml-unless> <dtml-unless sequence-end>,</dtml-unless>
</dtml-in> </dtml-in>
</dtml-if>
<dtml-if expr="_.len(delete_list) > 0">
<dtml-var sql_delimiter>
DELETE FROM content_translation
WHERE
(uid, property_name, content_language) IN (<dtml-in prefix="loop" expr="delete_list">
(<dtml-sqlvar "content_translation_dict_list[loop_item]['uid']" type=int>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['property_name']" type=string>,
<dtml-sqlvar "content_translation_dict_list[loop_item]['content_language']" type=string>
)
<dtml-unless sequence-end>,</dtml-unless>
</dtml-in>)
</dtml-if> </dtml-if>
</dtml-let> </dtml-let>
</dtml-let>
...@@ -36,14 +36,12 @@ for document in document_list: ...@@ -36,14 +36,12 @@ for document in document_list:
temporary_translated_text = translation_method(language=content_language) temporary_translated_text = translation_method(language=content_language)
if original_text != temporary_translated_text: if original_text != temporary_translated_text:
translated_text = temporary_translated_text translated_text = temporary_translated_text
if translated_text:
temporary_result.append({'uid': uid, temporary_result.append({'uid': uid,
'property_name': property_name, 'property_name': property_name,
'content_language': content_language, 'content_language': content_language,
'translated_text': translated_text, 'translated_text': translated_text,
}) })
# also add original content # also add original content
if original_text is not None:
temporary_result.append({'uid': uid, temporary_result.append({'uid': uid,
'property_name': property_name, 'property_name': property_name,
'content_language': '', 'content_language': '',
......
...@@ -66,6 +66,7 @@ class PropertyTranslatableBuiltInDictMixIn: ...@@ -66,6 +66,7 @@ class PropertyTranslatableBuiltInDictMixIn:
def deletePropertyTranslation(self, property_id, language): def deletePropertyTranslation(self, property_id, language):
try: try:
del self._getTranslationDict()[(property_id, language)] del self._getTranslationDict()[(property_id, language)]
self._p_changed = True
except KeyError: except KeyError:
pass pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment