Skip to content

Commit

Permalink
Refactor Publication Workflow
Browse files Browse the repository at this point in the history
+ Fixes issue with publication date being updates on all approvals
+ Adds column to Dataset History admin that lists the metadata changes.

Issue #348
  • Loading branch information
vchendrix committed Mar 15, 2022
1 parent 4188552 commit 70d6ba9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion archive_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,36 @@
from django.shortcuts import redirect, render
from django.urls import path
from django.utils.datetime_safe import datetime
from django.utils.safestring import mark_safe

from archive_api.models import DataSet, DataSetDownloadLog, MeasurementVariable, Person, Plot, Site
from simple_history.admin import SimpleHistoryAdmin

admin.site.register(DataSet,SimpleHistoryAdmin)

@admin.register(DataSet)
class DataSetHistoryAdmin(SimpleHistoryAdmin):
list_display = ["data_set_id", "version", "status", "name"]
history_list_display = ["list_changes"]
search_fields = ['name', 'status', "ngt_id", "version"]

def list_changes(self, obj):
"""
Lists the changes between revisions in the Admin UI
See: https://django-simple-history.readthedocs.io/en/latest/history_diffing.html
:param obj:
:return:
"""
diff = []
if obj.prev_record:
delta = obj.diff_against(obj.prev_record)
for change in delta.changes:
diff.append("<b>- {}:</b> changed from `{}` to `{}`".format(change.field, change.old, change.new))

# Mark safe (https://docs.djangoproject.com/en/4.0/ref/utils/#django.utils.safestring.mark_safe)
return mark_safe("\n<br>".join(diff))


class CsvImportForm(forms.Form):
Expand Down
2 changes: 1 addition & 1 deletion archive_api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def change_status(self, request, status):
dataset.archive.name = "{}/{}".format(new_path, filename)
elif status == APPROVED:
dataset.approval_date = now
if original_status == SUBMITTED:
if original_status == SUBMITTED and not dataset.publication_date:
# The dataset is NOT LIVE yet and is being approved for the first time
dataset.publication_date = now
dataset.status = status
Expand Down

0 comments on commit 70d6ba9

Please sign in to comment.