Convert the checkout detail view to use the DetailView CBV. Update usage the DetailView CBV in the DocumentProperties view. Add checkout details view permission.
This commit is contained in:
@@ -19,7 +19,7 @@ from .links import (
|
|||||||
from .literals import CHECK_EXPIRED_CHECK_OUTS_INTERVAL
|
from .literals import CHECK_EXPIRED_CHECK_OUTS_INTERVAL
|
||||||
from .permissions import (
|
from .permissions import (
|
||||||
permission_document_checkin, permission_document_checkin_override,
|
permission_document_checkin, permission_document_checkin_override,
|
||||||
permission_document_checkout
|
permission_document_checkout, permission_document_checkout_detail_view
|
||||||
)
|
)
|
||||||
from .tasks import task_check_expired_check_outs # NOQA
|
from .tasks import task_check_expired_check_outs # NOQA
|
||||||
# This import is required so that celerybeat can find the task
|
# This import is required so that celerybeat can find the task
|
||||||
@@ -69,6 +69,7 @@ class CheckoutsApp(MayanAppConfig):
|
|||||||
permission_document_checkout,
|
permission_document_checkout,
|
||||||
permission_document_checkin,
|
permission_document_checkin,
|
||||||
permission_document_checkin_override,
|
permission_document_checkin_override,
|
||||||
|
permission_document_checkout_detail_view
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from common.forms import DetailForm
|
||||||
|
|
||||||
|
from .literals import STATE_LABELS
|
||||||
from .models import DocumentCheckout
|
from .models import DocumentCheckout
|
||||||
from .widgets import SplitTimeDeltaWidget
|
from .widgets import SplitTimeDeltaWidget
|
||||||
|
|
||||||
@@ -13,3 +17,45 @@ class DocumentCheckoutForm(forms.ModelForm):
|
|||||||
widgets = {
|
widgets = {
|
||||||
'expiration_datetime': SplitTimeDeltaWidget()
|
'expiration_datetime': SplitTimeDeltaWidget()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentCheckoutDefailForm(DetailForm):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
instance = kwargs['instance']
|
||||||
|
|
||||||
|
extra_fields = (
|
||||||
|
{
|
||||||
|
'label': _('Document status'),
|
||||||
|
'field': lambda instance: STATE_LABELS[instance.checkout_state()]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if instance.is_checked_out():
|
||||||
|
checkout_info = instance.checkout_info()
|
||||||
|
extra_fields += (
|
||||||
|
{
|
||||||
|
'label': _('User'),
|
||||||
|
'field': lambda instance: checkout_info.user.get_full_name() or checkout_info.user
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('Check out time'),
|
||||||
|
'field': lambda instance: checkout_info.checkout_datetime,
|
||||||
|
'widget': forms.widgets.DateTimeInput
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('Check out expiration'),
|
||||||
|
'field': lambda instance: checkout_info.expiration_datetime,
|
||||||
|
'widget': forms.widgets.DateTimeInput
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('New versions allowed?'),
|
||||||
|
'field': lambda instance: _('Yes') if not checkout_info.block_new_version else _('No')
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs['extra_fields'] = extra_fields
|
||||||
|
super(DocumentCheckoutDefailForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
fields = ()
|
||||||
|
model = DocumentCheckout
|
||||||
|
|||||||
@@ -15,3 +15,6 @@ permission_document_checkin_override = namespace.add_permission(
|
|||||||
permission_document_checkout = namespace.add_permission(
|
permission_document_checkout = namespace.add_permission(
|
||||||
name='checkout_document', label=_('Check out documents')
|
name='checkout_document', label=_('Check out documents')
|
||||||
)
|
)
|
||||||
|
permission_document_checkout_detail_view = namespace.add_permission(
|
||||||
|
name='checkout_detail_view', label=_('Check out details view')
|
||||||
|
)
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ from __future__ import unicode_literals
|
|||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from .api_views import APICheckedoutDocumentListView, APICheckedoutDocumentView
|
from .api_views import APICheckedoutDocumentListView, APICheckedoutDocumentView
|
||||||
from .views import CheckoutDocumentView, CheckoutListView, DocumentCheckinView
|
from .views import (
|
||||||
|
CheckoutDocumentView, CheckoutDetailView, CheckoutListView,
|
||||||
|
DocumentCheckinView
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'checkouts.views',
|
'checkouts.views',
|
||||||
@@ -17,7 +20,7 @@ urlpatterns = patterns(
|
|||||||
name='checkin_document'
|
name='checkin_document'
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r'^(?P<document_pk>\d+)/check/info/$', 'checkout_info',
|
r'^(?P<pk>\d+)/check/info/$', CheckoutDetailView.as_view(),
|
||||||
name='checkout_info'
|
name='checkout_info'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,17 +12,19 @@ from documents.models import Document
|
|||||||
from documents.views import DocumentListView
|
from documents.views import DocumentListView
|
||||||
|
|
||||||
from acls.models import AccessControlList
|
from acls.models import AccessControlList
|
||||||
from common.generics import ConfirmView, SingleObjectCreateView
|
from common.generics import (
|
||||||
from common.utils import encapsulate, render_date_object
|
ConfirmView, SingleObjectCreateView, SingleObjectDetailView
|
||||||
|
)
|
||||||
|
from common.utils import encapsulate
|
||||||
from permissions import Permission
|
from permissions import Permission
|
||||||
|
|
||||||
from .exceptions import DocumentAlreadyCheckedOut, DocumentNotCheckedOut
|
from .exceptions import DocumentAlreadyCheckedOut, DocumentNotCheckedOut
|
||||||
from .forms import DocumentCheckoutForm
|
from .forms import DocumentCheckoutForm, DocumentCheckoutDefailForm
|
||||||
from .literals import STATE_LABELS
|
from .literals import STATE_LABELS
|
||||||
from .models import DocumentCheckout
|
from .models import DocumentCheckout
|
||||||
from .permissions import (
|
from .permissions import (
|
||||||
permission_document_checkin, permission_document_checkin_override,
|
permission_document_checkin, permission_document_checkin_override,
|
||||||
permission_document_checkout
|
permission_document_checkout, permission_document_checkout_detail_view
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -106,55 +108,21 @@ class CheckoutListView(DocumentListView):
|
|||||||
return DocumentCheckout.objects.checked_out_documents()
|
return DocumentCheckout.objects.checked_out_documents()
|
||||||
|
|
||||||
|
|
||||||
def checkout_info(request, document_pk):
|
class CheckoutDetailView(SingleObjectDetailView):
|
||||||
document = get_object_or_404(Document, pk=document_pk)
|
form_class = DocumentCheckoutDefailForm
|
||||||
try:
|
model = Document
|
||||||
Permission.check_permissions(
|
object_permission = permission_document_checkout_detail_view
|
||||||
request.user, (
|
|
||||||
permission_document_checkout, permission_document_checkin
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except PermissionDenied:
|
|
||||||
AccessControlList.objects.check_access(
|
|
||||||
(permission_document_checkout, permission_document_checkin),
|
|
||||||
request.user, document
|
|
||||||
)
|
|
||||||
|
|
||||||
paragraphs = [
|
def get_extra_context(self):
|
||||||
_('Document status: %s') % STATE_LABELS[document.checkout_state()]
|
return {
|
||||||
]
|
'object': self.get_object(),
|
||||||
|
'title': _(
|
||||||
|
'Check out details for document: %s'
|
||||||
|
) % self.get_object()
|
||||||
|
}
|
||||||
|
|
||||||
if document.is_checked_out():
|
def get_object(self):
|
||||||
checkout_info = document.checkout_info()
|
return get_object_or_404(Document, pk=self.kwargs['pk'])
|
||||||
paragraphs.append(
|
|
||||||
_('User: %s') % (
|
|
||||||
checkout_info.user.get_full_name() or checkout_info.user
|
|
||||||
)
|
|
||||||
)
|
|
||||||
paragraphs.append(
|
|
||||||
_(
|
|
||||||
'Check out time: %s'
|
|
||||||
) % render_date_object(checkout_info.checkout_datetime)
|
|
||||||
)
|
|
||||||
paragraphs.append(
|
|
||||||
_(
|
|
||||||
'Check out expiration: %s'
|
|
||||||
) % render_date_object(checkout_info.expiration_datetime)
|
|
||||||
)
|
|
||||||
paragraphs.append(
|
|
||||||
_(
|
|
||||||
'New versions allowed: %s'
|
|
||||||
) % (_('Yes') if not checkout_info.block_new_version else _('No'))
|
|
||||||
)
|
|
||||||
|
|
||||||
return render_to_response(
|
|
||||||
'appearance/generic_template.html', {
|
|
||||||
'paragraphs': paragraphs,
|
|
||||||
'object': document,
|
|
||||||
'title': _('Check out details for document: %s') % document
|
|
||||||
},
|
|
||||||
context_instance=RequestContext(request)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DocumentCheckinView(ConfirmView):
|
class DocumentCheckinView(ConfirmView):
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import logging
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.template.defaultfilters import filesizeformat
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from acls.models import AccessControlList
|
from acls.models import AccessControlList
|
||||||
@@ -101,6 +102,48 @@ class DocumentPropertiesForm(DetailForm):
|
|||||||
"""
|
"""
|
||||||
Detail class form to display a document file based properties
|
Detail class form to display a document file based properties
|
||||||
"""
|
"""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
document = kwargs['instance']
|
||||||
|
|
||||||
|
extra_fields = [
|
||||||
|
{
|
||||||
|
'label': _('Date added'),
|
||||||
|
'field': 'date_added',
|
||||||
|
'widget': forms.widgets.DateTimeInput
|
||||||
|
},
|
||||||
|
{'label': _('UUID'), 'field': 'uuid'},
|
||||||
|
]
|
||||||
|
|
||||||
|
if document.latest_version:
|
||||||
|
extra_fields += (
|
||||||
|
{
|
||||||
|
'label': _('File mimetype'),
|
||||||
|
'field': lambda x: document.file_mimetype or _('None')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('File encoding'),
|
||||||
|
'field': lambda x: document.file_mime_encoding or _(
|
||||||
|
'None'
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('File size'),
|
||||||
|
'field': lambda document: filesizeformat(
|
||||||
|
document.size
|
||||||
|
) if document.size else '-'
|
||||||
|
},
|
||||||
|
{'label': _('Exists in storage'), 'field': 'exists'},
|
||||||
|
{
|
||||||
|
'label': _('File path in storage'),
|
||||||
|
'field': 'latest_version.file'
|
||||||
|
},
|
||||||
|
{'label': _('Checksum'), 'field': 'checksum'},
|
||||||
|
{'label': _('Pages'), 'field': 'page_count'},
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs['extra_fields'] = extra_fields
|
||||||
|
super(DocumentPropertiesForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = ('document_type', 'description', 'language')
|
fields = ('document_type', 'description', 'language')
|
||||||
model = Document
|
model = Document
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from common.generics import (
|
|||||||
SingleObjectDetailView, SingleObjectEditView, SingleObjectListView
|
SingleObjectDetailView, SingleObjectEditView, SingleObjectListView
|
||||||
)
|
)
|
||||||
from common.mixins import MultipleInstanceActionMixin
|
from common.mixins import MultipleInstanceActionMixin
|
||||||
from common.utils import render_date_object
|
|
||||||
from converter.literals import (
|
from converter.literals import (
|
||||||
DEFAULT_PAGE_NUMBER, DEFAULT_ROTATION, DEFAULT_ZOOM_LEVEL
|
DEFAULT_PAGE_NUMBER, DEFAULT_ROTATION, DEFAULT_ZOOM_LEVEL
|
||||||
)
|
)
|
||||||
@@ -533,6 +532,7 @@ class DocumentVersionListView(SingleObjectListView):
|
|||||||
|
|
||||||
|
|
||||||
class DocumentView(SingleObjectDetailView):
|
class DocumentView(SingleObjectDetailView):
|
||||||
|
form_class = DocumentPropertiesForm
|
||||||
model = Document
|
model = Document
|
||||||
object_permission = permission_document_view
|
object_permission = permission_document_view
|
||||||
|
|
||||||
@@ -543,55 +543,11 @@ class DocumentView(SingleObjectDetailView):
|
|||||||
|
|
||||||
def get_extra_context(self):
|
def get_extra_context(self):
|
||||||
return {
|
return {
|
||||||
'form': self.get_form(),
|
|
||||||
'document': self.get_object(),
|
'document': self.get_object(),
|
||||||
'object': self.get_object(),
|
'object': self.get_object(),
|
||||||
'title': _('Properties for document: %s') % self.get_object(),
|
'title': _('Properties for document: %s') % self.get_object(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
document = self.get_object()
|
|
||||||
|
|
||||||
document_fields = [
|
|
||||||
{
|
|
||||||
'label': _('Date added'),
|
|
||||||
'field': lambda document: render_date_object(
|
|
||||||
document.date_added
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{'label': _('UUID'), 'field': 'uuid'},
|
|
||||||
]
|
|
||||||
if document.latest_version:
|
|
||||||
document_fields.extend([
|
|
||||||
{
|
|
||||||
'label': _('File mimetype'),
|
|
||||||
'field': lambda x: document.file_mimetype or _('None')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'label': _('File encoding'),
|
|
||||||
'field': lambda x: document.file_mime_encoding or _(
|
|
||||||
'None'
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'label': _('File size'),
|
|
||||||
'field': lambda document: filesizeformat(
|
|
||||||
document.size
|
|
||||||
) if document.size else '-'
|
|
||||||
},
|
|
||||||
{'label': _('Exists in storage'), 'field': 'exists'},
|
|
||||||
{
|
|
||||||
'label': _('File path in storage'),
|
|
||||||
'field': 'latest_version.file'
|
|
||||||
},
|
|
||||||
{'label': _('Checksum'), 'field': 'checksum'},
|
|
||||||
{'label': _('Pages'), 'field': 'page_count'},
|
|
||||||
])
|
|
||||||
|
|
||||||
return DocumentPropertiesForm(
|
|
||||||
instance=document, extra_fields=document_fields
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class EmptyTrashCanView(ConfirmView):
|
class EmptyTrashCanView(ConfirmView):
|
||||||
extra_context = {
|
extra_context = {
|
||||||
|
|||||||
Reference in New Issue
Block a user