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