source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/NSfunctions10.kid @ 2982

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/NSfunctions10.kid@2982
Revision 2982, 7.8 KB checked in by lawrence, 12 years ago (diff)

Support for viewing NumSim experiment documents

Line 
1<!-- This is a bunch of named templates for use in NumSim construction -->
2<?python
3 def et2s(x):
4     #use this to strip namespaces for children within text elements
5     cb=x.tag.find('}')
6     if cb!=-1:x.tag=x.tag[cb+1:]
7     txt=(x.text or '')
8     s='<%s>%s'%(x.tag,txt)
9     for a in x:
10         s+=et2s(a)
11     s+='</%s>%s'%(x.tag,(x.tail or ''))
12     return s
13     ?>
14<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#">
15
16    <span py:def="Text(elem)">
17        <!-- Note that we have to expect the possibility of xhtml in these elements and we won't
18        want the parent attributes, or the namespaces -->
19        ${elem.text or ''}
20        <?python
21        s=''
22        for a in elem:s+=et2s(a)
23        ?>
24        ${XML(s)}
25    </span>
26       
27    <div py:def="Description(elem,nsfix)">
28        <span py:if="elem is not None">
29            <?python
30            related=(elem.findall(nsfix('relatedTo')) or [])
31            content=elem.find(nsfix('contents'))
32            keywords=(elem.findall(nsfix('keywords')) or [])
33            cb=elem.tag.find('}')
34            ?>
35            <span py:if="content is not None">${elem.tag[cb+1:]}: <span py:replace="Text(content)"/></span>
36            <span py:for="k in keywords">${k.text}(${k.find(nsfix('dictionary')).text})</span>
37            <ul py:if="related!=[]">
38                <li py:for="uri in related"><div py:replace="RelatedTo(uri)"/></li>
39            </ul>
40        </span>
41    </div>
42   
43    <div py:def="References(elem,nsfix)">
44        <div py:if="elem is not None" class="RefList">
45            <?python
46                refs=(elem.findall(nsfix('reference')) or [])
47                refList,linkList=[],[]
48                for r in refs:
49                    href=r.attrib.get('{http://www.w3.org/1999/xlink}href')
50                    title=r.attrib.get('{http://www.w3.org/1999/xlink}title')
51                    #note that the attribs are compulsory, although they may be empty, but
52                    #we can't rely on that :-)
53                    l={'href':(href or ''),'title':(title or '')}
54                    if l['href']=='' and l['title']=='': l={}
55                    r.attrib={}
56                    b=('','')
57                    if r.text is not None and l!={}: b=('(',')')
58                    refList.append((r,l,b))
59            ?>
60            References:
61            <ul>
62                <li py:for="r in refList"><span py:replace="Text(r[0])"/>${r[2][0]}<a py:if="r[1]!={}" href="${r[1]['href']}">${r[1]['title']}</a>${r[2][1]}</li>
63            </ul>
64        </div>
65    </div>
66   
67    <div py:def="Parameters(elem,nsfix)">
68        <div py:if="elem is not None">
69            <ul>
70                <li py:for="i in elem.findall(nsfix('NS_RelatedURI'))"><span py:replace="Text(i)"/></li>
71            </ul>
72        </div>
73    </div>
74   
75    <div py:def="RelatedTo(elem,nsfix)">
76        <div py:if="elem is not None">
77            <?python
78            href=elem.attrib.get('{http://www.w3.org/1999/xlink}href')
79            title=elem.attrib.get('{http://www.w3.org/1999/xlink}title')
80            rel=elem.find(nsfix('description'))
81            if rel is not None:
82                s=(rel.text or '')
83            else:
84                #if there is no description, then these must exist
85                r=[i.text for i in elem.findall(nsfix('relationship'))]
86                s=','.join(r)
87            ?>
88            $s <a href="$href">$title</a>
89        </div>
90    </div>
91   
92    <div py:def="Condition(i,nsfix)">
93        <?python
94        ty=i.attrib.get('{http://ndg.nerc.ac.uk/numsim}type')
95        pe=i.attrib.get('{http://ndg.nerc.ac.uk/numsim}perturbed')
96        if ty is None: ty=''
97        if pe is None: pe=''
98        tag=i.tag[i.tag.find('}')+1:]
99        ?>
100        <p class="emphatic"> $tag $ty $pe </p>
101        <div py:replace="Description(i.find(nsfix('description')),nsfix)"/>
102        <div py:replace="References(i.find(nsfix('references')),nsfix)"/>
103        <div py:replace="Parameters(i.find(nsfix('controlledParameters')),nsfix)"/>
104        <div py:replace="RelatedTo(i.find(nsfix('boundaryDataset')),nsfix)"/>
105    </div>
106   
107    <div py:def="Ensemble(i,nsfix)">
108        <?python
109        s=i.attrib.get('{http://ndg.nerc.ac.uk/numsim}ensembleStatistics')
110        d=i.find(nsfix('description'))
111        et=(i.findall(nsfix('ensembleType')) or [])
112        ets=','.join(ets)
113        ?>
114        <tr><td>Ensemble $(if s: 'Average'}. Type:${ets}</td></tr>
115        <tr py:if="d"><td><div  py:replace="Description(d,nsfix)"/></td></tr>
116    </div>
117   
118    <div py:def="Model(elem,nsfix)" class="Model">
119        <table py:if="elem is not None" cellspacing="0" cellpadding="3" border="0"><tbody>
120            <?python
121            categoryList=[(i.text or '') for i in elem.findall(nsfix('category'))]
122            compTypeList=[(i.text or '') for i in elem.findall(nsfix('componentType'))]
123            descriptions=(elem.findall(nsfix('description')) or [])
124            refs=elem.find(nsfix('references'))
125            related=(elem.findall(nsfix('relatedModel')) or [])
126            resolution=elem.find(nsfix('resolution'))
127            components=(elem.findall(nsfix('component')) or [])
128            ?>
129            <tr><td class="linehead" colspan="3"><span class="headingO">
130                <span py:replace="Text(elem.find(nsfix('name')))"/></span></td></tr>
131            <tr py:if="categoryList!=[]"><td>category:${','.join(categoryList)}</td></tr>
132            <tr py:if="compTypeList!=[]"><td>type:${','.join(compTypeList)}</td></tr>
133            <tr py:for="d in descriptions"><td><div py:replace="Description(d,nsfix)"/></td></tr>
134            <tr py:if="resolution!=None"><td><div py:replace="Description(resolution,nsfix)"/></td></tr>
135            <tr py:for="r in related"><td><div py:replace="RelatedTo(r,nsfix)"/></td></tr>
136            <tr py:if="refs is not None"><td><div py:replace="References(refs,nsfix)"/></td></tr>
137            <tr py:for="cmp in components"><td><div py:replace="Model(cmp,nsfix)"/></td></tr>
138        </tbody></table>
139    </div>
140   
141    <div py:def="Experiment(elem,nsfix)" class="Model">
142        <table py:if="elem is not None" cellspacing="0" cellpadding="3" border="0">
143            <?python
144            baseModel=elem.find(nsfix('baseModel'))
145            descriptions=(elem.findall(nsfix('description')) or [])
146            refs=elem.find(nsfix('references'))
147            ics=(elem.findall(nsfix('initialCondition')) or [])
148            bcs=(elem.findall(nsfix('boundaryCondition')) or [])
149            parent=elem.find(nsfix('parentEnsemble'))
150            ?>
151            <tbody><tr><td class="linehead" colspan="3"><span class="headingO">
152                <span py:replace="Text(elem.find(nsfix('name')))"/></span></td></tr>
153                <tr py:if="baseModel"><td><div py:replace="Description(baseModel,nsfix)"/></td></tr>
154                 <tr py:for="d in descriptions"><td><div py:replace="Description(d,nsfix)"/></td></tr>
155                 <tr py:if="refs"><td><div py:replace="References(refs,nsfix)"/></td></tr>
156                 <tr py:for="i in ics"><td><div py:replace="Condition(i,nsfix)"/></td></tr>
157                 <tr py:for="i in bcs"><td><div py:replace="Condition(i,nsfix)"/></td></tr>
158                 <tr py:if="parent"><td><div py:replace="RelatedTo(parent,nsfix)"/></td></tr>
159            </tbody>
160        </table>
161   </div>
162   
163    <div py:def="simulationContent(xmlh)">
164        <div py:if="xmlh.tree[0].tag=='{http://ndg.nerc.ac.uk/numsim}model'"
165             py:replace="Model(xmlh.tree[0],xmlh._distributens)"/>
166        <div py:if="xmlh.tree[0].tag=='{http://ndg.nerc.ac.uk/numsim}experiment'"
167             py:replace="Experiment(xmlh.tree[0],xmlh._distributens)"/>
168        <?python dc=(xmlh.tree.findall('{http://purl.org/dc/elements/1.1/dc}*') or [])?>
169        <table py:if="dc !=[]"><tr py:for="e in dc">
170            <td>${e.tag}</td><td>${e.text}</td></tr>
171        </table>-->
172    </div>
173
174</html>
Note: See TracBrowser for help on using the repository browser.