Add depends on Button
issue6919 review40811002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add depends on Button
|
||||
* Add ModelData.has_model cache for ModelStorage.check_xml_record
|
||||
* Limit authentication attempt per IP network
|
||||
* Manage 'X-Forwarded' headers from proxies
|
||||
|
||||
@@ -129,6 +129,9 @@ List of attributes shared by many form elements:
|
||||
* ``pre_validate``: Only for button, it contains a domain to apply
|
||||
on the record before calling the button.
|
||||
|
||||
* ``depends``: Only for button, it must return the list of field on
|
||||
which the button depends.
|
||||
|
||||
.. _common-attributes-help:
|
||||
|
||||
* ``help``: The string that will be displayed when the cursor hovers over
|
||||
|
||||
@@ -1035,6 +1035,7 @@ class ModelData(ModelSQL, ModelView):
|
||||
cls._buttons.update({
|
||||
'sync': {
|
||||
'invisible': ~Eval('out_of_sync'),
|
||||
'depends': ['out_of_sync'],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -76,21 +76,27 @@ class Module(ModelSQL, ModelView):
|
||||
cls._buttons.update({
|
||||
'activate': {
|
||||
'invisible': Eval('state') != 'not activated',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'activate_cancel': {
|
||||
'invisible': Eval('state') != 'to activate',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'deactivate': {
|
||||
'invisible': Eval('state') != 'activated',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'deactivate_cancel': {
|
||||
'invisible': Eval('state') != 'to remove',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'upgrade': {
|
||||
'invisible': Eval('state') != 'activated',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'upgrade_cancel': {
|
||||
'invisible': Eval('state') != 'to upgrade',
|
||||
'depends': ['state'],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ class View(ModelSQL, ModelView):
|
||||
cls._buttons.update({
|
||||
'show': {
|
||||
'readonly': Eval('type') != 'form',
|
||||
'depends': ['type'],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -560,6 +560,9 @@ class ModelView(Model):
|
||||
else:
|
||||
element.set('type', 'instance')
|
||||
|
||||
for depend in states.get('depends', []):
|
||||
fields_attrs.setdefault(depend, {})
|
||||
|
||||
# translate view
|
||||
if Transaction().language != 'en':
|
||||
for attr in ('string', 'sum', 'confirm', 'help'):
|
||||
|
||||
@@ -825,9 +825,11 @@ class UserApplication(Workflow, ModelSQL, ModelView):
|
||||
cls._buttons.update({
|
||||
'validate_': {
|
||||
'invisible': Eval('state') != 'requested',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'cancel': {
|
||||
'invisible': Eval('state') == 'cancelled',
|
||||
'depends': ['state'],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from sql import Table
|
||||
|
||||
from trytond.pool import Pool, isregisteredby
|
||||
from trytond import backend
|
||||
from trytond.model import Workflow, ModelSQL, ModelSingleton, fields
|
||||
from trytond.model import Workflow, ModelSQL, ModelSingleton, ModelView, fields
|
||||
from trytond.model.fields import get_eval_fields, Function
|
||||
from trytond.tools import is_instance_method
|
||||
from trytond.transaction import Transaction
|
||||
@@ -308,6 +308,12 @@ class ModuleTestCase(unittest.TestCase):
|
||||
assert depends <= set(model._fields), (
|
||||
'Unknown depends %s in "%s"."%s"' % (
|
||||
list(depends - set(model._fields)), mname, fname))
|
||||
if issubclass(model, ModelView):
|
||||
for bname, button in model._buttons.iteritems():
|
||||
depends = set(button.get('depends', []))
|
||||
assert depends <= set(model._fields), (
|
||||
'Unknown depends %s in button "%s"."%s"' % (
|
||||
list(depends - set(model._fields)), mname, bname))
|
||||
|
||||
@with_transaction()
|
||||
def test_field_methods(self):
|
||||
|
||||
Reference in New Issue
Block a user