1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 AttributeBase class for GRAMPS.
25 """
26
27
28
29
30
31
32 from gen.lib.attribute import Attribute
33
34
35
36
37
38
40 """
41 Base class for attribute-aware objects.
42 """
43
45 """
46 Initialize a AttributeBase.
47
48 If the source is not None, then object is initialized from values of
49 the source object.
50
51 @param source: Object used to initialize the new object
52 @type source: AttributeBase
53 """
54 if source:
55 self.attribute_list = [ Attribute(attribute) \
56 for attribute in source.attribute_list ]
57 else:
58 self.attribute_list = []
59
61 """
62 Convert the object to a serialized tuple of data.
63 """
64 return [attr.serialize() for attr in self.attribute_list]
65
67 """
68 Convert a serialized tuple of data to an object.
69 """
70 self.attribute_list = [Attribute().unserialize(item) for item in data]
71
73 """
74 Add the L{Attribute} instance to the object's list of attributes.
75
76 @param attribute: L{Attribute} instance to add.
77 @type attribute: L{Attribute}
78 """
79 assert type(attribute) != unicode
80 self.attribute_list.append(attribute)
81
83 """
84 Remove the specified L{Attribute} instance from the attribute list.
85
86 If the instance does not exist in the list, the operation has
87 no effect.
88
89 @param attribute: L{Attribute} instance to remove from the list
90 @type attribute: L{Attribute}
91
92 @return: True if the attribute was removed, False if it was not
93 in the list.
94 @rtype: bool
95 """
96 if attribute in self.attribute_list:
97 self.attribute_list.remove(attribute)
98 return True
99 else:
100 return False
101
103 """
104 Return the list of L{Attribute} instances associated with the object.
105
106 @returns: Returns the list of L{Attribute} instances.
107 @rtype: list
108 """
109 return self.attribute_list
110
112 """
113 Assign the passed list to the Person's list of L{Attribute} instances.
114
115 @param attribute_list: List of L{Attribute} instances to ba associated
116 with the Person
117 @type attribute_list: list
118 """
119 self.attribute_list = attribute_list
120