Skip to content

Commit

Permalink
Merge pull request #1905 from SEED-platform/1903-column-renaming
Browse files Browse the repository at this point in the history
Fixes column renaming issues
  • Loading branch information
nllong committed Jun 21, 2019
2 parents ab48d0d + fe33e36 commit bf8849c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions seed/models/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ def _serialize_for_extra_data(column_value):
try:
with transaction.atomic():
# check if the new_column already exists
new_column = Column.objects.filter(table_name=self.table_name, column_name=new_column_name)
new_column = Column.objects.filter(table_name=self.table_name, column_name=new_column_name,
organization=self.organization)
if len(new_column) > 0:
if not force:
return [False, 'New column already exists, specify overwrite data if desired']
Expand Down Expand Up @@ -680,14 +681,14 @@ def _serialize_for_extra_data(column_value):
# go through the data and move it to the new field. I'm not sure yet on how long this is
# going to take to run, so we may have to move this to a background task
orig_data = STR_TO_CLASS[self.table_name].objects.filter(
organization=new_column.organization,
organization=self.organization,
data_state=DATA_STATE_MATCHING
)
if new_column.is_extra_data:
if self.is_extra_data:
for datum in orig_data:
datum.extra_data[new_column.column_name] = datum.extra_data[self.column_name]
del datum.extra_data[self.column_name]
datum.extra_data[new_column.column_name] = datum.extra_data.get(self.column_name, None)
datum.extra_data.pop(self.column_name, None)
datum.save()
else:
for datum in orig_data:
Expand All @@ -698,8 +699,8 @@ def _serialize_for_extra_data(column_value):
else:
if self.is_extra_data:
for datum in orig_data:
setattr(datum, new_column.column_name, datum.extra_data[self.column_name])
del datum.extra_data[self.column_name]
setattr(datum, new_column.column_name, datum.extra_data.get(self.column_name, None))
datum.extra_data.pop(self.column_name, None)
datum.save()
else:
for datum in orig_data:
Expand Down Expand Up @@ -1312,7 +1313,7 @@ def retrieve_all(org_id, inventory_type=None, only_used=False):
@staticmethod
def retrieve_priorities(org_id):
"""
Return the list of priorties for the columns. Result will be in the form of:
Return the list of priorities for the columns. Result will be in the form of:
.. code-block:: json
Expand Down

0 comments on commit bf8849c

Please sign in to comment.