Update document OCR content view to a CBV.
This commit is contained in:
@@ -18,7 +18,7 @@ class DocumentContentForm(forms.Form):
|
||||
single textarea widget
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.document = kwargs.pop('document', None)
|
||||
self.document = kwargs.pop('instance', None)
|
||||
super(DocumentContentForm, self).__init__(*args, **kwargs)
|
||||
content = []
|
||||
self.fields['contents'].initial = ''
|
||||
|
||||
@@ -6,14 +6,15 @@ from .api_views import (
|
||||
APIDocumentOCRView, APIDocumentPageContentView, APIDocumentVersionOCRView
|
||||
)
|
||||
from .views import (
|
||||
DocumentAllSubmitView, DocumentSubmitView, DocumentSubmitManyView,
|
||||
DocumentTypeSettingsEditView, DocumentTypeSubmitView, EntryListView
|
||||
DocumentAllSubmitView, DocumentOCRContent, DocumentSubmitView,
|
||||
DocumentSubmitManyView, DocumentTypeSettingsEditView,
|
||||
DocumentTypeSubmitView, EntryListView
|
||||
)
|
||||
|
||||
urlpatterns = patterns(
|
||||
'ocr.views',
|
||||
'',
|
||||
url(
|
||||
r'^(?P<document_id>\d+)/content/$', 'document_content',
|
||||
r'^(?P<pk>\d+)/content/$', DocumentOCRContent.as_view(),
|
||||
name='document_content'
|
||||
),
|
||||
url(
|
||||
|
||||
@@ -10,7 +10,8 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from common.generics import (
|
||||
ConfirmView, FormView, SingleObjectEditView, SingleObjectListView
|
||||
ConfirmView, FormView, SingleObjectDetailView, SingleObjectEditView,
|
||||
SingleObjectListView
|
||||
)
|
||||
from common.mixins import MultipleInstanceActionMixin
|
||||
from documents.models import Document, DocumentType
|
||||
@@ -134,30 +135,25 @@ class DocumentTypeSettingsEditView(SingleObjectEditView):
|
||||
}
|
||||
|
||||
|
||||
def document_content(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
class DocumentOCRContent(SingleObjectDetailView):
|
||||
model = Document
|
||||
form_class = DocumentContentForm
|
||||
object_permission = permission_ocr_content_view
|
||||
|
||||
try:
|
||||
Permission.check_permissions(
|
||||
request.user, (permission_ocr_content_view,)
|
||||
)
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(
|
||||
permission_ocr_content_view, request.user, document
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
result = super(DocumentOCRContent, self).dispatch(
|
||||
request, *args, **kwargs
|
||||
)
|
||||
self.get_object().add_as_recent_document_for_user(request.user)
|
||||
return result
|
||||
|
||||
document.add_as_recent_document_for_user(request.user)
|
||||
|
||||
content_form = DocumentContentForm(document=document)
|
||||
|
||||
return render_to_response('appearance/generic_form.html', {
|
||||
'document': document,
|
||||
'form': content_form,
|
||||
'hide_labels': True,
|
||||
'object': document,
|
||||
'read_only': True,
|
||||
'title': _('OCR result for document: %s') % document,
|
||||
}, context_instance=RequestContext(request))
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'document': self.get_object(),
|
||||
'hide_labels': True,
|
||||
'object': self.get_object(),
|
||||
'title': _('OCR result for document: %s') % self.get_object(),
|
||||
}
|
||||
|
||||
|
||||
class EntryListView(SingleObjectListView):
|
||||
|
||||
Reference in New Issue
Block a user