Improve get_attribute() so that it can search on related assets.

This commit is contained in:
Albert Cervera i Areny 2014-11-01 16:42:51 +01:00
parent 1814d6a8a6
commit c65ad5d29f
3 changed files with 35 additions and 9 deletions

View File

@ -3,11 +3,6 @@
from trytond.pool import Pool
from .monitoring import *
__all__ = ['CheckType', 'ResultType', 'StateType', 'StateIndicator',
'StateIndicatorLine', 'Scheduler', 'CheckPlan', 'IndicatorCheckPlan',
'Check', 'State', 'ResultInteger', 'ResultFloat', 'ResultChar',
'AssetPartyNotification', 'Asset', 'Party']
def register():
Pool.register(
CheckType,
@ -27,4 +22,5 @@ def register():
Asset,
StateTypeParty,
Party,
RelationType,
module='monitoring', type_='model')

View File

@ -13,7 +13,8 @@ from trytond.pyson import Eval
__all__ = ['CheckType', 'ResultType', 'StateType', 'StateIndicator',
'StateIndicatorLine', 'Scheduler', 'CheckPlan', 'StateIndicatorCheckPlan',
'Check', 'State', 'ResultInteger', 'ResultFloat', 'ResultChar',
'AssetPartyNotification', 'Asset', 'StateTypeParty', 'Party']
'AssetPartyNotification', 'Asset', 'StateTypeParty', 'Party',
'RelationType']
__metaclass__ = PoolMeta
@ -381,14 +382,26 @@ class Asset:
notification_parties = fields.Many2Many('asset-party.party-notification',
'asset', 'party', 'Notification Parties')
def get_attribute(self, name):
def get_attribute(self, name, browsed=None):
"""
Returns the value of the given attribute.
Other modules may want to implement their own way of searching for a
given attribute, for example by considering related items.
"""
return self.attributes.get(name) if self.attributes else None
if self.attributes and name in self.attributes:
return self.attributes[name]
if browsed is None:
browsed = set()
browsed.add(self)
for relation in self.relations:
if relation.to in browsed:
continue
if relation.type.search_attributes:
value = relation.to.get_attribute(name)
if value is not None:
return value
return None
def get_states(self, name):
IndicatorPlan = Pool().get(
@ -406,12 +419,16 @@ class StateTypeParty(ModelSQL):
class Party:
__name__ = 'party.party'
# TODO: Add calculated One2Many that shows all indicators in its current state.
notification_assets = fields.Many2Many('asset-party.party-notification',
'party', 'asset', 'Notification Assets')
notification_types = fields.Many2Many('monitoring.state.type-party.party',
'party', 'type', 'Types')
# TODO: Add calculated One2Many that shows all indicators in its current state.
class RelationType:
__name__ = 'asset.relation.type'
search_attributes = fields.Boolean('Search Attributes')
# Zabbix structure:

View File

@ -576,6 +576,19 @@
<field name="name">asset_form</field>
</record>
<record model="ir.ui.view" id="asset_relation_type_view_form">
<field name="model">asset.relation.type</field>
<field name="type">form</field>
<field name="inherit" ref="asset_relationship.asset_relation_type_view_form"/>
<field name="name">relation_type_form</field>
</record>
<record model="ir.ui.view" id="asset_relation_type_view_list">
<field name="model">asset.relation.type</field>
<field name="type">tree</field>
<field name="inherit" ref="asset_relationship.asset_relation_type_view_list"/>
<field name="name">relation_type_list</field>
</record>
<record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field>
<field name="type">form</field>