mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Initial work on new checklist handling. No more JSON!
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
{% if version.changes.old == None %}
|
||||
Created
|
||||
{% else %}
|
||||
Changed {% include 'version_changes.html' %} in
|
||||
Changed {% include 'partials/version_changes.html' %} in
|
||||
{% endif %}
|
||||
|
||||
{% include 'partials/object_button.html' with object=version.changes.new %}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% if version.changes.item_changes or version.changes.field_changes or version.changes.old == None %}
|
||||
{% if version.changes.anything_changed or version.changes.old == None %}
|
||||
{% for change in version.changes.field_changes %}
|
||||
<span title="Changes to {{ change.field.verbose_name }}" class="badge badge-info p-2" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='{% spaceless %}{% include "version_changes_change.html" %}{% endspaceless %}'>{{ change.field.verbose_name }}</span>
|
||||
{% endfor %}
|
||||
@@ -19,7 +19,7 @@
|
||||
{% if version.changes.old is None %}
|
||||
{{object|to_class_name}} Created
|
||||
{% else %}
|
||||
{% include 'version_changes.html' %}
|
||||
{% include 'partials/version_changes.html' %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -67,7 +67,6 @@ class FieldComparison(object):
|
||||
|
||||
|
||||
class ModelComparison(object):
|
||||
|
||||
def __init__(self, old=None, new=None, version=None, excluded_keys=[]):
|
||||
# recieves two objects of the same model, and compares them. Returns an array of FieldCompare objects
|
||||
try:
|
||||
@@ -117,29 +116,30 @@ class ModelComparison(object):
|
||||
@cached_property
|
||||
def item_changes(self):
|
||||
# Recieves two event version objects and compares their items, returns an array of ItemCompare objects
|
||||
|
||||
item_type = ContentType.objects.get_for_model(models.EventItem)
|
||||
old_item_versions = self.version.parent.revision.version_set.filter(content_type=item_type)
|
||||
new_item_versions = self.version.revision.version_set.filter(content_type=item_type)
|
||||
item_dict = {}
|
||||
if hasattr(self.version, 'parent'):
|
||||
old_item_versions = self.version.parent.revision.version_set.filter(content_type=item_type)
|
||||
new_item_versions = self.version.revision.version_set.filter(content_type=item_type)
|
||||
|
||||
comparisonParams = {'excluded_keys': ['id', 'event', 'order']}
|
||||
comparisonParams = {'excluded_keys': ['id', 'event', 'order']}
|
||||
|
||||
# Build some dicts of what we have
|
||||
item_dict = {} # build a list of items, key is the item_pk
|
||||
for version in old_item_versions: # put all the old versions in a list
|
||||
if version.field_dict["event_id"] == int(self.new.pk):
|
||||
compare = ModelComparison(old=version._object_version.object, **comparisonParams)
|
||||
item_dict[version.object_id] = compare
|
||||
# Build some dicts of what we have
|
||||
# build a list of items, key is the item_pk
|
||||
for version in old_item_versions: # put all the old versions in a list
|
||||
if version.field_dict["event_id"] == int(self.new.pk):
|
||||
compare = ModelComparison(old=version._object_version.object, **comparisonParams)
|
||||
item_dict[version.object_id] = compare
|
||||
|
||||
for version in new_item_versions: # go through the new versions
|
||||
if version.field_dict["event_id"] == int(self.new.pk):
|
||||
try:
|
||||
compare = item_dict[version.object_id] # see if there's a matching old version
|
||||
compare.new = version._object_version.object # then add the new version to the dictionary
|
||||
except KeyError: # there's no matching old version, so add this item to the dictionary by itself
|
||||
compare = ModelComparison(new=version._object_version.object, **comparisonParams)
|
||||
for version in new_item_versions: # go through the new versions
|
||||
if version.field_dict["event_id"] == int(self.new.pk):
|
||||
try:
|
||||
compare = item_dict[version.object_id] # see if there's a matching old version
|
||||
compare.new = version._object_version.object # then add the new version to the dictionary
|
||||
except KeyError: # there's no matching old version, so add this item to the dictionary by itself
|
||||
compare = ModelComparison(new=version._object_version.object, **comparisonParams)
|
||||
|
||||
item_dict[version.object_id] = compare # update the dictionary with the changes
|
||||
item_dict[version.object_id] = compare # update the dictionary with the changes
|
||||
|
||||
changes = []
|
||||
for (_, compare) in list(item_dict.items()):
|
||||
|
||||
Reference in New Issue
Block a user