diff options
-rw-r--r-- | ishtar_common/models.py | 6 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 3 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/window_nav.html | 6 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 15 |
4 files changed, 20 insertions, 10 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index c241b4fad..71868cb63 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1518,6 +1518,12 @@ class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData, self.save() return external_id + def get_last_history_date(self): + q = self.history.values("history_date").order_by('-history_date') + if not q.count(): + return + return q.all()[0]['history_date'] + def get_previous(self, step=None, date=None, strict=True): """ Get a "step" previous state of the item diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 9fb138ff2..c3fadd7bb 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -627,13 +627,14 @@ function hide_window(window_id){ update_window_menu(); } -function load_url(url){ +function load_url(url, callback){ $('.modal-progress').modal('show'); $.ajax({ url: url, cache: false, success:function(html){ close_wait(); + if (callback) callback(); }, error:function(XMLHttpRequest, textStatus, errorThrows){ close_wait(); diff --git a/ishtar_common/templates/ishtar/blocks/window_nav.html b/ishtar_common/templates/ishtar/blocks/window_nav.html index 62caff142..30e364ae5 100644 --- a/ishtar_common/templates/ishtar/blocks/window_nav.html +++ b/ishtar_common/templates/ishtar/blocks/window_nav.html @@ -6,7 +6,7 @@ {% if previous %} <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" - title="{{previous}}" + title="{{previous|date}} {{previous|time:'H:i'}}" onclick='load_window("{% url histo_url item.pk previous|date:"c"%}");$("#{{window_id}}").hide();return false;'> <i class="fa fa-step-backward"></i> </button> @@ -14,14 +14,14 @@ {% if next %} <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" - onclick='if(confirm("{%trans 'Are you sure to restore to this version? All changes made since this version will be lost.' %}")){load_url("{% url revert_url item.pk item.history_date|date:"c"%}");closeAllWindows();load_window("{% url show_url item.pk None %}");}' + onclick='if(confirm("{%trans 'Are you sure to restore to this version? All changes made since this version will be lost.' %}")){load_url("{% url revert_url item.pk item.history_date|date:"c"%}", function(){closeAllWindows();load_window("{% url show_url item.pk None %}");});}' title="{% trans 'Restore this version' %}"> <i class="fa fa-history"></i> </button> <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" onclick='load_window("{% url histo_url item.pk next|date:"c" %}");$("#{{window_id}}").hide();return false;' - title="{{next}}"> + title="{{next|date}} {{next|time:'H:i'}}"> <i class="fa fa-step-forward"></i> </button> {% endif %} diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index c2fab5bde..fbac512cd 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -203,13 +203,16 @@ def show_item(model, name, extra_dct=None, model_for_perms=None): try: date = datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%f') - item = item.get_previous(date=date) - assert item is not None + if item.get_last_history_date() != date: + item = item.get_previous(date=date) + assert item is not None + dct['previous'] = item._previous + dct['next'] = item._next + else: + date = None except (ValueError, AssertionError): - return HttpResponse(None, content_type='text/plain') - dct['previous'] = item._previous - dct['next'] = item._next - else: + return HttpResponse('', content_type='text/plain') + if not date: historized = item.history.all() if historized: item.history_date = historized[0].history_date |