Add MachMixin
issue3867 review5271002
This commit is contained in:
1 parent
22899c33e2
commit
1abe24ce34
4 files changed
+39
-1
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Add MachMixin
|
||||
* Remove context, current_date and time from record rule evaluation
|
||||
|
||||
Version 3.2.0 - 2014-04-21
|
||||
|
||||
@@ -543,5 +543,22 @@ Instance methods:
|
||||
|
||||
Getter for the :attr:`selection_json`.
|
||||
|
||||
==========
|
||||
MatchMixin
|
||||
==========
|
||||
|
||||
.. class:: MatchMixin
|
||||
|
||||
A mixin_ to add to a :class:`Model` a match method on pattern.
|
||||
The pattern is a dictionary with field name as key and the value to compare.
|
||||
The record matches the pattern if for all dictionary entries, the value of the
|
||||
record is equal or not defined.
|
||||
|
||||
Instance methods:
|
||||
|
||||
.. method:: MatchMixin.match(pattern)
|
||||
|
||||
Return if the instance match the pattern
|
||||
|
||||
.. _mixin: http://en.wikipedia.org/wiki/Mixin
|
||||
.. _JSON: http://en.wikipedia.org/wiki/Json
|
||||
@@ -7,6 +7,7 @@ from .modelsingleton import ModelSingleton
|
||||
from .modelsql import ModelSQL
|
||||
from .workflow import Workflow
|
||||
from .dictschema import DictSchemaMixin
|
||||
from .match import MatchMixin
|
||||
|
||||
__all__ = ['Model', 'ModelView', 'ModelStorage', 'ModelSingleton', 'ModelSQL',
|
||||
'Workflow', 'DictSchemaMixin']
|
||||
'Workflow', 'DictSchemaMixin', 'MatchMixin']
|
||||
@@ -0,0 +1,19 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the toplevel of this
|
||||
# repository contains the full copyright notices and license terms.
|
||||
|
||||
|
||||
class MatchMixin(object):
|
||||
|
||||
def match(self, pattern):
|
||||
'''Match on pattern
|
||||
pattern is a dictionary with model field as key
|
||||
and matching value as value'''
|
||||
for field, pattern_value in pattern.iteritems():
|
||||
value = getattr(self, field)
|
||||
if value is None:
|
||||
continue
|
||||
if self._fields[field]._type == 'many2one':
|
||||
value = value.id
|
||||
if value != pattern_value:
|
||||
return False
|
||||
return True
|
||||
Reference in new issue
Block a user