This repository was archived by the owner on Mar 22, 2022. It is now read-only.
Commit fad6406 1 parent 2ec70a2 commit fad6406 Copy full SHA for fad6406
File tree 2 files changed +37
-0
lines changed
src/zeit/cms/content/browser
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -75,3 +75,29 @@ class SerializeObjectSource(SerializeContextualSource):
75
75
76
76
def getId (self , value ):
77
77
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
Original file line number Diff line number Diff line change @@ -55,3 +55,14 @@ def test_allows_configuring_short_names(self):
55
55
b .open ('http://localhost/@@source?name=product' )
56
56
data = json .loads (b .contents )
57
57
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' ])
You can’t perform that action at this time.
0 commit comments