From e14dfc5c46ba1466facfb7fb047874455724fa23 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 28 May 2011 16:28:39 -0400 Subject: [PATCH] Changed the way to call the history of foreign objects --- apps/documents/__init__.py | 3 ++- apps/history/urls.py | 3 ++- apps/history/views.py | 13 +++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/documents/__init__.py b/apps/documents/__init__.py index 36bea18212..13dddce7d6 100644 --- a/apps/documents/__init__.py +++ b/apps/documents/__init__.py @@ -53,6 +53,7 @@ document_find_all_duplicates = {'text': _(u'find all duplicates'), 'view': 'docu document_clear_transformations = {'text': _(u'clear all transformations'), 'view': 'document_clear_transformations', 'args': 'object.id', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]} document_multiple_clear_transformations = {'text': _(u'clear all transformations'), 'view': 'document_multiple_clear_transformations', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]} document_print = {'text': _(u'print'), 'view': 'document_print', 'args': 'object.id', 'famfam': 'printer', 'permissions': [PERMISSION_DOCUMENT_VIEW]} +document_history_view = {'text': _(u'history'), 'view': 'history_for_object', 'args': ['"documents"', '"document"', 'object.id'], 'famfam': 'book_go', 'permissions': [PERMISSION_DOCUMENT_VIEW]} document_page_transformation_list = {'text': _(u'page transformations'), 'class': 'no-parent-history', 'view': 'document_page_transformation_list', 'args': 'object.id', 'famfam': 'pencil_go', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]} document_page_transformation_create = {'text': _(u'create new transformation'), 'class': 'no-parent-history', 'view': 'document_page_transformation_create', 'args': 'object.id', 'famfam': 'pencil_add', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]} @@ -83,7 +84,7 @@ upload_document_from_user_staging = {'text': _(u'user staging'), 'view': 'upload staging_file_preview = {'text': _(u'preview'), 'class': 'fancybox-noscaling', 'view': 'staging_file_preview', 'args': ['source', 'object.id'], 'famfam': 'drive_magnify'} staging_file_delete = {'text': _(u'delete'), 'view': 'staging_file_delete', 'args': ['source', 'object.id'], 'famfam': 'drive_delete'} -register_links(Document, [document_view_simple, document_view_advanced, document_edit, document_print, document_delete, document_download, document_find_duplicates, document_clear_transformations]) +register_links(Document, [document_view_simple, document_view_advanced, document_edit, document_print, document_delete, document_download, document_find_duplicates, document_clear_transformations, document_history_view]) register_links(Document, [document_create_siblings], menu_name='sidebar') register_multi_item_links(['search', 'results', 'document_group_view', 'document_list', 'document_list_recent'], [document_multiple_clear_transformations, document_multiple_delete]) diff --git a/apps/history/urls.py b/apps/history/urls.py index e67fbcbb57..5f78c23efe 100644 --- a/apps/history/urls.py +++ b/apps/history/urls.py @@ -2,6 +2,7 @@ from django.conf.urls.defaults import patterns, url urlpatterns = patterns('history.views', url(r'^list/$', 'history_list', (), 'history_list'), - url(r'^list/for_object/(?P\d+)/(?P\d+)/$', 'history_for_object', (), 'history_for_object'), + url(r'^list/for_object/(?P[\w\-]+)/(?P[\w\-]+)/(?P\d+)/$', 'history_for_object', (), 'history_for_object'), url(r'^(?P\d+)/$', 'history_view', (), 'history_view'), ) + diff --git a/apps/history/views.py b/apps/history/views.py index f31c7b4dae..89a7e53f15 100644 --- a/apps/history/views.py +++ b/apps/history/views.py @@ -7,6 +7,7 @@ from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.utils.http import urlencode from django.contrib.contenttypes.models import ContentType +from django.db.models.loading import get_model from permissions.api import check_permissions @@ -42,15 +43,19 @@ def history_list(request): context_instance=RequestContext(request)) -def history_for_object(request, content_type_id, object_id): +def history_for_object(request, app_label, module_name, object_id): check_permissions(request.user, [PERMISSION_HISTORY_VIEW]) - content_type = get_object_or_404(ContentType, pk=content_type_id) - content_object = get_object_or_404(content_type.model_class(), pk=object_id) + model = get_model(app_label, module_name) + if not model: + raise Http404 + content_object = get_object_or_404(model, pk=object_id) + content_type = ContentType.objects.get_for_model(model) context = { - 'object_list': History.objects.filter(content_type=content_type_id, object_id=object_id), + 'object_list': History.objects.filter(content_type=content_type, object_id=object_id), 'title': _(u'history for: %s') % content_object, + 'object': content_object, 'extra_columns': [ { 'name': _(u'date and time'),