1 | from htmlUtilities import * |
---|
2 | class renderEntity: |
---|
3 | |
---|
4 | def __init__(self,config=None): |
---|
5 | self.config=config |
---|
6 | |
---|
7 | def render(self,entity): |
---|
8 | ''' Take an NDG metadata entity (D or B) and render to HTML on a standard pattern, |
---|
9 | depends on all entities having the same attributes ''' |
---|
10 | |
---|
11 | #this is NOT supposed to be the whole page ... |
---|
12 | |
---|
13 | #need to start by building the coverage information html |
---|
14 | #follow by building the contact information |
---|
15 | #then get the related datasets (if available) |
---|
16 | |
---|
17 | if entity is None: return '' |
---|
18 | |
---|
19 | #try: |
---|
20 | |
---|
21 | #except: |
---|
22 | # contentHTML='' |
---|
23 | |
---|
24 | if entity.metadataType is 'stubB': |
---|
25 | relatedHTML=renderRelated(entity) |
---|
26 | else: |
---|
27 | relatedHTML='' |
---|
28 | |
---|
29 | if entity.type=='dgDataEntity': |
---|
30 | contentHTML=renderDataContent(entity) |
---|
31 | relatedHTML=renderGranules(entity)+relatedHTML |
---|
32 | elif entity.type=='DIF': |
---|
33 | contentHTML=renderDataContent(entity) |
---|
34 | relatedHTML=renderDataLinks(entity)+relatedHTML |
---|
35 | else: |
---|
36 | contentHTML='' |
---|
37 | |
---|
38 | #try: |
---|
39 | xicon=hyperlink(image(self.config.get('layout','Xicon'),'[X]'),entity.binding.url+'&xml') |
---|
40 | #except: |
---|
41 | # xicon='' |
---|
42 | |
---|
43 | html=''' |
---|
44 | <DIV id="EntityContent"> |
---|
45 | <p></p> |
---|
46 | <h5>%s%s</h5> |
---|
47 | <DIV id="Abstract"> |
---|
48 | <p>%s</p> |
---|
49 | </DIV> |
---|
50 | <p><br/></p> |
---|
51 | %s |
---|
52 | %s |
---|
53 | </DIV>'''%(entity.name,xicon,entity.abstract,contentHTML,relatedHTML) |
---|
54 | return html |
---|
55 | |
---|
56 | def renderDataContent(entity): |
---|
57 | '''Parse a data entity for content information ''' |
---|
58 | |
---|
59 | html='' |
---|
60 | try: |
---|
61 | if entity.constraints.exists: |
---|
62 | html='<p>Access Control: %s</p>'%entity.constraints.html |
---|
63 | except: pass |
---|
64 | |
---|
65 | html+=''' |
---|
66 | <table cellspacing="0" cellpadding="3" width="90%" border="0"> |
---|
67 | <tbody> |
---|
68 | <tr> |
---|
69 | <td class="lineHead" width="40%"><b>Field</b></td> |
---|
70 | <td class="lineHead" width="60%"><b>Description</b></td> |
---|
71 | </tr>''' |
---|
72 | |
---|
73 | |
---|
74 | try: |
---|
75 | #currently all entities are parsed for these ... |
---|
76 | for item in entity.parameters: |
---|
77 | html+=''' |
---|
78 | <tr><td class="line"><b>Parameter</b><br/></td> |
---|
79 | <td class="line">%s</td></tr>'''%item |
---|
80 | |
---|
81 | html+=''' |
---|
82 | <tr><td class="line"><b>Spatial Coverage</b><br/></td> |
---|
83 | <td class="line">%s</td></tr>'''%entity.bbox.toHTML() |
---|
84 | |
---|
85 | html+=''' |
---|
86 | <tr><td class="line"><b>Temporal Coverage</b><br/></td> |
---|
87 | <td class="line">%s</td></tr>'''%entity.timeCoverage |
---|
88 | |
---|
89 | except: pass |
---|
90 | |
---|
91 | html+=''' |
---|
92 | <tr><td class="line"><b>Data Curator</b><br/></td> |
---|
93 | <td class="line">%s</td></tr>'''%entity.curator.toHTML() |
---|
94 | |
---|
95 | for c in entity.creators: |
---|
96 | html+=''' |
---|
97 | <tr><td class="line"><b>Data Creator</b><br/></td> |
---|
98 | <td class="line">%s</td></tr>'''%c.toHTML() |
---|
99 | |
---|
100 | html+='</tbody></table>' |
---|
101 | |
---|
102 | return html |
---|
103 | # |
---|
104 | # Following classes specific to stub-B |
---|
105 | # |
---|
106 | def renderGranules(entity): |
---|
107 | ''' Render information about data granules within a data entity ''' |
---|
108 | if len(entity.granules): |
---|
109 | html='''<p><br/></p> |
---|
110 | <table cellspacing="0" cellpadding="3" width="90%" border="0"> |
---|
111 | <tbody> |
---|
112 | <tr><td class="lineHead" colspan="3"> |
---|
113 | <span class="headingO">Data Granules</span></td></tr> |
---|
114 | <tr class="lineHiLite"> |
---|
115 | <td width="30%" colspan="2">Accessability</td><td>Link</td></tr>''' |
---|
116 | for g in entity.granules: |
---|
117 | html+='<tr>' |
---|
118 | if g.constraints.exist: |
---|
119 | html+='<td width="20px" class="key"></td><td>%s</td>'%g.constraints.html |
---|
120 | else: |
---|
121 | html+='<td>public</td><td></td>' |
---|
122 | html+='<td>%s</td></tr>'%g.binding |
---|
123 | html+='</tbody></table>' |
---|
124 | return html |
---|
125 | else: return '' |
---|
126 | |
---|
127 | def renderDataLinks(entity): |
---|
128 | return 'some data link stuff' |
---|
129 | |
---|
130 | def renderRelated(entity): |
---|
131 | ''' take a stub-b and create html for the related entities ''' |
---|
132 | if entity.related!=[]: |
---|
133 | html='''<p><br/></p> |
---|
134 | <table cellspacing="0" cellpadding="3" width="90%" border="0"> |
---|
135 | <tbody> |
---|
136 | <tr> |
---|
137 | <td class="lineHead" colspan="2"><span class="headingO">Related Entities</span></td> |
---|
138 | </tr>''' |
---|
139 | |
---|
140 | for deployment in entity.related: |
---|
141 | #really ought to have a row for the deployment name .... |
---|
142 | for instance in deployment[1]: |
---|
143 | label=instance[0] |
---|
144 | for link in instance[1]: |
---|
145 | html+='<tr><td width="40%%"><b>%s</b></td><td width="60%%">%s</td></tr>'%(label,link) |
---|
146 | html+='</tbody></table>' |
---|
147 | else: |
---|
148 | html='' |
---|
149 | return html |
---|
150 | |
---|
151 | if __name__=="__main__": |
---|
152 | from stubB import stubB |
---|
153 | xml=open('../../exampleB/methyl.example.xml').read() |
---|
154 | renderer=renderEntity('browse.config') |
---|
155 | x=stubB(xml,makeHTML=renderer,serviceFile='serviceMap.config') |
---|
156 | html=x.toHTML() |
---|
157 | f=open('output.html','w') |
---|
158 | f.write(html) |
---|
159 | |
---|
160 | |
---|
161 | |
---|