summaryrefslogtreecommitdiffstats
path: root/pykolab/xml/contact_reference.py
blob: 5a832dacbec291b923a7567f5f2cdd14af12f83d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import kolabformat

"""
    def __eq__(self, *args): return _kolabformat.ContactReference___eq__(self, *args)
    def isValid(self): return _kolabformat.ContactReference_isValid(self)
    def setName(self, *args): return _kolabformat.ContactReference_setName(self, *args)
    def email(self): return _kolabformat.ContactReference_email(self)
    def uid(self): return _kolabformat.ContactReference_uid(self)
    def name(self): return _kolabformat.ContactReference_name(self)
    def type(self): return _kolabformat.ContactReference_type(self)
"""

class ContactReference(kolabformat.ContactReference):
    properties_map = {
        'email': 'email',
        'name':  'name',
        'type':  'type',
        'uid':   'uid',
    }

    def __init__(self, email=None):
        if email == None:
            kolabformat.ContactReference.__init__(self)
        elif isinstance(email, kolabformat.ContactReference):
            kolabformat.ContactReference.__init__(self, email.email(), email.name(), email.uid())
        else:
            kolabformat.ContactReference.__init__(self, email)

    def get_email(self):
        return self.email()

    def get_name(self):
        return self.name()

    def set_cn(self, value):
        self.setName(value)

    def set_email(self, email):
        kolabformat.ContactReference.__init__(self, email)

    def set_name(self, name):
        self.setName(name)

    def to_dict(self):
        data = dict()

        for p, getter in self.properties_map.iteritems():
            val = None
            if hasattr(self, getter):
                val = getattr(self, getter)()
            if val is not None:
                data[p] = val

        return data