Add automatic check in of documents after check out expiration happens
This commit is contained in:
@@ -4,6 +4,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from navigation.api import (register_links, register_top_menu,
|
||||
register_multi_item_links, register_sidebar_template)
|
||||
from scheduler.api import register_interval_job
|
||||
|
||||
from documents.models import Document
|
||||
from documents.permissions import PERMISSION_DOCUMENT_VIEW
|
||||
@@ -12,6 +13,7 @@ from acls.api import class_permissions
|
||||
from .permissions import (PERMISSION_DOCUMENT_CHECKOUT, PERMISSION_DOCUMENT_CHECKIN, PERMISSION_DOCUMENT_CHECKIN_OVERRIDE)
|
||||
from .links import checkout_list, checkout_document, checkout_info, checkin_document
|
||||
from .models import DocumentCheckout
|
||||
from .tasks import task_check_expired_check_outs
|
||||
|
||||
|
||||
def initialize_document_checkout_extra_methods():
|
||||
@@ -31,8 +33,10 @@ class_permissions(Document, [
|
||||
PERMISSION_DOCUMENT_CHECKIN_OVERRIDE
|
||||
])
|
||||
|
||||
initialize_document_checkout_extra_methods()
|
||||
CHECK_EXPIRED_CHECK_OUTS_INTERVAL=60 # Lowest check out expiration allowed
|
||||
register_interval_job('task_check_expired_check_outs', _(u'Checks the OCR queue for pending documents.'), task_check_expired_check_outs, seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL)
|
||||
|
||||
initialize_document_checkout_extra_methods()
|
||||
|
||||
#TODO: default checkout time
|
||||
#TODO: forcefull check in
|
||||
@@ -40,3 +44,5 @@ initialize_document_checkout_extra_methods()
|
||||
#TODO: out check in after expiration datetime
|
||||
#TODO: add checkin out history
|
||||
#TODO: limit restrictions to non checkout user and admins?
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
from django.db import models
|
||||
|
||||
from documents.models import Document
|
||||
@@ -13,6 +14,13 @@ 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):
|
||||
return Document.objects.filter(pk__in=self.model.objects.filter(expiration_datetime__gt=datetime.datetime.now()).values_list('document__pk', flat=True))
|
||||
|
||||
def check_in_expired_check_outs(self):
|
||||
for document in self.expired_check_outs():
|
||||
document.check_in()
|
||||
|
||||
def is_document_checked_out(self, document):
|
||||
if self.model.objects.filter(document=document):
|
||||
|
||||
24
apps/checkouts/tasks.py
Normal file
24
apps/checkouts/tasks.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
from lock_manager import Lock, LockError
|
||||
|
||||
from .models import DocumentCheckout
|
||||
|
||||
LOCK_EXPIRE = 50
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def task_check_expired_check_outs():
|
||||
logger.debug('executing...')
|
||||
lock_id = u'task_expired_check_outs'
|
||||
try:
|
||||
logger.debug('trying to acquire lock: %s' % lock_id)
|
||||
lock = Lock.acquire_lock(lock_id, LOCK_EXPIRE)
|
||||
logger.debug('acquired lock: %s' % lock_id)
|
||||
DocumentCheckout.objects.check_in_expired_check_outs()
|
||||
lock.release()
|
||||
except LockError:
|
||||
logger.debug('unable to obtain lock')
|
||||
pass
|
||||
Reference in New Issue
Block a user