mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
More
This commit is contained in:
parent
6098977ee3
commit
292bebdc0e
@ -111,12 +111,8 @@
|
||||
<h5 class="card-header">{% trans "Pre-Change Data" %}</h5>
|
||||
<div class="card-body">
|
||||
{% if object.prechange_data %}
|
||||
{% spaceless %}
|
||||
<pre class="change-data">{% for text, changed in text_before %}{% spaceless %}
|
||||
<span{% if changed %} class="removed"{% endif %}>{{ text }}</span>
|
||||
{% endspaceless %}{% endfor %}
|
||||
<pre class="change-data">{% for text, changed in text_before %}<span{% if changed %} class="removed"{% endif %}>{{ text }}<br></span>{% endfor %}
|
||||
</pre>
|
||||
{% endspaceless %}
|
||||
{% elif non_atomic_change %}
|
||||
{% trans "Warning: Comparing non-atomic change to previous change record" %} (<a href="{% url 'extras:objectchange' pk=prev_change.pk %}">{{ prev_change.pk }}</a>)
|
||||
{% else %}
|
||||
@ -130,12 +126,8 @@
|
||||
<h5 class="card-header">{% trans "Post-Change Data" %}</h5>
|
||||
<div class="card-body">
|
||||
{% if object.postchange_data %}
|
||||
{% spaceless %}
|
||||
<pre class="change-data">{% for text,changed in text_after %}{% spaceless %}
|
||||
<span{% if changed %} class="added"{% endif %}>{{ text }}</span>
|
||||
{% endspaceless %}{% endfor %}
|
||||
<pre class="change-data">{% for text,changed in text_after %}<span{% if changed %} class="added"{% endif %}>{{ text }}<br></span>{% endfor %}
|
||||
</pre>
|
||||
{% endspaceless %}
|
||||
{% else %}
|
||||
<span class="text-muted">{% trans "None" %}</span>
|
||||
{% endif %}
|
||||
|
@ -132,18 +132,20 @@ def drange(start, end, step=decimal.Decimal(1)):
|
||||
#
|
||||
# String utilities
|
||||
#
|
||||
|
||||
|
||||
def regular_line_ending(s: str):
|
||||
if s.endswith(","):
|
||||
if s.endswith(','):
|
||||
return True
|
||||
return not (s.endswith("{") or s.endswith("["))
|
||||
return not (s.endswith('{') or s.endswith('['))
|
||||
|
||||
|
||||
def begin_of_complex(s: str):
|
||||
return s.endswith("[") or s.endswith("{")
|
||||
return s.endswith('[') or s.endswith('{')
|
||||
|
||||
|
||||
def has_indent(s: str, indent: str):
|
||||
return not s.removeprefix(indent).startswith(" ")
|
||||
return not s.removeprefix(indent).startswith(' ')
|
||||
|
||||
|
||||
def extract_key(s: str):
|
||||
@ -153,6 +155,7 @@ def extract_key(s: str):
|
||||
substr = s[:idx].replace('"', '').strip()
|
||||
return substr
|
||||
|
||||
|
||||
def make_diff(old: str, new: str):
|
||||
old_lines = old.splitlines(False)
|
||||
new_lines = new.splitlines(False)
|
||||
@ -166,13 +169,13 @@ def make_diff(old: str, new: str):
|
||||
if old_idx == len(old_lines):
|
||||
while new_idx != len(new_lines):
|
||||
new_list.append((new_lines[new_idx], True))
|
||||
old_list.append(("", False))
|
||||
old_list.append(('', False))
|
||||
new_idx += 1
|
||||
break
|
||||
if new_idx == len(new_lines):
|
||||
while old_idx != len(old_lines):
|
||||
old_list.append((old_lines[old_idx], True))
|
||||
new_list.append(("", False))
|
||||
new_list.append(('', False))
|
||||
old_idx += 1
|
||||
break
|
||||
old_s = old_lines[old_idx]
|
||||
@ -183,20 +186,17 @@ def make_diff(old: str, new: str):
|
||||
new_idx += 1
|
||||
# Handle additions of keys
|
||||
if old_k is not None and new_k is not None and old_k != new_k:
|
||||
print("Found mismatch:", old_k, new_k)
|
||||
found_it = False
|
||||
for old_idx2 in range(old_idx, len(old_lines)):
|
||||
old_s2 = old_lines[old_idx2]
|
||||
old_k2 = extract_key(old_s2)
|
||||
print(">>", old_k2, new_k)
|
||||
if old_k2 == new_k:
|
||||
print("Found it", old_k2, old_idx2, new_k)
|
||||
old_list.append((old_s, False))
|
||||
new_list.append((" <O>", False))
|
||||
old_s = "" if old_idx >= len(old_lines) else old_lines[old_idx]
|
||||
new_list.append(('', False))
|
||||
old_s = '' if old_idx >= len(old_lines) else old_lines[old_idx]
|
||||
for _ in range(old_idx + 1, old_idx2 + 1):
|
||||
old_s = "" if old_idx >= len(old_lines) else old_lines[old_idx]
|
||||
new_list.append((" <<OLDFILLER>", False))
|
||||
old_s = '' if old_idx >= len(old_lines) else old_lines[old_idx]
|
||||
new_list.append(('', False))
|
||||
old_list.append((old_s, True))
|
||||
old_idx += 1
|
||||
old_list.append((old_s, False))
|
||||
@ -209,15 +209,13 @@ def make_diff(old: str, new: str):
|
||||
for new_idx2 in range(new_idx, len(new_lines)):
|
||||
new_s2 = new_lines[new_idx2]
|
||||
new_k2 = extract_key(new_s2)
|
||||
print(">>22", old_k, new_k2)
|
||||
if new_k2 == old_k:
|
||||
print("NEW Found it", new_k2, new_idx2, old_k)
|
||||
old_list.append((" <N>", False))
|
||||
old_list.append(('', False))
|
||||
new_list.append((new_s, False))
|
||||
new_s = "" if new_idx >= len(new_lines) else new_lines[new_idx]
|
||||
new_s = '' if new_idx >= len(new_lines) else new_lines[new_idx]
|
||||
for _ in range(new_idx + 1, new_idx2 + 1):
|
||||
new_s = "" if new_idx >= len(new_lines) else new_lines[new_idx]
|
||||
old_list.append((" <<NEWFILLER>", False))
|
||||
new_s = '' if new_idx >= len(new_lines) else new_lines[new_idx]
|
||||
old_list.append(('', False))
|
||||
new_idx += 1
|
||||
new_list.append((new_s, True))
|
||||
old_list.append((old_s, False))
|
||||
@ -226,13 +224,13 @@ def make_diff(old: str, new: str):
|
||||
found_it = True
|
||||
break
|
||||
continue
|
||||
if "{" == old_s.strip() and "{" == new_s.strip():
|
||||
old_list.append(("{", False))
|
||||
new_list.append(("{", False))
|
||||
if '{' == old_s.strip() and '{' == new_s.strip():
|
||||
old_list.append(('{', False))
|
||||
new_list.append(('{', False))
|
||||
continue
|
||||
if "}" == old_s.strip() and "}" == new_s.strip():
|
||||
old_list.append(("}", False))
|
||||
new_list.append(("}", False))
|
||||
if '}' == old_s.strip() and '}' == new_s.strip():
|
||||
old_list.append(('}', False))
|
||||
new_list.append(('}', False))
|
||||
continue
|
||||
# Handle:
|
||||
# "foo": null "foo": [
|
||||
@ -240,14 +238,14 @@ def make_diff(old: str, new: str):
|
||||
# "baz",
|
||||
# "]"
|
||||
if regular_line_ending(old_s) and begin_of_complex(new_s):
|
||||
indent_of_new = new_s.replace(new_s.strip(), "")
|
||||
indent_of_new = new_s.replace(new_s.strip(), '')
|
||||
new_list.append((new_s, True))
|
||||
old_list.append((old_s, True))
|
||||
while not has_indent(new_lines[new_idx], indent_of_new):
|
||||
old_list.append(("", True))
|
||||
old_list.append(('', True))
|
||||
new_list.append((new_lines[new_idx], True))
|
||||
new_idx += 1
|
||||
old_list.append(("", True))
|
||||
old_list.append(('', True))
|
||||
new_list.append((new_lines[new_idx], True))
|
||||
new_idx += 1
|
||||
continue
|
||||
@ -256,20 +254,20 @@ def make_diff(old: str, new: str):
|
||||
# "foo": "bar"
|
||||
# }
|
||||
if begin_of_complex(old_s) and regular_line_ending(new_s):
|
||||
indent_of_old = old_s.replace(old_s.strip(), "")
|
||||
indent_of_old = old_s.replace(old_s.strip(), '')
|
||||
old_list.append((old_s, True))
|
||||
new_list.append((new_s, True))
|
||||
while not has_indent(old_lines[old_idx], indent_of_old):
|
||||
new_list.append(("", True))
|
||||
new_list.append(('', True))
|
||||
old_list.append((old_lines[old_idx], True))
|
||||
old_idx += 1
|
||||
new_list.append(("", True))
|
||||
new_list.append(('', True))
|
||||
old_list.append((old_lines[old_idx], True))
|
||||
old_idx += 1
|
||||
continue
|
||||
if begin_of_complex(old_s) and begin_of_complex(new_s):
|
||||
indent_of_old = old_s.replace(old_s.strip(), "")
|
||||
indent_of_new = new_s.replace(new_s.strip(), "")
|
||||
indent_of_old = old_s.replace(old_s.strip(), '')
|
||||
indent_of_new = new_s.replace(new_s.strip(), '')
|
||||
old_list.append((old_s, False))
|
||||
new_list.append((new_s, False))
|
||||
old_tmp = []
|
||||
@ -280,7 +278,7 @@ def make_diff(old: str, new: str):
|
||||
while not has_indent(new_lines[new_idx], indent_of_new):
|
||||
new_tmp.append(new_lines[new_idx])
|
||||
new_idx += 1
|
||||
a, b = make_diff("\n".join(old_tmp), "\n".join(new_tmp))
|
||||
a, b = make_diff('\n'.join(old_tmp), '\n'.join(new_tmp))
|
||||
assert len(a) == len(b)
|
||||
old_list += a
|
||||
new_list += b
|
||||
@ -299,6 +297,5 @@ def make_diff(old: str, new: str):
|
||||
old_list.append((old_s, True))
|
||||
new_list.append((new_s, True))
|
||||
continue
|
||||
print(len(old_list), len(new_list))
|
||||
assert len(old_list) == len(new_list)
|
||||
return old_list, new_list
|
Loading…
Reference in New Issue
Block a user