root / lib / pyzinn / erp / IpartyContactMechanism.py @ a899390a2a8aca3b3b4617dd7cd96a19e64b489c

View | Annotate | Download (3 KB)

1
# Copyright (c) 2009 Lost Oasis, IELO <info@ielo.net>
2
#
3
# This file is part of ZINN.
4
# 
5
# SINN is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your
8
# option) any later version.
9
# 
10
# SINN is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for more details.
14
# 
15
# You should have received a copy of the GNU General Public License
16
# along with ZINN.  If not, see <http://www.gnu.org/licenses/>.
17
18
"""
19
    Common interface that erp party contact mechanism (client contact mechanism) plugins must implement
20
"""
21
22
class IpartyContactMechanism(object):
23
    fields = [
24
            'id',
25
            'type',
26
            'value',
27
            #'comment'
28
            ]
29
30
    types = [
31
            'phone',
32
            'mobile',
33
            'fax',
34
            'email',
35
            'sip',
36
            'skype',
37
            'website'
38
            ]
39
40
    def __init__(self, transport):
41
        pass
42
43
    def list(self, partyLabel, contactType=None):
44
        '''
45
        Get an address by its label
46
47
        :param label : a string, address label
48
        '''
49
        raise NotImplementedError
50
51
    def create(self, client, label, attributes):
52
        '''
53
        Create an address
54
55
        :param client : a string client label
56
        :param label : a string address label
57
        :param attributes : a dictionary with fields names as key
58
                        and created values as value
59
        '''
60
        raise NotImplementedError
61
62
    def update(self, client, label, attributes):
63
        '''
64
        Update an address
65
66
        :param client : a string client label
67
        :param label : a string address label
68
        :param attributes : a dictionary with fields names as key
69
                        and created values as value
70
        '''
71
        raise NotImplementedError
72
73
    def delete(self, client, label):
74
        '''
75
        Update an address
76
77
        :param client : a string client label
78
        :param label : a string address label
79
        '''
80
        raise NotImplementedError
81
82
    def attributes(self, onlyMutables=True):
83
        raise NotImplementedError
84
85
    def getAttributes(self, onlyMutables=False):
86
        """
87
        @param onlyMutables: bool (optionnal) filters unmutable attributes.
88
        """
89
        if onlyMutables:
90
            return [a for a in self.getAttributes() if a not in ()]
91
        else:
92
            return [a for a in self.fields if a not in ('id')]
93
94
    def AttributesFilter(self, attributes, default=None):
95
        mutables = self.getAttributes(onlyMutables=True)
96
        args = default if isinstance(default, dict) else {}
97
        if isinstance(attributes, dict):
98
            for k, v in attributes.iteritems():
99
                if k in mutables:
100
                    args[k] = v
101
        return args