Add first control code
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -88,16 +88,18 @@ class ControlCode(object):
|
||||
}
|
||||
)
|
||||
|
||||
# Sort control codes so that they are executed in the
|
||||
# specified order after the collection finishes.
|
||||
results = results.sort(key=lambda x: x['order'])
|
||||
# Sort control codes so that they are executed in the
|
||||
# specified order after the collection finishes.
|
||||
results.sort(key=lambda x: x['order'])
|
||||
|
||||
for result in results:
|
||||
control_code_class = ControlCode.get(name=result['name'])
|
||||
control_code = control_code_class(
|
||||
**yaml_load(result['arguments'])
|
||||
)
|
||||
control_code.execute()
|
||||
context = {'document_page': document_page}
|
||||
|
||||
for result in results:
|
||||
control_code_class = ControlCode.get(name=result['name'])
|
||||
control_code = control_code_class(
|
||||
**yaml_load(result['arguments'])
|
||||
)
|
||||
control_code.execute(context=context)
|
||||
|
||||
@classmethod
|
||||
def register(cls, control_code):
|
||||
@@ -128,7 +130,7 @@ class ControlCode(object):
|
||||
|
||||
return CONTROL_CODE_SEPARATOR.join(result)
|
||||
|
||||
def execute(self):
|
||||
def execute(self, context):
|
||||
raise NotImplementedError(
|
||||
'Your %s class has not defined the required '
|
||||
'execue() method.' % self.__class__.__name__
|
||||
|
||||
@@ -3,13 +3,18 @@ from __future__ import unicode_literals
|
||||
from .classes import ControlCode
|
||||
|
||||
|
||||
class ControlCodeTest(ControlCode):
|
||||
arguments = ('argument_1',)
|
||||
label = 'Test'
|
||||
name = 'test'
|
||||
class ControlCodeAttributeEdit(ControlCode):
|
||||
arguments = ('attribute', 'value')
|
||||
label = 'Change document attribute'
|
||||
name = 'document_attribute_edit'
|
||||
|
||||
def execute(self):
|
||||
pass
|
||||
def execute(self, context):
|
||||
document = context['document_page'].document
|
||||
print("!@#@", self.attribute, self.value)
|
||||
setattr(document, self.attribute, self.value)
|
||||
print("!!", document.label)
|
||||
|
||||
document.save()
|
||||
|
||||
|
||||
ControlCode.register(control_code=ControlCodeTest)
|
||||
ControlCode.register(control_code=ControlCodeAttributeEdit)
|
||||
|
||||
@@ -3,11 +3,14 @@ from __future__ import unicode_literals
|
||||
from mayan.apps.common.tests.base import BaseTestCase
|
||||
from mayan.apps.documents.tests.base import GenericDocumentTestCase
|
||||
|
||||
from ..control_codes import ControlCodeAttributeEdit
|
||||
|
||||
from .mixins import ControlSheetCodeTestMixin
|
||||
|
||||
#TODO: use mktmp
|
||||
TEST_CONTROL_CODE_DOCUMENT_PATH = '/tmp/test_control_code.png'
|
||||
|
||||
|
||||
"""
|
||||
class ControlCodeTestCase(ControlSheetCodeTestMixin, GenericDocumentTestCase):
|
||||
auto_upload_document = False
|
||||
test_document_path = TEST_CONTROL_CODE_DOCUMENT_PATH
|
||||
@@ -17,8 +20,26 @@ class ControlCodeTestCase(ControlSheetCodeTestMixin, GenericDocumentTestCase):
|
||||
control_code = self._test_control_code_class(
|
||||
argument_1='test argument value'
|
||||
)
|
||||
control_code.image.save(file_object)
|
||||
control_code.get_image().save(file_object)
|
||||
|
||||
self.upload_document()
|
||||
|
||||
print self.test_document.pages.count()
|
||||
"""
|
||||
|
||||
class ControlCodeAttributeEditTestCase(GenericDocumentTestCase):
|
||||
auto_upload_document = False
|
||||
test_document_path = TEST_CONTROL_CODE_DOCUMENT_PATH
|
||||
|
||||
def test_control_code(self):
|
||||
TEST_ATTRIBUTE_VALUE = 'test value'
|
||||
|
||||
with open(TEST_CONTROL_CODE_DOCUMENT_PATH, mode='wb') as file_object:
|
||||
control_code = ControlCodeAttributeEdit(
|
||||
attribute='label', value=TEST_ATTRIBUTE_VALUE
|
||||
)
|
||||
control_code.get_image().save(file_object)
|
||||
|
||||
self.upload_document()
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(self.test_document.label, TEST_ATTRIBUTE_VALUE)
|
||||
|
||||
Reference in New Issue
Block a user