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
|
#Sort results by the label not the key value
|
||||||
return sorted(results, key=lambda x: x[1])
|
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):
|
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
|
single textarea widget
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -21,15 +21,15 @@ UPLOAD_SOURCE_USER_STAGING = u'user_staging'
|
|||||||
HISTORY_DOCUMENT_CREATED = {
|
HISTORY_DOCUMENT_CREATED = {
|
||||||
'namespace': 'documents', 'name': 'document_created',
|
'namespace': 'documents', 'name': 'document_created',
|
||||||
'label': _(u'Document creation'),
|
'label': _(u'Document creation'),
|
||||||
'summary': _(u'Document: %(content_object)s created 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.'),
|
'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'}]
|
'expressions': [{'fullname': 'user.get_full_name() if user.get_full_name() else user.username'}]
|
||||||
}
|
}
|
||||||
|
|
||||||
HISTORY_DOCUMENT_EDITED = {
|
HISTORY_DOCUMENT_EDITED = {
|
||||||
'namespace': 'documents', 'name': 'document_edited',
|
'namespace': 'documents', 'name': 'document_edited',
|
||||||
'label': _(u'Document edited'),
|
'label': _(u'Document edited'),
|
||||||
'summary': _(u'Document: %(content_object)s edited 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.'),
|
'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'}]
|
'expressions': [{'fullname': 'user.get_full_name() if user.get_full_name() else user.username'}]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
import urlparse
|
import urlparse
|
||||||
|
import copy
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
@@ -16,7 +17,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
|
|||||||
from django.contrib.comments.models import Comment
|
from django.contrib.comments.models import Comment
|
||||||
|
|
||||||
import sendfile
|
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, \
|
from common.literals import PAGE_SIZE_DIMENSIONS, \
|
||||||
PAGE_ORIENTATION_PORTRAIT, PAGE_ORIENTATION_LANDSCAPE
|
PAGE_ORIENTATION_PORTRAIT, PAGE_ORIENTATION_LANDSCAPE
|
||||||
from common.conf.settings import DEFAULT_PAPER_SIZE
|
from common.conf.settings import DEFAULT_PAPER_SIZE
|
||||||
@@ -166,15 +167,16 @@ def upload_document_with_type(request, source):
|
|||||||
document_type = get_object_or_404(DocumentType, pk=document_type_id[0])
|
document_type = get_object_or_404(DocumentType, pk=document_type_id[0])
|
||||||
else:
|
else:
|
||||||
document_type = None
|
document_type = None
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if source == UPLOAD_SOURCE_LOCAL:
|
if source == UPLOAD_SOURCE_LOCAL:
|
||||||
form = DocumentForm(request.POST, request.FILES,
|
form = DocumentForm(request.POST, request.FILES, document_type=document_type)
|
||||||
initial={'document_type': document_type})
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
try:
|
try:
|
||||||
if (not UNCOMPRESS_COMPRESSED_LOCAL_FILES) or (UNCOMPRESS_COMPRESSED_LOCAL_FILES and not _handle_zip_file(request, request.FILES['file'], document_type)):
|
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()
|
instance = form.save()
|
||||||
|
if document_type:
|
||||||
|
instance.document_type = document_type
|
||||||
_handle_save_document(request, instance, form)
|
_handle_save_document(request, instance, form)
|
||||||
messages.success(request, _(u'Document uploaded successfully.'))
|
messages.success(request, _(u'Document uploaded successfully.'))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@@ -185,7 +187,7 @@ def upload_document_with_type(request, source):
|
|||||||
StagingFile = create_staging_file_class(request, source)
|
StagingFile = create_staging_file_class(request, source)
|
||||||
form = StagingDocumentForm(request.POST,
|
form = StagingDocumentForm(request.POST,
|
||||||
request.FILES, cls=StagingFile,
|
request.FILES, cls=StagingFile,
|
||||||
initial={'document_type': document_type})
|
document_type=document_type)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
try:
|
try:
|
||||||
staging_file = StagingFile.get(form.cleaned_data['staging_file_id'])
|
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'])
|
return HttpResponseRedirect(request.META['HTTP_REFERER'])
|
||||||
else:
|
else:
|
||||||
if source == UPLOAD_SOURCE_LOCAL:
|
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):
|
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)
|
StagingFile = create_staging_file_class(request, source)
|
||||||
form = StagingDocumentForm(cls=StagingFile,
|
form = StagingDocumentForm(cls=StagingFile,
|
||||||
initial={'document_type': document_type})
|
document_type=document_type)
|
||||||
|
|
||||||
subtemplates_list = []
|
subtemplates_list = []
|
||||||
|
|
||||||
@@ -497,7 +499,8 @@ def document_edit(request, document_id):
|
|||||||
document = get_object_or_404(Document, pk=document_id)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
|
|
||||||
if request.method == 'POST':
|
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():
|
if form.is_valid():
|
||||||
warnings = delete_indexes(document)
|
warnings = delete_indexes(document)
|
||||||
if request.user.is_staff or request.user.is_superuser:
|
if request.user.is_staff or request.user.is_superuser:
|
||||||
@@ -510,13 +513,15 @@ def document_edit(request, document_id):
|
|||||||
if 'document_type_available_filenames' in form.cleaned_data:
|
if 'document_type_available_filenames' in form.cleaned_data:
|
||||||
if form.cleaned_data['document_type_available_filenames']:
|
if form.cleaned_data['document_type_available_filenames']:
|
||||||
document.file_filename = form.cleaned_data['document_type_available_filenames'].filename
|
document.file_filename = form.cleaned_data['document_type_available_filenames'].filename
|
||||||
|
|
||||||
document.save()
|
document.save()
|
||||||
|
|
||||||
|
#print 'diff', return_diff(old_document, document)
|
||||||
|
|
||||||
create_history(HISTORY_DOCUMENT_EDITED, document, {'user': request.user})
|
create_history(HISTORY_DOCUMENT_EDITED, document, {'user': request.user})
|
||||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
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)
|
warnings = update_indexes(document)
|
||||||
if request.user.is_staff or request.user.is_superuser:
|
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())
|
return HttpResponseRedirect(document.get_absolute_url())
|
||||||
else:
|
else:
|
||||||
if hasattr(document, 'document_type'):
|
|
||||||
document_type = document.document_type
|
|
||||||
else:
|
|
||||||
document_type = None
|
|
||||||
form = DocumentForm_edit(instance=document, initial={
|
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', {
|
return render_to_response('generic_form.html', {
|
||||||
'form': form,
|
'form': form,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ def history_for_object(request, app_label, module_name, object_id):
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
'object_list': History.objects.filter(content_type=content_type, object_id=object_id),
|
'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,
|
'object': content_object,
|
||||||
'extra_columns': [
|
'extra_columns': [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user