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

View | Annotate | Download (3 KB)

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