Update document page and document edit views to CBV.
This commit is contained in:
@@ -79,6 +79,15 @@ class DocumentForm(forms.ModelForm):
|
||||
label=_('Quick document rename')
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
if 'document_type_available_filenames' in self.cleaned_data:
|
||||
if self.cleaned_data['document_type_available_filenames']:
|
||||
self.cleaned_data['label'] = self.cleaned_data[
|
||||
'document_type_available_filenames'
|
||||
]
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
class DocumentPropertiesForm(DetailForm):
|
||||
"""
|
||||
|
||||
@@ -29,7 +29,7 @@ from mimetype.api import get_mimetype
|
||||
|
||||
from .events import (
|
||||
event_document_create, event_document_new_version,
|
||||
event_document_version_revert
|
||||
event_document_properties_edit, event_document_version_revert
|
||||
)
|
||||
from .literals import DEFAULT_DELETE_PERIOD, DEFAULT_DELETE_TIME_UNIT
|
||||
from .managers import (
|
||||
@@ -195,6 +195,7 @@ class Document(models.Model):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
user = kwargs.pop('_user', None)
|
||||
print '!!!!!!!!!!', user
|
||||
new_document = not self.pk
|
||||
super(Document, self).save(*args, **kwargs)
|
||||
|
||||
@@ -204,6 +205,8 @@ class Document(models.Model):
|
||||
event_document_create.commit(actor=user, target=self)
|
||||
else:
|
||||
event_document_create.commit(target=self)
|
||||
else:
|
||||
event_document_properties_edit.commit(actor=user, target=self)
|
||||
|
||||
def add_as_recent_document_for_user(self, user):
|
||||
RecentDocument.objects.add_document_for_user(user, self)
|
||||
|
||||
@@ -13,13 +13,14 @@ from .api_views import (
|
||||
)
|
||||
from .settings import setting_print_size, setting_display_size
|
||||
from .views import (
|
||||
DeletedDocumentDeleteView, DeletedDocumentListView, DocumentListView,
|
||||
DocumentManyDeleteView, DocumentManyRestoreView, DocumentPageListView,
|
||||
DocumentPreviewView, DocumentRestoreView, DocumentTypeCreateView,
|
||||
DocumentTypeDeleteView, DocumentTypeDocumentListView,
|
||||
DocumentTypeFilenameDeleteView, DocumentTypeFilenameEditView,
|
||||
DocumentTypeFilenameListView, DocumentTypeListView, DocumentTypeEditView,
|
||||
DocumentVersionListView, EmptyTrashCanView, RecentDocumentListView
|
||||
DeletedDocumentDeleteView, DeletedDocumentListView, DocumentEditView,
|
||||
DocumentListView, DocumentManyDeleteView, DocumentManyRestoreView,
|
||||
DocumentPageView, DocumentPageListView, DocumentPreviewView,
|
||||
DocumentRestoreView, DocumentTypeCreateView, DocumentTypeDeleteView,
|
||||
DocumentTypeDocumentListView, DocumentTypeFilenameDeleteView,
|
||||
DocumentTypeFilenameEditView, DocumentTypeFilenameListView,
|
||||
DocumentTypeListView, DocumentTypeEditView, DocumentVersionListView,
|
||||
EmptyTrashCanView, RecentDocumentListView
|
||||
)
|
||||
|
||||
urlpatterns = patterns(
|
||||
@@ -75,7 +76,7 @@ urlpatterns = patterns(
|
||||
name='document_multiple_trash'
|
||||
),
|
||||
url(
|
||||
r'^(?P<document_id>\d+)/edit/$', 'document_edit',
|
||||
r'^(?P<pk>\d+)/edit/$', DocumentEditView.as_view(),
|
||||
name='document_edit'
|
||||
),
|
||||
url(
|
||||
@@ -150,7 +151,7 @@ urlpatterns = patterns(
|
||||
),
|
||||
|
||||
url(
|
||||
r'^page/(?P<document_page_id>\d+)/$', 'document_page_view',
|
||||
r'^page/(?P<pk>\d+)/$', DocumentPageView.as_view(),
|
||||
name='document_page_view'
|
||||
),
|
||||
url(
|
||||
|
||||
@@ -18,7 +18,7 @@ from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
from acls.models import AccessControlList
|
||||
from common.compressed_files import CompressedFile
|
||||
from common.generics import (
|
||||
ConfirmView, SingleObjectCreateView, SingleObjectDeleteView,
|
||||
ConfirmView, SimpleView, SingleObjectCreateView, SingleObjectDeleteView,
|
||||
SingleObjectDetailView, SingleObjectEditView, SingleObjectListView
|
||||
)
|
||||
from common.mixins import MultipleInstanceActionMixin
|
||||
@@ -390,43 +390,28 @@ def document_multiple_trash(request):
|
||||
)
|
||||
|
||||
|
||||
def document_edit(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
try:
|
||||
Permission.check_permissions(
|
||||
request.user, (permission_document_properties_edit,)
|
||||
class DocumentEditView(SingleObjectEditView):
|
||||
form_class = DocumentForm
|
||||
model = Document
|
||||
object_permission = permission_document_properties_edit
|
||||
|
||||
def get_extra_context(self):
|
||||
self.get_object().add_as_recent_document_for_user(self.request.user)
|
||||
|
||||
return {
|
||||
'object': self.get_object(),
|
||||
'title': _('Edit properties of document: %s') % self.get_object(),
|
||||
}
|
||||
|
||||
def get_save_extra_data(self):
|
||||
return {
|
||||
'_user': self.request.user
|
||||
}
|
||||
|
||||
def get_post_action_redirect(self):
|
||||
return reverse(
|
||||
'documents:document_properties', args=(self.get_object().pk,)
|
||||
)
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(
|
||||
permission_document_properties_edit, request.user, document
|
||||
)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentForm(request.POST, instance=document)
|
||||
if form.is_valid():
|
||||
document.label = form.cleaned_data['label']
|
||||
document.description = form.cleaned_data['description']
|
||||
document.language = form.cleaned_data['language']
|
||||
|
||||
if 'document_type_available_filenames' in form.cleaned_data:
|
||||
if form.cleaned_data['document_type_available_filenames']:
|
||||
document.label = form.cleaned_data['document_type_available_filenames'].filename
|
||||
|
||||
document.save()
|
||||
event_document_properties_edit.commit(actor=request.user, target=document)
|
||||
document.add_as_recent_document_for_user(request.user)
|
||||
|
||||
messages.success(request, _('Document "%s" edited successfully.') % document)
|
||||
|
||||
return HttpResponseRedirect(document.get_absolute_url())
|
||||
else:
|
||||
form = DocumentForm(instance=document)
|
||||
|
||||
return render_to_response('appearance/generic_form.html', {
|
||||
'form': form,
|
||||
'object': document,
|
||||
'title': _('Edit properties of document: %s') % document,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def document_document_type_edit(request, document_id=None, document_id_list=None):
|
||||
@@ -738,35 +723,50 @@ def document_multiple_clear_transformations(request):
|
||||
return document_clear_transformations(request, document_id_list=request.GET.get('id_list', []))
|
||||
|
||||
|
||||
def document_page_view(request, document_page_id):
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
class DocumentPageView(SimpleView):
|
||||
template_name = 'appearance/generic_form.html'
|
||||
|
||||
try:
|
||||
Permission.check_permissions(request.user, (permission_document_view,))
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(permission_document_view, request.user, document_page.document)
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
try:
|
||||
Permission.check_permissions(
|
||||
request.user, (permission_document_view,)
|
||||
)
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(
|
||||
permission_document_view, request.user,
|
||||
self.get_object().document
|
||||
)
|
||||
return super(
|
||||
DocumentPageView, self
|
||||
).dispatch(request, *args, **kwargs)
|
||||
|
||||
zoom = int(request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
|
||||
rotation = int(request.GET.get('rotation', DEFAULT_ROTATION))
|
||||
document_page_form = DocumentPageForm(instance=document_page, zoom=zoom, rotation=rotation)
|
||||
def get_extra_context(self):
|
||||
zoom = int(self.request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
|
||||
rotation = int(self.request.GET.get('rotation', DEFAULT_ROTATION))
|
||||
document_page_form = DocumentPageForm(
|
||||
instance=self.get_object(), zoom=zoom, rotation=rotation
|
||||
)
|
||||
|
||||
base_title = _('Details for: %s') % document_page
|
||||
base_title = _('Image of: %s') % self.get_object()
|
||||
|
||||
if zoom != DEFAULT_ZOOM_LEVEL:
|
||||
zoom_text = '(%d%%)' % zoom
|
||||
else:
|
||||
zoom_text = ''
|
||||
if zoom != DEFAULT_ZOOM_LEVEL:
|
||||
zoom_text = '(%d%%)' % zoom
|
||||
else:
|
||||
zoom_text = ''
|
||||
|
||||
return render_to_response('appearance/generic_form.html', {
|
||||
'access_object': document_page.document,
|
||||
'form': document_page_form,
|
||||
'navigation_object_list': ('page',),
|
||||
'page': document_page,
|
||||
'rotation': rotation,
|
||||
'title': ' '.join([base_title, zoom_text]),
|
||||
'read_only': True,
|
||||
'zoom': zoom,
|
||||
}, context_instance=RequestContext(request))
|
||||
return {
|
||||
'form': document_page_form,
|
||||
'hide_labels': True,
|
||||
'navigation_object_list': ('page',),
|
||||
'page': self.get_object(),
|
||||
'rotation': rotation,
|
||||
'title': ' '.join([base_title, zoom_text]),
|
||||
'read_only': True,
|
||||
'zoom': zoom,
|
||||
}
|
||||
|
||||
def get_object(self):
|
||||
return get_object_or_404(DocumentPage, pk=self.kwargs['pk'])
|
||||
|
||||
|
||||
def document_page_view_reset(request, document_page_id):
|
||||
|
||||
Reference in New Issue
Block a user