Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Commit fad6406

Browse files
committed
IR-80: Serialize subressorts with ressorts
1 parent 2ec70a2 commit fad6406

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/zeit/cms/content/browser/sources.py

+26
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,29 @@ class SerializeObjectSource(SerializeContextualSource):
7575

7676
def getId(self, value):
7777
return self.context.getToken(None, value)
78+
79+
80+
class SerializeRessortSource(SerializeContextualSource):
81+
82+
grok.context(zeit.cms.content.sources.RessortSource)
83+
84+
def __call__(self):
85+
# XXX 90% copy&paste from zeit.web.core.view_json.c1_channeltree()
86+
result = []
87+
for ressort in self.context._get_tree().xpath('/ressorts/ressort'):
88+
item = {
89+
'id': ressort.get('name').lower(),
90+
'title': ressort.find('title').text
91+
}
92+
result.append(item)
93+
94+
children = []
95+
for sub in ressort.xpath('subnavigation'):
96+
subitem = {
97+
'id': sub.get('name').lower(),
98+
'title': sub.find('title').text
99+
}
100+
children.append(subitem)
101+
if children:
102+
item['children'] = children
103+
return result

src/zeit/cms/content/browser/tests/test_sources.py

+11
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,14 @@ def test_allows_configuring_short_names(self):
5555
b.open('http://localhost/@@source?name=product')
5656
data = json.loads(b.contents)
5757
self.assertIn({'id': 'ZEDE', 'title': 'Zeit Online'}, data)
58+
59+
def test_serializes_subressorts(self):
60+
b = self.browser
61+
b.open('http://localhost/@@source'
62+
'?name=zeit.cms.content.sources.RessortSource')
63+
data = json.loads(b.contents)
64+
row = data[0]
65+
self.assertEqual('deutschland', row['id'])
66+
self.assertEqual('Deutschland', row['title'])
67+
self.assertEqual(4, len(row['children']))
68+
self.assertEqual('integration', row['children'][0]['id'])

0 commit comments

Comments
 (0)