mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Handle history for non-existant objects
This commit is contained in:
parent
434ab15543
commit
4b96dc0a21
2 changed files with 9 additions and 7 deletions
|
@ -454,6 +454,7 @@ class UserHistory(History):
|
|||
Version.objects.get_for_model(Adherent)
|
||||
)
|
||||
obj = next(adherents, None)
|
||||
model = Adherent
|
||||
|
||||
# Fallback on a Club
|
||||
if obj is None:
|
||||
|
@ -462,6 +463,7 @@ class UserHistory(History):
|
|||
Version.objects.get_for_model(Club)
|
||||
)
|
||||
obj = next(clubs, None)
|
||||
model = Club
|
||||
|
||||
# If nothing was found, abort
|
||||
if obj is None:
|
||||
|
@ -492,8 +494,8 @@ class UserHistory(History):
|
|||
# Do the same thing for the Adherent of Club
|
||||
self._last_version = None
|
||||
obj_versions = filter(
|
||||
lambda x: x.field_dict["id"] == obj.id,
|
||||
Version.objects.get_for_model(type(obj)).order_by("revision__date_created")
|
||||
lambda x: x.field_dict["id"] == user_id,
|
||||
Version.objects.get_for_model(model).order_by("revision__date_created")
|
||||
)
|
||||
|
||||
for version in obj_versions:
|
||||
|
|
|
@ -526,6 +526,7 @@ def get_history_object(request, model, object_name, object_id, allow_deleted=Fal
|
|||
instance = model.get_instance(**kwargs)
|
||||
except model.DoesNotExist:
|
||||
is_deleted = True
|
||||
instance = None
|
||||
|
||||
if is_deleted and not allow_deleted:
|
||||
messages.error(request, _("Nonexistent entry."))
|
||||
|
@ -575,11 +576,7 @@ def detailed_history(request, object_name, object_id):
|
|||
|
||||
# Generate the pagination with the objects
|
||||
max_result = GeneralOption.get_cached_value("pagination_number")
|
||||
events = re2o_paginator(
|
||||
request,
|
||||
history.get(object_id),
|
||||
max_result
|
||||
)
|
||||
events = history.get(int(object_id))
|
||||
|
||||
# Events is None if object wasn't found
|
||||
if events is None:
|
||||
|
@ -588,6 +585,9 @@ def detailed_history(request, object_name, object_id):
|
|||
reverse("users:profil", kwargs={"userid": str(request.user.id)})
|
||||
)
|
||||
|
||||
# Add the paginator in case there are many results
|
||||
events = re2o_paginator(request, events, max_result)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"logs/detailed_history.html",
|
||||
|
|
Loading…
Reference in a new issue