Initial commit for document diff support in history
This commit is contained in:
@@ -335,3 +335,18 @@ def generate_choices_w_labels(choices, display_object_type=True):
|
||||
|
||||
#Sort results by the label not the key value
|
||||
return sorted(results, key=lambda x: x[1])
|
||||
|
||||
|
||||
def return_diff(old_obj, new_obj, attrib_list=None):
|
||||
diff_dict = {}
|
||||
attrib_list = old_obj.__dict__.keys()
|
||||
for attrib in attrib_list:
|
||||
old_val = getattr(old_obj, attrib)
|
||||
new_val = getattr(new_obj, attrib)
|
||||
if old_val != new_val:
|
||||
diff_dict[attrib] = {
|
||||
'old_value': old_val,
|
||||
'new_value': new_val
|
||||
}
|
||||
|
||||
return diff_dict
|
||||
|
||||
@@ -209,7 +209,7 @@ class DocumentPropertiesForm(DetailForm):
|
||||
|
||||
class DocumentContentForm(forms.Form):
|
||||
"""
|
||||
Form that contatenates all of a document pages' text content into a
|
||||
Form that concatenates all of a document pages' text content into a
|
||||
single textarea widget
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@@ -21,15 +21,15 @@ UPLOAD_SOURCE_USER_STAGING = u'user_staging'
|
||||
HISTORY_DOCUMENT_CREATED = {
|
||||
'namespace': 'documents', 'name': 'document_created',
|
||||
'label': _(u'Document creation'),
|
||||
'summary': _(u'Document: %(content_object)s created by %(fullname)s.'),
|
||||
'details': _(u'Document: %(content_object)s created on %(datetime)s by %(fullname)s.'),
|
||||
'summary': _(u'Document "%(content_object)s" created by %(fullname)s.'),
|
||||
'details': _(u'Document "%(content_object)s" created on %(datetime)s by %(fullname)s.'),
|
||||
'expressions': [{'fullname': 'user.get_full_name() if user.get_full_name() else user.username'}]
|
||||
}
|
||||
|
||||
HISTORY_DOCUMENT_EDITED = {
|
||||
'namespace': 'documents', 'name': 'document_edited',
|
||||
'label': _(u'Document edited'),
|
||||
'summary': _(u'Document: %(content_object)s edited by %(fullname)s.'),
|
||||
'details': _(u'Document: %(content_object)s edited on %(datetime)s by %(fullname)s.'),
|
||||
'summary': _(u'Document "%(content_object)s" edited by %(fullname)s.'),
|
||||
'details': _(u'Document "%(content_object)s" edited on %(datetime)s by %(fullname)s.'),
|
||||
'expressions': [{'fullname': 'user.get_full_name() if user.get_full_name() else user.username'}]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import zipfile
|
||||
import urlparse
|
||||
import copy
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.http import HttpResponseRedirect
|
||||
@@ -16,7 +17,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.contrib.comments.models import Comment
|
||||
|
||||
import sendfile
|
||||
from common.utils import pretty_size, parse_range, urlquote
|
||||
from common.utils import pretty_size, parse_range, urlquote, return_diff
|
||||
from common.literals import PAGE_SIZE_DIMENSIONS, \
|
||||
PAGE_ORIENTATION_PORTRAIT, PAGE_ORIENTATION_LANDSCAPE
|
||||
from common.conf.settings import DEFAULT_PAPER_SIZE
|
||||
@@ -169,12 +170,13 @@ def upload_document_with_type(request, source):
|
||||
|
||||
if request.method == 'POST':
|
||||
if source == UPLOAD_SOURCE_LOCAL:
|
||||
form = DocumentForm(request.POST, request.FILES,
|
||||
initial={'document_type': document_type})
|
||||
form = DocumentForm(request.POST, request.FILES, document_type=document_type)
|
||||
if form.is_valid():
|
||||
try:
|
||||
if (not UNCOMPRESS_COMPRESSED_LOCAL_FILES) or (UNCOMPRESS_COMPRESSED_LOCAL_FILES and not _handle_zip_file(request, request.FILES['file'], document_type)):
|
||||
instance = form.save()
|
||||
if document_type:
|
||||
instance.document_type = document_type
|
||||
_handle_save_document(request, instance, form)
|
||||
messages.success(request, _(u'Document uploaded successfully.'))
|
||||
except Exception, e:
|
||||
@@ -185,7 +187,7 @@ def upload_document_with_type(request, source):
|
||||
StagingFile = create_staging_file_class(request, source)
|
||||
form = StagingDocumentForm(request.POST,
|
||||
request.FILES, cls=StagingFile,
|
||||
initial={'document_type': document_type})
|
||||
document_type=document_type)
|
||||
if form.is_valid():
|
||||
try:
|
||||
staging_file = StagingFile.get(form.cleaned_data['staging_file_id'])
|
||||
@@ -206,11 +208,11 @@ def upload_document_with_type(request, source):
|
||||
return HttpResponseRedirect(request.META['HTTP_REFERER'])
|
||||
else:
|
||||
if source == UPLOAD_SOURCE_LOCAL:
|
||||
form = DocumentForm(initial={'document_type': document_type})
|
||||
form = DocumentForm(document_type=document_type)
|
||||
elif (USE_STAGING_DIRECTORY and source == UPLOAD_SOURCE_STAGING) or (PER_USER_STAGING_DIRECTORY and source == UPLOAD_SOURCE_USER_STAGING):
|
||||
StagingFile = create_staging_file_class(request, source)
|
||||
form = StagingDocumentForm(cls=StagingFile,
|
||||
initial={'document_type': document_type})
|
||||
document_type=document_type)
|
||||
|
||||
subtemplates_list = []
|
||||
|
||||
@@ -497,7 +499,8 @@ def document_edit(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentForm_edit(request.POST, initial={'document_type': document.document_type})
|
||||
old_document = copy.copy(document)
|
||||
form = DocumentForm_edit(request.POST, instance=document)
|
||||
if form.is_valid():
|
||||
warnings = delete_indexes(document)
|
||||
if request.user.is_staff or request.user.is_superuser:
|
||||
@@ -513,10 +516,12 @@ def document_edit(request, document_id):
|
||||
|
||||
document.save()
|
||||
|
||||
#print 'diff', return_diff(old_document, document)
|
||||
|
||||
create_history(HISTORY_DOCUMENT_EDITED, document, {'user': request.user})
|
||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||
|
||||
messages.success(request, _(u'Document %s edited successfully.') % document)
|
||||
messages.success(request, _(u'Document "%s" edited successfully.') % document)
|
||||
|
||||
warnings = update_indexes(document)
|
||||
if request.user.is_staff or request.user.is_superuser:
|
||||
@@ -525,12 +530,8 @@ def document_edit(request, document_id):
|
||||
|
||||
return HttpResponseRedirect(document.get_absolute_url())
|
||||
else:
|
||||
if hasattr(document, 'document_type'):
|
||||
document_type = document.document_type
|
||||
else:
|
||||
document_type = None
|
||||
form = DocumentForm_edit(instance=document, initial={
|
||||
'new_filename': document.file_filename, 'document_type': document_type})
|
||||
'new_filename': document.file_filename})
|
||||
|
||||
return render_to_response('generic_form.html', {
|
||||
'form': form,
|
||||
|
||||
@@ -54,7 +54,7 @@ def history_for_object(request, app_label, module_name, object_id):
|
||||
|
||||
context = {
|
||||
'object_list': History.objects.filter(content_type=content_type, object_id=object_id),
|
||||
'title': _(u'history for: %s') % content_object,
|
||||
'title': _(u'history events for: %s') % content_object,
|
||||
'object': content_object,
|
||||
'extra_columns': [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user