mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 15:33:45 +00:00
Handle history for non-existant objects
This commit is contained in:
parent
e8a3134492
commit
bd06ee3327
2 changed files with 9 additions and 7 deletions
|
@ -454,6 +454,7 @@ class UserHistory(History):
|
||||||
Version.objects.get_for_model(Adherent)
|
Version.objects.get_for_model(Adherent)
|
||||||
)
|
)
|
||||||
obj = next(adherents, None)
|
obj = next(adherents, None)
|
||||||
|
model = Adherent
|
||||||
|
|
||||||
# Fallback on a Club
|
# Fallback on a Club
|
||||||
if obj is None:
|
if obj is None:
|
||||||
|
@ -462,6 +463,7 @@ class UserHistory(History):
|
||||||
Version.objects.get_for_model(Club)
|
Version.objects.get_for_model(Club)
|
||||||
)
|
)
|
||||||
obj = next(clubs, None)
|
obj = next(clubs, None)
|
||||||
|
model = Club
|
||||||
|
|
||||||
# If nothing was found, abort
|
# If nothing was found, abort
|
||||||
if obj is None:
|
if obj is None:
|
||||||
|
@ -492,8 +494,8 @@ class UserHistory(History):
|
||||||
# Do the same thing for the Adherent of Club
|
# Do the same thing for the Adherent of Club
|
||||||
self._last_version = None
|
self._last_version = None
|
||||||
obj_versions = filter(
|
obj_versions = filter(
|
||||||
lambda x: x.field_dict["id"] == obj.id,
|
lambda x: x.field_dict["id"] == user_id,
|
||||||
Version.objects.get_for_model(type(obj)).order_by("revision__date_created")
|
Version.objects.get_for_model(model).order_by("revision__date_created")
|
||||||
)
|
)
|
||||||
|
|
||||||
for version in obj_versions:
|
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)
|
instance = model.get_instance(**kwargs)
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
is_deleted = True
|
is_deleted = True
|
||||||
|
instance = None
|
||||||
|
|
||||||
if is_deleted and not allow_deleted:
|
if is_deleted and not allow_deleted:
|
||||||
messages.error(request, _("Nonexistent entry."))
|
messages.error(request, _("Nonexistent entry."))
|
||||||
|
@ -575,11 +576,7 @@ def detailed_history(request, object_name, object_id):
|
||||||
|
|
||||||
# Generate the pagination with the objects
|
# Generate the pagination with the objects
|
||||||
max_result = GeneralOption.get_cached_value("pagination_number")
|
max_result = GeneralOption.get_cached_value("pagination_number")
|
||||||
events = re2o_paginator(
|
events = history.get(int(object_id))
|
||||||
request,
|
|
||||||
history.get(object_id),
|
|
||||||
max_result
|
|
||||||
)
|
|
||||||
|
|
||||||
# Events is None if object wasn't found
|
# Events is None if object wasn't found
|
||||||
if events is None:
|
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)})
|
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(
|
return render(
|
||||||
request,
|
request,
|
||||||
"logs/detailed_history.html",
|
"logs/detailed_history.html",
|
||||||
|
|
Loading…
Reference in a new issue