Skip to content

Commit

Permalink
Display changes to metadata fields added by extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
hayley-leblanc committed Jul 24, 2019
1 parent 680ede0 commit 3fc42ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 34 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -2692,6 +2692,7 @@ def sanitize_id(id_):
@core_helper
def compare_pkg_dicts(original, new):
# TODO: clean this up or make it shorter somehow
# TODO: what happens if someone REMOVES a value from a field that previously had a value?

change_list = []

Expand Down Expand Up @@ -2851,6 +2852,39 @@ def compare_pkg_dicts(original, new):
else:
change_list.append(["Changed the version of", s.join(seq1), "to", new['version']])

# list of the default metadata fields for a dataset
# any fields that are not part of this list are custom fields added by a user or extension
fields = ['owner_org', 'maintainer', 'maintainer_email', 'relationships_as_object', 'private', 'num_tags',
'id', 'metadata_created', 'metadata_modified', 'author', 'author_email', 'state', 'version',
'license_id', 'type', 'resources', 'num_resources', 'tags', 'title', 'groups', 'creator_user_id',
'relationships_as_subject', 'name', 'isopen', 'url', 'notes', 'license_title', 'extras',
'license_url', 'organization', 'revision_id']
fields_set = set(fields)

# if there are any fields from extensions that are in the new dataset and
# have been updated, print a generic message stating that
original_set = set(original.keys())
new_set = set(new.keys())

addl_fields_new = new_set - fields_set # set of additional fields in the new dictionary
addl_fields_original = original_set - fields_set # set of additional fields in the original dictionary
addl_fields = addl_fields_new.intersection(addl_fields_original) # set of additional fields in both

# do NOT display a change if any additional fields have been added or deleted,
# since that is not a change made by the user from the web interface

# if additional fields have been changed
addl_fields_list = list(addl_fields)
for field in addl_fields_list:
if original[field] != new[field]:
if original[field]:
change_list.append(["Changed field", field.capitalize(), "to", new[field], "(previously", original[field] + ")", "in", s.join(seq1)])

# check the extras field to see if anything has been added, deleted, or changed
# that is where custom fields added via the web interface go - they do not become
# actual fields in a package dict
# TODO: add this ^^



return change_list
3 changes: 1 addition & 2 deletions ckan/templates/package/changes.html
Expand Up @@ -31,10 +31,9 @@ <h1 class="page-heading">{{ _('Changes') }}</h1>

{% for i in range(1, activity_diff.activities|length) %}
On {{ h.render_datetime(activity_diff.activities[1].timestamp, with_hours=True, with_seconds=True) }}, {{ h.linked_user(activity_diff.activities[1].user_id) }}:
<br>

{% set changes = h.compare_pkg_dicts(activity_diff.activities[0].data.package, activity_diff.activities[1].data.package) %}
<ul >
<ul>
{% for change in changes %}
<li>
{% for element in change %}
Expand Down

0 comments on commit 3fc42ce

Please sign in to comment.