Import and PEP8 cleanups
This commit is contained in:
@@ -2,13 +2,10 @@ from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from navigation.api import (bind_links, register_top_menu,
|
||||
register_model_list_columns,
|
||||
register_sidebar_template, Link)
|
||||
from navigation.api import bind_links, register_top_menu
|
||||
from scheduler.api import register_interval_job
|
||||
|
||||
from documents.models import Document
|
||||
from documents.permissions import PERMISSION_DOCUMENT_VIEW
|
||||
from acls.api import class_permissions
|
||||
|
||||
from .permissions import (PERMISSION_DOCUMENT_CHECKOUT,
|
||||
@@ -37,6 +34,6 @@ class_permissions(Document, [
|
||||
PERMISSION_DOCUMENT_RESTRICTIONS_OVERRIDE
|
||||
])
|
||||
|
||||
CHECK_EXPIRED_CHECK_OUTS_INTERVAL=60 # Lowest check out expiration allowed
|
||||
CHECK_EXPIRED_CHECK_OUTS_INTERVAL = 60 # Lowest check out expiration allowed
|
||||
register_interval_job('task_check_expired_check_outs', _(u'Check expired check out documents and checks them in.'), task_check_expired_check_outs, seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL)
|
||||
initialize_document_checkout_extra_methods()
|
||||
|
||||
@@ -3,7 +3,8 @@ class DocumentNotCheckedOut(Exception):
|
||||
Raised when trying to checkin a document that is not checkedout
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class DocumentAlreadyCheckedOut(Exception):
|
||||
"""
|
||||
Raised when trying to checkout an already checkedout document
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .models import DocumentCheckout
|
||||
from .exceptions import DocumentAlreadyCheckedOut
|
||||
@@ -17,7 +16,7 @@ class DocumentCheckoutForm(forms.ModelForm):
|
||||
|
||||
widgets = {
|
||||
'document': forms.widgets.HiddenInput(),
|
||||
}
|
||||
}
|
||||
|
||||
def clean_document(self):
|
||||
document = self.cleaned_data['document']
|
||||
|
||||
@@ -2,7 +2,6 @@ from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from documents.permissions import PERMISSION_DOCUMENT_VIEW
|
||||
from navigation.api import Link
|
||||
|
||||
from .permissions import (PERMISSION_DOCUMENT_CHECKOUT, PERMISSION_DOCUMENT_CHECKIN, PERMISSION_DOCUMENT_CHECKIN_OVERRIDE)
|
||||
|
||||
@@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
class DocumentCheckoutManager(models.Manager):
|
||||
def checked_out_documents(self):
|
||||
return Document.objects.filter(pk__in=self.model.objects.all().values_list('document__pk', flat=True))
|
||||
|
||||
|
||||
def expired_check_outs(self):
|
||||
expired_list = Document.objects.filter(pk__in=self.model.objects.filter(expiration_datetime__lte=datetime.datetime.now()).values_list('document__pk', flat=True))
|
||||
logger.debug('expired_list: %s' % expired_list)
|
||||
@@ -37,7 +37,7 @@ class DocumentCheckoutManager(models.Manager):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def check_in_document(self, document, user=None):
|
||||
try:
|
||||
document_checkout = self.model.objects.get(document=document)
|
||||
@@ -51,9 +51,9 @@ class DocumentCheckoutManager(models.Manager):
|
||||
history_document_checked_in.commit(source_object=document, data={'user': user, 'document': document})
|
||||
else:
|
||||
history_document_auto_checked_in.commit(source_object=document, data={'document': document})
|
||||
|
||||
|
||||
document_checkout.delete()
|
||||
|
||||
|
||||
def document_checkout_info(self, document):
|
||||
try:
|
||||
return self.model.objects.get(document=document)
|
||||
@@ -93,7 +93,6 @@ class DocumentCheckoutManager(models.Manager):
|
||||
# Last resort check if original user enabled restriction
|
||||
return not checkout_info.block_new_version
|
||||
else:
|
||||
return True
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
from django.db import models, IntegrityError
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
@@ -11,7 +11,6 @@ from django.contrib.contenttypes import generic
|
||||
from documents.models import Document
|
||||
|
||||
from .managers import DocumentCheckoutManager
|
||||
from .exceptions import DocumentAlreadyCheckedOut
|
||||
from .events import history_document_checked_out
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -33,9 +32,9 @@ class DocumentCheckout(models.Model):
|
||||
#block_metadata
|
||||
#block_editing
|
||||
#block tag add/remove
|
||||
|
||||
|
||||
objects = DocumentCheckoutManager()
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.document)
|
||||
|
||||
@@ -45,11 +44,11 @@ class DocumentCheckout(models.Model):
|
||||
result = super(DocumentCheckout, self).save(*args, **kwargs)
|
||||
history_document_checked_out.commit(source_object=self.document, data={'user': self.user_object, 'document': self.document})
|
||||
return result
|
||||
|
||||
|
||||
@models.permalink
|
||||
def get_absolute_url(self):
|
||||
return ('checkout_info', [self.document.pk])
|
||||
|
||||
return ('checkout_info', [self.document.pk])
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'document checkout')
|
||||
verbose_name_plural = _(u'document checkouts')
|
||||
|
||||
@@ -10,4 +10,3 @@ PERMISSION_DOCUMENT_CHECKOUT = Permission.objects.register(namespace, 'checkout_
|
||||
PERMISSION_DOCUMENT_CHECKIN = Permission.objects.register(namespace, 'checkin_document', _(u'Check in documents'))
|
||||
PERMISSION_DOCUMENT_CHECKIN_OVERRIDE = Permission.objects.register(namespace, 'checkin_document_override', _(u'Forcefully check in documents'))
|
||||
PERMISSION_DOCUMENT_RESTRICTIONS_OVERRIDE = Permission.objects.register(namespace, 'checkout_restrictions_override', _(u'Allow overriding check out restrictions'))
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ from .permissions import (PERMISSION_DOCUMENT_CHECKOUT, PERMISSION_DOCUMENT_CHEC
|
||||
PERMISSION_DOCUMENT_CHECKIN_OVERRIDE)
|
||||
from .forms import DocumentCheckoutForm
|
||||
from .exceptions import DocumentAlreadyCheckedOut, DocumentNotCheckedOut
|
||||
from .literals import STATE_CHECKED_OUT, STATE_CHECKED_IN, STATE_ICONS, STATE_LABELS
|
||||
from .widgets import checkout_widget
|
||||
|
||||
|
||||
@@ -56,12 +55,12 @@ def checkout_info(request, document_pk):
|
||||
paragraphs.append(_(u'Check out time: %s') % checkout_info.checkout_datetime)
|
||||
paragraphs.append(_(u'Check out expiration: %s') % checkout_info.expiration_datetime)
|
||||
paragraphs.append(_(u'New versions allowed: %s') % (_(u'yes') if not checkout_info.block_new_version else _(u'no')))
|
||||
|
||||
|
||||
return render_to_response('generic_template.html', {
|
||||
'paragraphs': paragraphs,
|
||||
'object': document,
|
||||
'title': _(u'Check out details for document: %s') % document
|
||||
}, context_instance=RequestContext(request))
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def checkout_document(request, document_pk):
|
||||
@@ -70,7 +69,7 @@ def checkout_document(request, document_pk):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CHECKOUT])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_CHECKOUT, request.user, document)
|
||||
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentCheckoutForm(data=request.POST, initial={'document': document})
|
||||
try:
|
||||
@@ -94,7 +93,7 @@ def checkout_document(request, document_pk):
|
||||
'form': form,
|
||||
'object': document,
|
||||
'title': _(u'Check out document: %s') % document
|
||||
}, context_instance=RequestContext(request))
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def checkin_document(request, document_pk):
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.utils.safestring import mark_safe
|
||||
from django.conf import settings
|
||||
from django.core import validators
|
||||
|
||||
from .literals import STATE_CHECKED_OUT, STATE_CHECKED_IN, STATE_ICONS, STATE_LABELS
|
||||
from .literals import STATE_ICONS, STATE_LABELS
|
||||
|
||||
|
||||
def checkout_widget(document):
|
||||
@@ -27,9 +27,9 @@ class SplitDeltaWidget(forms.widgets.MultiWidget):
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
widgets = (
|
||||
forms.widgets.TextInput(attrs={'maxlength': 3, 'style':'width: 5em;', 'placeholder': _(u'Days')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 4, 'style':'width: 5em;', 'placeholder': _(u'Hours')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 5, 'style':'width: 5em;', 'placeholder': _(u'Minutes')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 3, 'style': 'width: 5em;', 'placeholder': _(u'Days')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 4, 'style': 'width: 5em;', 'placeholder': _(u'Hours')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 5, 'style': 'width: 5em;', 'placeholder': _(u'Minutes')}),
|
||||
)
|
||||
super(SplitDeltaWidget, self).__init__(widgets, attrs)
|
||||
|
||||
@@ -49,7 +49,7 @@ class SplitHiddenDeltaWidget(forms.widgets.SplitDateTimeWidget):
|
||||
is_hidden = True
|
||||
|
||||
def __init__(self, attrs=None):
|
||||
super(SplitHiddenDeltaWidget, self).__init__(attrs, date_format, time_format)
|
||||
super(SplitHiddenDeltaWidget, self).__init__(attrs)
|
||||
for widget in self.widgets:
|
||||
widget.input_type = 'hidden'
|
||||
widget.is_hidden = True
|
||||
@@ -73,15 +73,15 @@ class SplitTimeDeltaField(forms.MultiValueField):
|
||||
fields = (
|
||||
forms.IntegerField(min_value=0,
|
||||
error_messages={'invalid': errors['invalid_days']},
|
||||
localize=localize
|
||||
localize=localize
|
||||
),
|
||||
forms.IntegerField(min_value=0,
|
||||
error_messages={'invalid': errors['invalid_hours']},
|
||||
localize=localize
|
||||
localize=localize
|
||||
),
|
||||
forms.IntegerField(min_value=0,
|
||||
error_messages={'invalid': errors['invalid_minutes']},
|
||||
localize=localize
|
||||
localize=localize
|
||||
),
|
||||
)
|
||||
super(SplitTimeDeltaField, self).__init__(fields, *args, **kwargs)
|
||||
@@ -91,7 +91,7 @@ class SplitTimeDeltaField(forms.MultiValueField):
|
||||
def compress(self, data_list):
|
||||
if data_list == [0, 0, 0]:
|
||||
raise forms.ValidationError(self.error_messages['invalid_timedelta'])
|
||||
|
||||
|
||||
if data_list:
|
||||
# Raise a validation error if time or date is empty
|
||||
# (possible if SplitDateTimeField has required=False).
|
||||
@@ -100,8 +100,8 @@ class SplitTimeDeltaField(forms.MultiValueField):
|
||||
if data_list[1] in validators.EMPTY_VALUES:
|
||||
raise forms.ValidationError(self.error_messages['invalid_hours'])
|
||||
if data_list[2] in validators.EMPTY_VALUES:
|
||||
raise forms.ValidationError(self.error_messages['invalid_minutes'])
|
||||
|
||||
raise forms.ValidationError(self.error_messages['invalid_minutes'])
|
||||
|
||||
timedelta = datetime.timedelta(days=data_list[0], hours=data_list[1], minutes=data_list[2])
|
||||
return datetime.datetime.now() + timedelta
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user