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:
56
mayan/apps/document_parsing/methods.py
Normal file
56
mayan/apps/document_parsing/methods.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.common.settings import settings_db_sync_task_delay
|
||||
|
||||
from .events import event_parsing_document_version_submit
|
||||
from .tasks import task_parse_document_version
|
||||
from .utils import get_document_version_content_iterator
|
||||
|
||||
|
||||
def method_document_submit_for_parsing(self):
|
||||
latest_version = self.latest_version
|
||||
# Don't error out if document has no version
|
||||
if latest_version:
|
||||
latest_version.submit_for_parsing()
|
||||
|
||||
|
||||
def method_document_version_submit_for_parsing(self):
|
||||
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},
|
||||
)
|
||||
|
||||
|
||||
def method_get_document_content(self):
|
||||
latest_version = self.latest_version
|
||||
|
||||
if latest_version:
|
||||
return latest_version.get_content()
|
||||
|
||||
|
||||
method_get_document_content.help_text = _(
|
||||
'Return the parsed content of the document.'
|
||||
)
|
||||
method_get_document_content.short_description = _(
|
||||
'get_content()'
|
||||
)
|
||||
|
||||
|
||||
def method_get_document_version_content(self):
|
||||
return ' '.join(
|
||||
get_document_version_content_iterator(document_version=self)
|
||||
)
|
||||
|
||||
|
||||
method_get_document_version_content.help_text = _(
|
||||
'Return the parsed content of the document version.'
|
||||
)
|
||||
Reference in New Issue
Block a user