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