Skip to content

Commit eb59832

Browse files
committed
polish changes page
- review changes - Inspect page: add link to history of current object
1 parent c90099a commit eb59832

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

serveradmin/serverdb/templates/serverdb/changes.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ <h3>
9494
<label for="attribute" class="col-sm-1 col-form-label">Attribute:</label>
9595
<div class="col-md-4">
9696
<input name="attribute" id="attribute" type="text" value="{% if attribute %}{{ attribute }}{% endif %}" class="form-control form-control-sm" placeholder="responsible_admin" />
97+
<small class="form-text text-muted">Requires hostname, object ID, or user/app filter</small>
9798
</div>
9899
</div>
99100
<div class="form-group row input-controls buttons">

serveradmin/serverdb/templatetags/changes.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@ def hostname(object_id: int) -> Union[str, int]:
2323
return object_id
2424

2525

26-
def _format_value(value: Any) -> str:
27-
"""Format a value for display, handling None/empty as '-'."""
28-
if value is None or value == '':
29-
return '-'
30-
if isinstance(value, list):
31-
return ', '.join(str(v) for v in value)
32-
if isinstance(value, set):
33-
return ', '.join(str(v) for v in sorted(value))
34-
return str(value)
35-
36-
3726
@register.filter
3827
def get_attribute_changes(change: Change) -> list:
3928
"""Extract attribute changes from a Change object's change_json.
@@ -46,14 +35,14 @@ def get_attribute_changes(change: Change) -> list:
4635

4736
changes_list = []
4837

49-
for attr_name, attr_change in change.change_json.items():
50-
if attr_name == 'object_id' or not isinstance(attr_change, dict):
38+
for attribute_id, attr_change in change.change_json.items():
39+
if attribute_id == 'object_id' or not isinstance(attr_change, dict):
5140
continue
5241

53-
prefix = f'<strong>{escape(attr_name)}:</strong>'
42+
prefix = f'<strong>{attribute_id}:</strong>'
5443
action = attr_change.get('action')
55-
old_val = escape(_format_value(attr_change.get('old')))
56-
new_val = escape(_format_value(attr_change.get('new')))
44+
old_val = escape(attr_change.get('old'))
45+
new_val = escape(attr_change.get('new'))
5746

5847
if action == 'update':
5948
if attr_change.get('new') in (None, ''):

serveradmin/serverdb/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ def changes(request):
6868

6969
f_attribute = request.GET.get('attribute')
7070
if f_attribute:
71-
commits = commits.filter(change__change_json__has_key=f_attribute)
71+
# Only allow attribute filter if another filter is set (no index)
72+
if f_hostname or f_object_id or f_user_or_app:
73+
commits = commits.filter(change__change_json__has_key=f_attribute)
74+
else:
75+
f_attribute = None
7276

7377
commits = commits.select_related('app', 'user')
7478

serveradmin/servershell/templates/servershell/inspect.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ <h3>
2626
<div class="col-md-8">
2727
<a class="btn btn-success" data-edit-link href="{% url 'servershell_edit' %}?object_id={{ object_id }}">Edit</a>
2828
<a href="{% url 'servershell_index' %}" class="btn btn-success">Goto Servershell</a>
29+
<a href="/serverdb/changes?object_id={{ object_id }}" class="btn btn-success">History</a>
2930
</div>
3031
</div>
3132
<div class="row mb-3">
@@ -72,6 +73,7 @@ <h3>
7273
<div class="col-md-8">
7374
<a class="btn btn-success" data-edit-link href="{% url 'servershell_edit' %}?object_id={{ object_id }}">Edit</a>
7475
<a href="{% url 'servershell_index' %}" class="btn btn-success">Goto Servershell</a>
76+
<a href="/serverdb/changes?object_id={{ object_id }}" class="btn btn-success">History</a>
7577
</div>
7678
</div>
7779
</div>

0 commit comments

Comments
 (0)