- Timestamp:
- 18/10/12 17:21:55 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/HPFos/trunk/hpfos/HPFos/osImpl/myimpl.py
r8638 r8640 49 49 from ceda_markup.opensearch.template.atom import OSAtomResponse 50 50 from ceda_markup.opensearch.template.html import OSHTMLResponse 51 from sqlalchemy.orm.collections import InstrumentedList 51 52 from ea_model.iso_19108_2006_temporal_schema.temporal_objects.tm_instant \ 52 53 import TM_Instant … … 106 107 ''' 107 108 108 def _digest_fatcat_atom (self, context, results):109 def _digest_fatcat_atom_(self, context, results): 109 110 count, start_index, start_page = self._importCountAndPage(context) 110 111 entries = results.findall('{%s}entry' % (ATOM_NAMESPACE)) … … 148 149 subresult = subresults, title=HPFOS_TITLE) 149 150 151 def _digest_fatcat_atom(self, context, results): 152 entries = results.findall('{%s}entry' % (ATOM_NAMESPACE)) 153 subresults = [] 154 for entry in entries: 155 iid = entry.find('{%s}id' % (ATOM_NAMESPACE)).text.strip() 156 ititle = entry.find('{%s}title' % (ATOM_NAMESPACE)).text.strip() 157 kwargs = {} 158 159 element = entry.find('.//{%s}beginPosition' % (GML_NAMESPACE)) 160 if element is not None: 161 kwargs['beginPosition'] = element.text.strip() 162 element = None 163 164 element = entry.find('.//{%s}endPosition' % (GML_NAMESPACE)) 165 if element is not None: 166 kwargs['endPosition'] = element.text.strip() 167 element = None 168 169 geometry = entry.find('.//{%s}posList' % (GML_NAMESPACE)) 170 if geometry is not None: 171 kwargs['geometry'] = 'POLYGON((%s))' % geometry.text.strip() 172 else: 173 geometry = entry.find('.//{%s}Envelope' % (GML_NAMESPACE)) 174 if geometry is not None: 175 lc = geometry.find('./{%s}lowerCorner' % (GML_NAMESPACE)).text.strip() 176 uc = geometry.find('./{%s}upperCorner' % (GML_NAMESPACE)).text.strip() 177 kwargs['geometry'] = _create_box2d(lc, uc) 178 179 180 kwargs['enclosure'] = entry.findall("./{%s}link" % (ATOM_NAMESPACE)) 181 #This can be activated on python >= 2.7 182 #kwargs['enclosure'] = entry.findall("./{%s}link[@rel='enclosure']" % (ATOM_NAMESPACE)) 183 kwargs['description'] = 'no description' 184 subresults.append(Subresult(iid, ititle, 185 datetime.now().isoformat(), **kwargs)) 186 187 return subresults 188 189 ''' 190 tot_results = int(results.find('{%s}totalResults' 191 % (OS_NAMESPACE)).text.replace('\n','').strip()) 192 193 return Result(count, start_index, start_page, tot_results, 194 subresult = subresults, title=HPFOS_TITLE) 195 ''' 196 150 197 def _check_text_filter(self, text, title, description): 151 198 words = text.split() … … 228 275 return subresults 229 276 230 def digest_search_results (self, results, context):277 def digest_search_results_(self, results, context): 231 278 if type(results) == CEDA_ObservationCollection: 232 279 results = results.member 233 280 elif isinstance(results, _ElementInterface): 234 return self._digest_fatcat_atom (context, results)281 return self._digest_fatcat_atom_(context, results) 235 282 236 283 count, start_index, start_page = self._importCountAndPage(context) … … 250 297 pass 251 298 299 return Result(count, start_index, start_page, tot_results, \ 300 subresult = subresults, title=HPFOS_TITLE) 301 302 def digest_search_results(self, results, context): 303 instances = None 304 tot_results = 0 305 if type(results) == CEDA_ObservationCollection: 306 instances = results.member 307 elif type(results) == tuple: 308 ids = [id[0] for id in results[1]] 309 instances = context['moles3EPB'].get_instance_by_ids(ids) 310 try: 311 tot_results = len(instances) 312 except: 313 pass 314 elif isinstance(results, _ElementInterface): 315 instances = self._digest_fatcat_atom(context, results) 316 tot_results = int(results.find('{%s}totalResults' 317 % (OS_NAMESPACE)).text.replace('\n','').strip()) 318 319 count, start_index, start_page = self._importCountAndPage(context) 320 subresults = filter_results(instances, count, start_index, start_page) 321 322 if (type(instances) == list \ 323 and type(instances[0]) == CEDA_ObservationCollection) \ 324 or (type(instances) == InstrumentedList \ 325 and type(instances[0]) == CEDA_Observation): 326 subresults = self.apply_query_params(context, subresults) 327 252 328 return Result(count, start_index, start_page, tot_results, \ 253 329 subresult = subresults, title=HPFOS_TITLE)
Note: See TracChangeset
for help on using the changeset viewer.