summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar/furnitures/models.py25
-rw-r--r--ishtar/furnitures/urls.py2
-rw-r--r--ishtar/furnitures/views.py16
-rw-r--r--ishtar/templates/sheet_file.html10
4 files changed, 47 insertions, 6 deletions
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py
index 2fe65b598..de519076f 100644
--- a/ishtar/furnitures/models.py
+++ b/ishtar/furnitures/models.py
@@ -174,15 +174,32 @@ class BaseHistorizedItem(models.Model):
super(BaseHistorizedItem, self).save(*args, **kwargs)
return True
- def get_previous(self, step, strict=True):
+ def get_previous(self, step=None, date=None, strict=True):
"""
Get a "step" previous state of the item
"""
+ assert step or date
historized = self.history.all()
- assert len(historized) > step
- assert not hasattr(historized, '_step')
- item = historized[step]
+ item = None
+ if step:
+ assert len(historized) > step
+ item = historized[step]
+ else:
+ for step, item in enumerate(historized):
+ if item.history_date == date:
+ break
+ # ended with no match
+ if item.history_date != date:
+ return
item._step = step
+ if len(historized) != (step + 1):
+ item._previous = historized[step + 1].history_date
+ else:
+ item._previous = None
+ if step > 0:
+ item._next = historized[step - 1].history_date
+ else:
+ item._next = None
model = self.__class__
for k in model._meta.get_all_field_names():
field = model._meta.get_field_by_name(k)[0]
diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py
index 2342d4027..5a155b5b5 100644
--- a/ishtar/furnitures/urls.py
+++ b/ishtar/furnitures/urls.py
@@ -111,6 +111,8 @@ urlpatterns += patterns('ishtar.furnitures.views',
name='get-file'),
url(BASE_URL + r'show-file/(?P<pk>.+)?/(?P<type>.+)?$', 'show_file',
name='show-file'),
+ url(BASE_URL + r'show-historized-file/(?P<pk>.+)?/(?P<date>.+)?$',
+ 'show_file', name='show-historized-file'),
url(BASE_URL + r'autocomplete-operation/$', 'autocomplete_operation',
name='autocomplete-operation'),
url(BASE_URL + r'get-operation/(?P<type>.+)?$', 'get_operation',
diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py
index 0320ce5c9..43e663267 100644
--- a/ishtar/furnitures/views.py
+++ b/ishtar/furnitures/views.py
@@ -212,9 +212,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
items = items.order_by(sign + k)
datas = []
if old:
- print [item.pk for item in items]
items = [item.get_previous(old) for item in items]
- print [item.pk for item in items]
for item in items:
data = [item.pk]
for k in model.TABLE_COLS:
@@ -286,9 +284,23 @@ def show_item(model, name):
except ObjectDoesNotExist:
return HttpResponse(None)
doc_type = 'type' in dct and dct.pop('type')
+ date = 'date' in dct and dct.pop('date')
dct['item'], dct['item_name'] = item, name
dct['window_id'] = "%s-%d-%s" % (name, item.pk,
datetime.datetime.now().strftime('%M%s'))
+ if date:
+ try:
+ date = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f')
+ item = item.get_previous(date=date)
+ assert item != None
+ except (ValueError, AssertionError):
+ return HttpResponse(None, mimetype='text/plain')
+ dct['previous'] = item._previous
+ dct['next'] = item._next
+ else:
+ historized = item.history.all()
+ if len(historized) > 1:
+ dct['previous'] = historized[1].history_date
context_instance = RequestContext(request)
context_instance.update(dct)
n = datetime.datetime.now()
diff --git a/ishtar/templates/sheet_file.html b/ishtar/templates/sheet_file.html
index 8a004b0a5..b161a8e22 100644
--- a/ishtar/templates/sheet_file.html
+++ b/ishtar/templates/sheet_file.html
@@ -1,6 +1,16 @@
{% extends "sheet.html" %}
{% load i18n %}
{% block content %}
+{% if previous or next %}
+<div class='tool'>
+{%if previous%}
+<a href="#" onclick='load_window("{% url show-historized-file item.pk previous %}");$("#{{window_id}}").hide();return false;'>{%trans "Previous version"%} ({{previous}})</a>
+{% endif %}
+{%if next%}
+ - <a href="#" onclick='load_window("{% url show-historized-file item.pk next %}");$("#{{window_id}}").hide();return false;'>{%trans "Next version"%} ({{next}})</a>
+{% endif %}
+</div>
+{% endif %}
<div class='tool'>{%trans "Export as:"%} <a href='{% url show-file item.pk "odt" %}'>{%trans "OpenOffice.org file"%}</a>, <a href='{% url show-file item.pk "pdf" %}'>{%trans "PDF file"%}</a></div>
<h3>{% trans "General"%}</h3>
<p><label>{%trans "Year:"%}</label> <span class='value'>{{ item.year }}</span></p>