mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Make RelatedHistory cleaner
This commit is contained in:
parent
37f87d6487
commit
13cb3f7990
2 changed files with 15 additions and 17 deletions
|
@ -289,16 +289,17 @@ class MachineHistorySearch:
|
||||||
############################
|
############################
|
||||||
|
|
||||||
class RelatedHistory:
|
class RelatedHistory:
|
||||||
def __init__(self, name, app_name, model_name, object_id):
|
def __init__(self, version):
|
||||||
"""
|
"""
|
||||||
:param name: Name of this instance
|
:param name: Name of this instance
|
||||||
:param model_name: Name of the related model (e.g. "user")
|
:param model_name: Name of the related model (e.g. "user")
|
||||||
:param object_id: ID of the related object
|
:param object_id: ID of the related object
|
||||||
"""
|
"""
|
||||||
self.name = "{} (id = {})".format(name, object_id)
|
self.version = version
|
||||||
self.app_name = app_name
|
self.app_name = version.content_type.app_label
|
||||||
self.model_name = model_name
|
self.model_name = version.content_type.model
|
||||||
self.object_id = object_id
|
self.object_id = version.object_id
|
||||||
|
self.name = version._object_cache or version.object_repr
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (
|
return (
|
||||||
|
@ -646,13 +647,8 @@ class UserHistory(History):
|
||||||
self.related = (
|
self.related = (
|
||||||
Version.objects.get_for_model(Machine)
|
Version.objects.get_for_model(Machine)
|
||||||
.filter(serialized_data__contains='"user": {}'.format(user_id))
|
.filter(serialized_data__contains='"user": {}'.format(user_id))
|
||||||
.order_by("-revision__date_created")
|
|
||||||
)
|
)
|
||||||
self.related = [RelatedHistory(
|
self.related = [RelatedHistory(v) for v in self.related]
|
||||||
m.field_dict["name"] or _("None"),
|
|
||||||
"machines",
|
|
||||||
"machine",
|
|
||||||
m.field_dict["id"]) for m in self.related]
|
|
||||||
self.related = list(dict.fromkeys(self.related))
|
self.related = list(dict.fromkeys(self.related))
|
||||||
|
|
||||||
# Get all the versions for this user, with the oldest first
|
# Get all the versions for this user, with the oldest first
|
||||||
|
@ -744,11 +740,7 @@ class MachineHistory(History):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create RelatedHistory objects and remove duplicates
|
# Create RelatedHistory objects and remove duplicates
|
||||||
self.related = [RelatedHistory(
|
self.related = [RelatedHistory(v) for v in self.related]
|
||||||
i.field_dict["mac_address"] or _("None"),
|
|
||||||
"machines",
|
|
||||||
"interface",
|
|
||||||
i.field_dict["id"]) for i in self.related]
|
|
||||||
self.related = list(dict.fromkeys(self.related))
|
self.related = list(dict.fromkeys(self.related))
|
||||||
|
|
||||||
events = super(MachineHistory, self).get(machine_id, Machine)
|
events = super(MachineHistory, self).get(machine_id, Machine)
|
||||||
|
|
|
@ -78,7 +78,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<ul>
|
<ul>
|
||||||
{% for related in related_history %}
|
{% for related in related_history %}
|
||||||
<li>
|
<li>
|
||||||
<a title="{% trans "History" %}" href="{% url 'logs:history' related.app_name related.model_name related.object_id %}">{{ related.model_name }} - {{ related.name }}</a>
|
{% if related.object_id %}
|
||||||
|
<a href="{% url 'logs:history' related.application related.model_name related.object_id %}" title="{% trans "History" %}">
|
||||||
|
{{ related.name }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
{{ related.name }}
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue