Skip to content

Commit

Permalink
Merge pull request #4100 from Engerrs/4094-org-and-grp-custom-fields-…
Browse files Browse the repository at this point in the history
…deletion

[#4094] Update Orgs/Groups logic for custom fields delete and update
  • Loading branch information
Konstantin Sivakov authored and tino097 committed Mar 15, 2018
1 parent 87ef07f commit 7c2f4d4
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -132,19 +132,6 @@ def package_extras_save(extra_dicts, obj, context):
state = 'deleted'
extra.state = state

def group_extras_save(extras_dicts, context):

model = context["model"]
session = context["session"]

result_dict = {}
for extra_dict in extras_dicts:
if extra_dict.get("deleted"):
continue
result_dict[extra_dict["key"]] = extra_dict["value"]

return result_dict

def package_tag_list_save(tag_dicts, package, context):
allow_partial_update = context.get("allow_partial_update", False)
if tag_dicts is None and allow_partial_update:
Expand Down Expand Up @@ -411,14 +398,17 @@ def group_dict_save(group_dict, context, prevent_packages_update=False):
'Groups: %r Tags: %r', pkgs_edited, group_users_changed,
group_groups_changed, group_tags_changed)

extras = group_extras_save(group_dict.get("extras", {}), context)
if extras or not allow_partial_update:
old_extras = set(group.extras.keys())
new_extras = set(extras.keys())
for key in old_extras - new_extras:
extras = group_dict.get("extras", [])
new_extras = {i['key'] for i in extras}
if extras:
old_extras = group.extras
for key in set(old_extras) - new_extras:
del group.extras[key]
for key in new_extras:
group.extras[key] = extras[key]
for x in extras:
if 'deleted' in x and x['key'] in old_extras:
del group.extras[x['key']]
continue
group.extras[x['key']] = x['value']

# We will get a list of packages that we have either added or
# removed from the group, and trigger a re-index.
Expand Down

0 comments on commit 7c2f4d4

Please sign in to comment.