Skip to content

Commit

Permalink
Merge branch 'OC-13108' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gushil committed Oct 22, 2020
2 parents 837c98b + 521ae65 commit fd35ed6
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions kpi/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,57 @@ def _adjust_content_custom_column(self, content):

def _adjust_content_media_column(self, content):
survey = content.get('survey', [])
media_columns = ['media::audio', 'media::image', 'media::video']
non_dc_media_columns = ['audio', 'image', 'video']
for survey_col_idx in range(len(survey)):
survey_col = survey[survey_col_idx]
for media_column in media_columns:
if media_column in survey_col:
content['survey'][survey_col_idx][media_column[7:]] = survey_col[media_column]
del content['survey'][survey_col_idx][media_column]
for non_dc_media_column in non_dc_media_columns:
oc_non_dc_media_column = "oc_{}".format(non_dc_media_column)
if oc_non_dc_media_column in survey_col.keys():
survey_col[non_dc_media_column] = survey_col[oc_non_dc_media_column]
del survey_col[oc_non_dc_media_column]

translated = content.get('translated', [])
for translated_idx in range(len(translated)):
for non_dc_media_column in non_dc_media_columns:
oc_non_dc_media_column = "oc_{}".format(non_dc_media_column)
if oc_non_dc_media_column == translated[translated_idx]:
translated[translated_idx] = non_dc_media_column

def _adjust_content_media_column_before_standardize(self, content):

def _adjust_media_columns(survey, non_dc_cols):
for survey_col_idx in range(len(survey)):
survey_col = survey[survey_col_idx]
survey_col_keys = list(survey_col.keys())
for survey_col_key in survey_col_keys:
if survey_col_key in non_dc_cols:
survey_col["oc_{}".format(survey_col_key)] = survey_col[survey_col_key]
del survey_col[survey_col_key]

survey = content.get('survey', [])

survey_col_key_list = []
for survey_col_idx in range(len(survey)):
survey_col = survey[survey_col_idx]
survey_col_key_list = survey_col_key_list + list(survey_col.keys())

media_columns = {"audio": "media::audio", "image": "media::image", "video": 'media::video'}

for media_column_key in media_columns.keys():
non_dc_col = media_column_key
non_dc_cols = [s for s in survey_col_key_list if s.startswith(non_dc_col)]

if len(non_dc_cols) > 0:
_adjust_media_columns(survey, non_dc_cols)

if 'translations' in content:
translated = content.get('translated', [])
non_dc_media_columns = ['audio', 'image', 'video']
for translated_idx in range(len(translated)):
for non_dc_media_column in non_dc_media_columns:
if non_dc_media_column == translated[translated_idx]:
translated[translated_idx] = "oc_{}".format(non_dc_media_column)


def _revert_custom_column(self, content):
survey = content.get('survey', [])
Expand All @@ -821,9 +865,10 @@ def adjust_content_on_save(self):
asset.save(adjust_content=False)
'''
self._adjust_content_custom_column(self.content)
self._adjust_content_media_column_before_standardize(self.content)
self._standardize(self.content)
self._revert_custom_column(self.content)
self._adjust_content_media_column(self.content)
self._revert_custom_column(self.content)
self._make_default_translation_first(self.content)
self._strip_empty_rows(self.content)
self._assign_kuids(self.content)
Expand Down

0 comments on commit fd35ed6

Please sign in to comment.