Convert half the widget to HTML widgets. Rename links and views to use the nomeclature _template_ and _instance_ to differenciate between index instances and index templates. Update URL parameters to use the "_id" form. Add more tests. Add model permission inheritance to the IndexTemplateNode, and IndexInstanceNode models. Remove the level and document count display from the instance node. Display instead the total items. Use a FilteredSelectionForm subclass to display the list of index templates to rebuild. Add missing icons. Add keyword arguments to links. Modernize tests to use the document test mixin. Update the permission requirements for the index template document type selection screen. The document type view permission is now required in addition to the index template edit permission. Use ExternalObjectMixin to reduce the code in all views. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
from __future__ import unicode_literals
|
|
|
|
import logging
|
|
|
|
from django.apps import apps
|
|
from django.db import OperationalError
|
|
|
|
from mayan.apps.lock_manager import LockError
|
|
from mayan.celery import app
|
|
|
|
from .literals import RETRY_DELAY
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, max_retries=None, ignore_result=True)
|
|
def task_delete_empty(self):
|
|
IndexInstanceNode = apps.get_model(
|
|
app_label='document_indexing', model_name='IndexInstanceNode'
|
|
)
|
|
|
|
try:
|
|
IndexInstanceNode.objects.delete_empty()
|
|
except LockError as exception:
|
|
raise self.retry(exc=exception)
|
|
|
|
|
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, max_retries=None, ignore_result=True)
|
|
def task_index_document(self, document_id):
|
|
Document = apps.get_model(
|
|
app_label='documents', model_name='Document'
|
|
)
|
|
Index = apps.get_model(
|
|
app_label='document_indexing', model_name='Index'
|
|
)
|
|
|
|
try:
|
|
document = Document.objects.get(pk=document_id)
|
|
except Document.DoesNotExist:
|
|
# Document was deleted before we could execute, abort about
|
|
# updating
|
|
pass
|
|
else:
|
|
try:
|
|
Index.objects.index_document(document=document)
|
|
except OperationalError as exception:
|
|
logger.warning(
|
|
'Operational error while trying to index document: '
|
|
'%s; %s', document, exception
|
|
)
|
|
raise self.retry(exc=exception)
|
|
except LockError as exception:
|
|
logger.warning(
|
|
'Unable to acquire lock for document %s; %s ',
|
|
document, exception
|
|
)
|
|
raise self.retry(exc=exception)
|
|
|
|
|
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, ignore_result=True)
|
|
def task_rebuild_index(self, index_template_id):
|
|
Index = apps.get_model(
|
|
app_label='document_indexing', model_name='Index'
|
|
)
|
|
|
|
try:
|
|
index = Index.objects.get(pk=index_template_id)
|
|
index.rebuild()
|
|
except LockError as exception:
|
|
# This index is being rebuilt by another task, retry later
|
|
raise self.retry(exc=exception)
|
|
|
|
|
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, max_retries=None, ignore_result=True)
|
|
def task_remove_document(self, document_id):
|
|
Document = apps.get_model(
|
|
app_label='documents', model_name='Document'
|
|
)
|
|
IndexInstanceNode = apps.get_model(
|
|
app_label='document_indexing', model_name='IndexInstanceNode'
|
|
)
|
|
|
|
try:
|
|
document = Document.objects.get(pk=document_id)
|
|
except Document.DoesNotExist:
|
|
# Document was deleted before we could execute
|
|
# Since it was automatically removed from the document M2M
|
|
# we just now delete the empty instance nodes
|
|
try:
|
|
IndexInstanceNode.objects.delete_empty()
|
|
except LockError as exception:
|
|
raise self.retry(exc=exception)
|
|
else:
|
|
try:
|
|
IndexInstanceNode.objects.remove_document(document=document)
|
|
except LockError as exception:
|
|
raise self.retry(exc=exception)
|