1
2
3 __doc__ == """
4 A workspace is a conceptual container holding a set of collections.
5 The organization brought by workspaces is mainly for clarity.
6 Consider workspaces being a drawer and collections folders inside.
7 """
8
9 from bridge import Element, Attribute
10 from bridge.common import ATOM10_PREFIX, ATOMPUB_PREFIX, \
11 ATOM10_NS, ATOMPUB_NS
12
14 - def __init__(self, service, name_or_id, title):
15 """
16 APP workspace entity
17
18 A workspace is a
19
20 Keyword arguments:
21 service -- the amplee.atompub.service.AtomPubService instance holding
22 this workspace instance
23 name_or_id -- reference to the workspace
24 title -- human readable label of this workspace
25 """
26 self.service = service
27 self.name_or_id = name_or_id
28 self.title = title
29 self.service.workspaces.append(self)
30
31
32 self.collections = []
33
34 - def to_workspace(self, prefix=ATOMPUB_PREFIX, namespace=ATOMPUB_NS):
35 """
36 Generates and returns a bridge.Element instance of the workspace
37 document and its collections.
38
39 The first collection shown will be the one having the 'favorite'
40 attribute set to True.
41
42 Keyword arguments:
43 prefix -- XML prefix to use (default:%s)
44 namespace -- Namespace associated with the workspace document
45 (default:%s)
46
47 """ % (ATOMPUB_PREFIX, ATOMPUB_NS)
48 workspace = Element(u'workspace', prefix=prefix, namespace=namespace)
49 workspace.collection = []
50 Element(u'title', content=self.title, attributes={u'type': u'text'},
51 prefix=ATOM10_PREFIX, namespace=ATOM10_NS, parent=workspace)
52
53 for collection in self.collections:
54 ct = collection.collection
55 ct.parent = workspace
56 if collection.favorite:
57 workspace.xml_children.insert(0, ct)
58 workspace.collection.insert(0, ct)
59 else:
60 workspace.xml_children.append(ct)
61 workspace.collection.append(ct)
62
63 return workspace
64 workspace = property(to_workspace)
65