Merge all kind of buttons

review483002
This commit is contained in:
Cédric Krier
2012-09-10 15:26:34 +02:00
parent 8ba5902d01
commit 4dcb7b6dd3
11 changed files with 58 additions and 82 deletions
+1
View File
@@ -1,3 +1,4 @@
* Merge all kind of buttons
* Use XML id for board action instead of id
* Add states attribute to notebook
* Allow to use tuple for Reference
+5
View File
@@ -117,6 +117,11 @@ Static methods:
Decorate button method to check group access.
.. staticmethod:: ModelView.button_action(action)
Same as :stat:`ModelView.button` but return the action id of the XML `id`
action.
Instance methods:
.. method:: ModelView.fields_view_get([view_id[, view_type[, toolbar]]])
+10 -20
View File
@@ -18,18 +18,12 @@ this repository contains the full copyright notices and license terms. -->
<label name="state"/>
<field name="state" readonly="1"/>
<group col="2" colspan="2" id="button">
<button string="Mark for Upgrade" name="upgrade"
type="object"/>
<button string="Mark for Uninstallation (beta)" name="uninstall"
type="object"/>
<button string="Mark for Installation" name="install"
type="object"/>
<button string="Cancel Installation" name="install_cancel"
type="object"/>
<button string="Cancel Upgrade" name="upgrade_cancel"
type="object"/>
<button string="Cancel Uninstallation" name="uninstall_cancel"
type="object"/>
<button string="Mark for Upgrade" name="upgrade"/>
<button string="Mark for Uninstallation (beta)" name="uninstall"/>
<button string="Mark for Installation" name="install"/>
<button string="Cancel Installation" name="install_cancel"/>
<button string="Cancel Upgrade" name="upgrade_cancel"/>
<button string="Cancel Uninstallation" name="uninstall_cancel"/>
</group>
</form>
]]>
@@ -45,14 +39,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="name" expand="1"/>
<field name="version"/>
<field name="state"/>
<button string="Mark for Upgrade" name="upgrade"
type="object"/>
<button string="Mark for Installation" name="install"
type="object"/>
<button string="Cancel Installation" name="install_cancel"
type="object"/>
<button string="Cancel Upgrade" name="upgrade_cancel"
type="object"/>
<button string="Mark for Upgrade" name="upgrade"/>
<button string="Mark for Installation" name="install"/>
<button string="Cancel Installation" name="install_cancel"/>
<button string="Cancel Upgrade" name="upgrade_cancel"/>
</tree>
]]>
</field>
-4
View File
@@ -137,12 +137,8 @@ attlist.button &= attribute help { text }?
attlist.button &=
[ a:defaultValue = "Unknown" ] attribute string { text }?
attlist.button &= attribute icon { text }?
attlist.button &=
[ a:defaultValue = "object" ]
attribute type { "object" | "action" }?
attlist.button &= attribute confirm { text }?
attlist.button &= attribute name { text }
attlist.button &= attribute states { text }?
notebook = element notebook { attlist.notebook, page* }
attlist.notebook &= [ a:defaultValue = "4" ] attribute colspan { text }?
attlist.notebook &= attribute states { text }?
-15
View File
@@ -530,16 +530,6 @@
<attribute name="icon"/>
</optional>
</define>
<define name="attlist.button" combine="interleave">
<optional>
<attribute name="type" a:defaultValue="object">
<choice>
<value>object</value>
<value>action</value>
</choice>
</attribute>
</optional>
</define>
<define name="attlist.button" combine="interleave">
<optional>
<attribute name="confirm"/>
@@ -548,11 +538,6 @@
<define name="attlist.button" combine="interleave">
<attribute name="name"/>
</define>
<define name="attlist.button" combine="interleave">
<optional>
<attribute name="states"/>
</optional>
</define>
<define name="notebook">
<element name="notebook">
<ref name="attlist.notebook"/>
-4
View File
@@ -54,12 +54,8 @@ button = element button { attlist.button, empty }
attlist.button &= attribute help { text }?
attlist.button &=
[ a:defaultValue = "Unknown" ] attribute string { text }?
attlist.button &=
[ a:defaultValue = "object" ]
attribute type { "object" | "action" }?
attlist.button &= attribute confirm { text }?
attlist.button &= attribute name { text }
attlist.button &= attribute states { text }?
data = element data { attlist.data, xpath+ }
attlist.data &= empty
xpath = element xpath { attlist.xpath,
-15
View File
@@ -163,16 +163,6 @@
<attribute name="string" a:defaultValue="Unknown"/>
</optional>
</define>
<define name="attlist.button" combine="interleave">
<optional>
<attribute name="type" a:defaultValue="object">
<choice>
<value>object</value>
<value>action</value>
</choice>
</attribute>
</optional>
</define>
<define name="attlist.button" combine="interleave">
<optional>
<attribute name="confirm"/>
@@ -181,11 +171,6 @@
<define name="attlist.button" combine="interleave">
<attribute name="name"/>
</define>
<define name="attlist.button" combine="interleave">
<optional>
<attribute name="states"/>
</optional>
</define>
<define name="data">
<element name="data">
<ref name="attlist.data"/>
+7
View File
@@ -50,6 +50,9 @@ class View(ModelSQL, ModelView):
'invalid_xml': 'Invalid XML for View!',
})
self._order.insert(0, ('priority', 'ASC'))
self._buttons.update({
'show': {},
})
def init(self, module_name):
super(View, self).init(module_name)
@@ -70,6 +73,10 @@ class View(ModelSQL, ModelView):
def default_module(self):
return Transaction().context.get('module') or ''
@ModelView.button_action('ir.act_view_show')
def show(self, ids):
pass
def check_xml(self, ids):
"Check XML"
pool = Pool()
+1 -5
View File
@@ -29,11 +29,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="field_childs"/>
<separator name="arch" colspan="4"/>
<field name="arch" colspan="4"/>
<button name="%(act_view_show)d"
string="_Show"
type="action"
colspan="4"
/>
<button name="show" string="_Show" colspan="4"/>
</form>
]]>
</field>
+31 -13
View File
@@ -450,19 +450,17 @@ class ModelView(Model):
CONTEXT)))
if element.tag == 'button':
if element.get('type', 'object') == 'object':
assert not element.get('states')
button_name = element.attrib['name']
if button_name in self._buttons:
states = self._buttons[button_name]
else:
states = {}
groups = set(user_obj.get_groups())
button_groups = button_obj.get_groups(self._name, button_name)
if button_groups and not groups & button_groups:
states = states.copy()
states['readonly'] = True
element.set('states', encoder.encode(states))
button_name = element.attrib['name']
if button_name in self._buttons:
states = self._buttons[button_name]
else:
states = {}
groups = set(user_obj.get_groups())
button_groups = button_obj.get_groups(self._name, button_name)
if button_groups and not groups & button_groups:
states = states.copy()
states['readonly'] = True
element.set('states', encoder.encode(states))
# translate view
if Transaction().language != 'en_US':
@@ -504,3 +502,23 @@ class ModelView(Model):
% (func.__name__, self._name))
return func(self, *args, **kwargs)
return wrapper
@staticmethod
def button_action(action):
def decorator(func):
func = ModelView.button(func)
@wraps(func)
def wrapper(*args, **kwargs):
pool = Pool()
model_data_obj = pool.get('ir.model.data')
action_obj = pool.get('ir.action')
func(*args, **kwargs)
module, fs_id = action.split('.')
action_id = action_obj.get_action_id(
model_data_obj.get_id(module, fs_id))
return action_id
return wrapper
return decorator
+3 -6
View File
@@ -51,16 +51,13 @@ this repository contains the full copyright notices and license terms. -->
<label name="trigger_date"/>
<field name="trigger_date"/>
<group col="2" colspan="2" id="buttons">
<button name="send" string="Send"
type="object"/>
<button name="reply" string="Reply"
type="object"/>
<button name="send" string="Send"/>
<button name="reply" string="Reply"/>
</group>
<label name="state"/>
<field name="state"/>
<group col="3" colspan="2" id="button">
<button name="close" string="Close"
type="object"/>
<button name="close" string="Close"/>
</group>
</page>
<page string="References" col="1" id="references">