Add from __future__ import unicode_literals, issue #37
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import pytz
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
import pytz
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .permissions import (PERMISSION_DOCUMENT_CHECKOUT, PERMISSION_DOCUMENT_CHECKIN, PERMISSION_DOCUMENT_CHECKIN_OVERRIDE)
|
||||
from .permissions import (
|
||||
PERMISSION_DOCUMENT_CHECKOUT, PERMISSION_DOCUMENT_CHECKIN,
|
||||
PERMISSION_DOCUMENT_CHECKIN_OVERRIDE
|
||||
)
|
||||
|
||||
|
||||
def is_checked_out(context):
|
||||
@@ -13,7 +16,7 @@ def is_not_checked_out(context):
|
||||
return not context['object'].is_checked_out()
|
||||
|
||||
|
||||
checkout_list = {'text': _(u'Checkouts'), 'view': 'checkouts:checkout_list', 'famfam': 'basket'}
|
||||
checkout_list = {'text': _('Checkouts'), 'view': 'checkouts:checkout_list', 'famfam': 'basket'}
|
||||
checkout_document = {'text': _('Check out document'), 'view': 'checkouts:checkout_document', 'args': 'object.pk', 'famfam': 'basket_put', 'condition': is_not_checked_out, 'permissions': [PERMISSION_DOCUMENT_CHECKOUT]}
|
||||
checkin_document = {'text': _('Check in document'), 'view': 'checkouts:checkin_document', 'args': 'object.pk', 'famfam': 'basket_remove', 'condition': is_checked_out, 'permissions': [PERMISSION_DOCUMENT_CHECKIN, PERMISSION_DOCUMENT_CHECKIN_OVERRIDE]}
|
||||
checkout_info = {'text': _('Check in/out'), 'view': 'checkouts:checkout_info', 'args': 'object.pk', 'famfam': 'basket', 'permissions': [PERMISSION_DOCUMENT_CHECKIN, PERMISSION_DOCUMENT_CHECKIN_OVERRIDE, PERMISSION_DOCUMENT_CHECKOUT]}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -6,6 +6,6 @@ STATE_CHECKED_OUT = 'checkedout'
|
||||
STATE_CHECKED_IN = 'checkedin'
|
||||
|
||||
STATE_LABELS = {
|
||||
STATE_CHECKED_OUT: _(u'Checked out'),
|
||||
STATE_CHECKED_IN: _(u'Checked in/available'),
|
||||
STATE_CHECKED_OUT: _('Checked out'),
|
||||
STATE_CHECKED_IN: _('Checked in/available'),
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from django.db import models
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
|
||||
from acls.models import AccessEntry
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
@@ -20,16 +20,16 @@ class DocumentCheckout(models.Model):
|
||||
"""
|
||||
Model to store the state and information of a document checkout
|
||||
"""
|
||||
document = models.ForeignKey(Document, verbose_name=_(u'Document'), unique=True)
|
||||
checkout_datetime = models.DateTimeField(verbose_name=_(u'Check out date and time'), auto_now_add=True)
|
||||
expiration_datetime = models.DateTimeField(verbose_name=_(u'Check out expiration date and time'), help_text=_(u'Amount of time to hold the document checked out in minutes.'))
|
||||
document = models.ForeignKey(Document, verbose_name=_('Document'), unique=True)
|
||||
checkout_datetime = models.DateTimeField(verbose_name=_('Check out date and time'), auto_now_add=True)
|
||||
expiration_datetime = models.DateTimeField(verbose_name=_('Check out expiration date and time'), help_text=_('Amount of time to hold the document checked out in minutes.'))
|
||||
|
||||
# TODO: simplify user_object to an instance of User
|
||||
user_content_type = models.ForeignKey(ContentType, null=True, blank=True) # blank and null added for ease of db migration
|
||||
user_object_id = models.PositiveIntegerField(null=True, blank=True)
|
||||
user_object = generic.GenericForeignKey(ct_field='user_content_type', fk_field='user_object_id')
|
||||
|
||||
block_new_version = models.BooleanField(default=True, verbose_name=_(u'Block new version upload'), help_text=_(u'Do not allow new version of this document to be uploaded.'))
|
||||
block_new_version = models.BooleanField(default=True, verbose_name=_('Block new version upload'), help_text=_('Do not allow new version of this document to be uploaded.'))
|
||||
|
||||
# block_metadata
|
||||
# block_editing
|
||||
@@ -55,5 +55,5 @@ class DocumentCheckout(models.Model):
|
||||
return ('checkout:checkout_info', [self.document.pk])
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'Document checkout')
|
||||
verbose_name_plural = _(u'Document checkouts')
|
||||
verbose_name = _('Document checkout')
|
||||
verbose_name_plural = _('Document checkouts')
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from permissions.models import PermissionNamespace, Permission
|
||||
|
||||
namespace = PermissionNamespace('checkouts', _(u'Document checkout'))
|
||||
namespace = PermissionNamespace('checkouts', _('Document checkout'))
|
||||
|
||||
PERMISSION_DOCUMENT_CHECKOUT = Permission.objects.register(namespace, 'checkout_document', _(u'Check out documents'))
|
||||
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'))
|
||||
PERMISSION_DOCUMENT_CHECKOUT = Permission.objects.register(namespace, 'checkout_document', _('Check out documents'))
|
||||
PERMISSION_DOCUMENT_CHECKIN = Permission.objects.register(namespace, 'checkin_document', _('Check in documents'))
|
||||
PERMISSION_DOCUMENT_CHECKIN_OVERRIDE = Permission.objects.register(namespace, 'checkin_document_override', _('Forcefully check in documents'))
|
||||
PERMISSION_DOCUMENT_RESTRICTIONS_OVERRIDE = Permission.objects.register(namespace, 'checkout_restrictions_override', _('Allow overriding check out restrictions'))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
|
||||
@app.task(ignore_result=True)
|
||||
def task_check_expired_check_outs():
|
||||
logger.debug('executing...')
|
||||
lock_id = u'task_expired_check_outs'
|
||||
lock_id = 'task_expired_check_outs'
|
||||
try:
|
||||
logger.debug('trying to acquire lock: %s', lock_id)
|
||||
lock = Lock.acquire_lock(lock_id, LOCK_EXPIRE)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .api_views import APICheckedoutDocumentListView, APICheckedoutDocumentView
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import PermissionDenied
|
||||
@@ -12,8 +12,7 @@ from documents.models import Document
|
||||
from documents.views import document_list
|
||||
|
||||
from acls.models import AccessEntry
|
||||
from common.utils import get_object_name
|
||||
from common.utils import encapsulate
|
||||
from common.utils import encapsulate, get_object_name
|
||||
from permissions.models import Permission
|
||||
|
||||
from .exceptions import DocumentAlreadyCheckedOut, DocumentNotCheckedOut
|
||||
@@ -29,12 +28,12 @@ def checkout_list(request):
|
||||
return document_list(
|
||||
request,
|
||||
object_list=DocumentCheckout.objects.checked_out_documents(),
|
||||
title=_(u'Documents checked out'),
|
||||
title=_('Documents checked out'),
|
||||
extra_context={
|
||||
'extra_columns': [
|
||||
{'name': _(u'Checkout user'), 'attribute': encapsulate(lambda document: get_object_name(document.checkout_info().user_object, display_object_type=False))},
|
||||
{'name': _(u'Checkout time and date'), 'attribute': encapsulate(lambda document: document.checkout_info().checkout_datetime)},
|
||||
{'name': _(u'Checkout expiration'), 'attribute': encapsulate(lambda document: document.checkout_info().expiration_datetime)},
|
||||
{'name': _('Checkout user'), 'attribute': encapsulate(lambda document: get_object_name(document.checkout_info().user_object, display_object_type=False))},
|
||||
{'name': _('Checkout time and date'), 'attribute': encapsulate(lambda document: document.checkout_info().checkout_datetime)},
|
||||
{'name': _('Checkout expiration'), 'attribute': encapsulate(lambda document: document.checkout_info().expiration_datetime)},
|
||||
],
|
||||
}
|
||||
)
|
||||
@@ -47,19 +46,19 @@ def checkout_info(request, document_pk):
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_accesses([PERMISSION_DOCUMENT_CHECKOUT, PERMISSION_DOCUMENT_CHECKIN], request.user, document)
|
||||
|
||||
paragraphs = [_(u'Document status: %s') % STATE_LABELS[document.checkout_state()]]
|
||||
paragraphs = [_('Document status: %s') % STATE_LABELS[document.checkout_state()]]
|
||||
|
||||
if document.is_checked_out():
|
||||
checkout_info = document.checkout_info()
|
||||
paragraphs.append(_(u'User: %s') % get_object_name(checkout_info.user_object, display_object_type=False))
|
||||
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')))
|
||||
paragraphs.append(_('User: %s') % get_object_name(checkout_info.user_object, display_object_type=False))
|
||||
paragraphs.append(_('Check out time: %s') % checkout_info.checkout_datetime)
|
||||
paragraphs.append(_('Check out expiration: %s') % checkout_info.expiration_datetime)
|
||||
paragraphs.append(_('New versions allowed: %s') % (_('Yes') if not checkout_info.block_new_version else _('No')))
|
||||
|
||||
return render_to_response('main/generic_template.html', {
|
||||
'paragraphs': paragraphs,
|
||||
'object': document,
|
||||
'title': _(u'Document check out details')
|
||||
'title': _('Document check out details')
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@@ -79,12 +78,12 @@ def checkout_document(request, document_pk):
|
||||
document_checkout.document = document
|
||||
document_checkout.save()
|
||||
except DocumentAlreadyCheckedOut:
|
||||
messages.error(request, _(u'Document already checked out.'))
|
||||
messages.error(request, _('Document already checked out.'))
|
||||
return HttpResponseRedirect(reverse('checkouts:checkout_info', args=[document.pk]))
|
||||
except Exception as exception:
|
||||
messages.error(request, _(u'Error trying to check out document; %s') % exception)
|
||||
messages.error(request, _('Error trying to check out document; %s') % exception)
|
||||
else:
|
||||
messages.success(request, _(u'Document "%s" checked out successfully.') % document)
|
||||
messages.success(request, _('Document "%s" checked out successfully.') % document)
|
||||
return HttpResponseRedirect(reverse('checkouts:checkout_info', args=[document.pk]))
|
||||
else:
|
||||
form = DocumentCheckoutForm(initial={'document': document})
|
||||
@@ -92,7 +91,7 @@ def checkout_document(request, document_pk):
|
||||
return render_to_response('main/generic_form.html', {
|
||||
'form': form,
|
||||
'object': document,
|
||||
'title': _(u'Document check out')
|
||||
'title': _('Document check out')
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@@ -104,7 +103,7 @@ def checkin_document(request, document_pk):
|
||||
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', reverse('main:home'))))
|
||||
|
||||
if not document.is_checked_out():
|
||||
messages.error(request, _(u'Document has not been checked out.'))
|
||||
messages.error(request, _('Document has not been checked out.'))
|
||||
return HttpResponseRedirect(previous)
|
||||
|
||||
# If the user trying to check in the document is the same as the check out
|
||||
@@ -125,11 +124,11 @@ def checkin_document(request, document_pk):
|
||||
try:
|
||||
document.check_in(user=request.user)
|
||||
except DocumentNotCheckedOut:
|
||||
messages.error(request, _(u'Document has not been checked out.'))
|
||||
messages.error(request, _('Document has not been checked out.'))
|
||||
except Exception as exception:
|
||||
messages.error(request, _(u'Error trying to check in document; %s') % exception)
|
||||
messages.error(request, _('Error trying to check in document; %s') % exception)
|
||||
else:
|
||||
messages.success(request, _(u'Document "%s" checked in successfully.') % document)
|
||||
messages.success(request, _('Document "%s" checked in successfully.') % document)
|
||||
return HttpResponseRedirect(next)
|
||||
|
||||
context = {
|
||||
@@ -140,9 +139,9 @@ def checkin_document(request, document_pk):
|
||||
}
|
||||
|
||||
if document.checkout_info().user_object != request.user:
|
||||
context['title'] = _(u'You didn\'t originally checked out this document. Are you sure you wish to forcefully check in document: %s?') % document
|
||||
context['title'] = _('You didn\'t originally checked out this document. Are you sure you wish to forcefully check in document: %s?') % document
|
||||
else:
|
||||
context['title'] = _(u'Are you sure you wish to check in document: %s?') % document
|
||||
context['title'] = _('Are you sure you wish to check in document: %s?') % document
|
||||
|
||||
return render_to_response('main/generic_confirm.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -14,9 +14,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': _('Days')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 4, 'style': 'width: 5em;', 'placeholder': _('Hours')}),
|
||||
forms.widgets.TextInput(attrs={'maxlength': 5, 'style': 'width: 5em;', 'placeholder': _('Minutes')}),
|
||||
)
|
||||
super(SplitDeltaWidget, self).__init__(widgets, attrs)
|
||||
|
||||
@@ -46,10 +46,10 @@ class SplitTimeDeltaField(forms.MultiValueField):
|
||||
widget = SplitDeltaWidget
|
||||
hidden_widget = SplitHiddenDeltaWidget
|
||||
default_error_messages = {
|
||||
'invalid_days': _(u'Enter a valid number of days.'),
|
||||
'invalid_hours': _(u'Enter a valid number of hours.'),
|
||||
'invalid_minutes': _(u'Enter a valid number of minutes.'),
|
||||
'invalid_timedelta': _(u'Enter a valid time difference.'),
|
||||
'invalid_days': _('Enter a valid number of days.'),
|
||||
'invalid_hours': _('Enter a valid number of hours.'),
|
||||
'invalid_minutes': _('Enter a valid number of minutes.'),
|
||||
'invalid_timedelta': _('Enter a valid time difference.'),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -75,7 +75,7 @@ class SplitTimeDeltaField(forms.MultiValueField):
|
||||
),
|
||||
)
|
||||
super(SplitTimeDeltaField, self).__init__(fields, *args, **kwargs)
|
||||
self.help_text = _(u'Amount of time to hold the document in the checked out state in days, hours and/or minutes.')
|
||||
self.help_text = _('Amount of time to hold the document in the checked out state in days, hours and/or minutes.')
|
||||
self.label = _('Check out expiration date and time')
|
||||
|
||||
def compress(self, data_list):
|
||||
|
||||
Reference in New Issue
Block a user