Refactor the model accesors

Refactor the accesors to behave like methods instead of properties.
This means all accesors will be prepended with the string
"get_" and will include a set of parenthesis.

Improve the ModeAttribute class to use the method's
short_description. This commit also adds support for a
new method .help_text attribute has been added.

Move accessors to their own module, named "methods.py".

Remove the PropertyHelper class as the accessors no longer
need it.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-15 04:49:40 -04:00
parent 8c63ef4c69
commit 0e86f2ad8a
42 changed files with 434 additions and 282 deletions

View File

@@ -1,11 +1,9 @@
from __future__ import unicode_literals
import logging
from datetime import timedelta
from django.apps import apps
from django.db.models.signals import post_save
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from kombu import Exchange, Queue
@@ -16,14 +14,12 @@ from mayan.apps.common import (
menu_tools
)
from mayan.apps.common.classes import ModelAttribute, ModelField
from mayan.apps.common.settings import settings_db_sync_task_delay
from mayan.apps.documents.search import document_page_search, document_search
from mayan.apps.documents.signals import post_version_upload
from mayan.apps.documents.widgets import document_link
from mayan.apps.navigation import SourceColumn
from mayan.celery import app
from .events import event_parsing_document_version_submit
from .handlers import (
handler_index_document, handler_initialize_new_parsing_settings,
handler_parse_document_version
@@ -35,36 +31,20 @@ from .links import (
link_document_type_parsing_settings, link_document_type_submit,
link_error_list
)
from .methods import (
method_document_submit_for_parsing,
method_document_version_submit_for_parsing,
method_get_document_content, method_get_document_version_content
)
from .permissions import (
permission_content_view, permission_document_type_parsing_setup,
permission_parse_document
)
from .signals import post_document_version_parsing
from .utils import document_property_content, get_document_content
logger = logging.getLogger(__name__)
def document_parsing_submit(self):
latest_version = self.latest_version
# Don't error out if document has no version
if latest_version:
latest_version.submit_for_parsing()
def document_version_parsing_submit(self):
from .tasks import task_parse_document_version
event_parsing_document_version_submit.commit(
action_object=self.document, target=self
)
task_parse_document_version.apply_async(
eta=now() + timedelta(seconds=settings_db_sync_task_delay.value),
kwargs={'document_version_pk': self.pk},
)
class DocumentParsingApp(MayanAppConfig):
app_namespace = 'document_parsing'
app_url = 'parsing'
@@ -96,26 +76,24 @@ class DocumentParsingApp(MayanAppConfig):
)
Document.add_to_class(
name='submit_for_parsing', value=document_parsing_submit
name='submit_for_parsing',
value=method_document_submit_for_parsing
)
Document.add_to_class(
name='content', value=document_property_content
name='get_content', value=method_get_document_content
)
DocumentVersion.add_to_class(
name='content', value=get_document_content
name='get_content', value=method_get_document_version_content
)
DocumentVersion.add_to_class(
name='submit_for_parsing', value=document_version_parsing_submit
name='submit_for_parsing',
value=method_document_version_submit_for_parsing
)
ModelAttribute(
model=Document, name='content', description=_(
'The parsed content of the document.'
)
)
ModelAttribute(model=Document, name='get_content')
ModelField(
Document, name='versions__pages__content__content'
model=Document, name='versions__pages__content__content'
)
ModelPermission.register(