source: mauRepo/HPFos/trunk/src/HPFos/view/view.py @ 8352

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/HPFos/trunk/src/HPFos/view/view.py@8352
Revision 8352, 2.2 KB checked in by mnagni, 9 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1'''
2Created on 1 Nov 2011
3
4@author: mnagni
5'''
6from django.shortcuts import render_to_response
7from django.core.context_processors import csrf
8from django.utils.safestring import mark_safe
9from osImpl.myimpl import COLLECTION, OBSERVATION, RESULT
10from settings import os_engine
11
12def getDescription(request, collection_guid = None, observation_guid = None, result_guid = None):
13    ospath = _buildDescriptionOsPath(collection_guid, observation_guid, result_guid)
14    response = os_engine.getDescription(ospath)
15    return _dispatchResponse(request, response)
16
17def _doSearch(request, format, collection_guid = None, observation_guid = None, result_guid = None):   
18    #params = {'q': ['ice', 'snow']}
19    params = request.GET.copy()
20    if collection_guid:
21        params[COLLECTION] = collection_guid   
22    if observation_guid:
23        params[OBSERVATION] = observation_guid       
24    if result_guid:
25        params[RESULT] = result_guid               
26   
27    response = os_engine.doSearch(format, params_values = params, moles3EPB = request.moles3EPB)
28    return _dispatchResponse(request, response)
29
30def doSearchL0(request, format):
31    #params = {'q': ['ice', 'snow']}
32    return _doSearch(request, format)
33
34def doSearchL1(request, collection_guid, format):
35    return _doSearch(request, format, collection_guid)
36
37def doSearchL2(request, collection_guid, observation_guid, format):
38    return _doSearch(request, format, collection_guid, observation_guid)
39
40def doSearchL3(request, collection_guid, observation_guid, result_guid, format):
41    return _doSearch(request, format, collection_guid, observation_guid, result_guid)   
42
43def _buildDescriptionOsPath(collection_guid = None, observation_guid = None, result_guid = None):
44    ospath = "%s/search/" % (os_engine.ospath)
45    if collection_guid:
46        ospath = "%s%s/" % (ospath, collection_guid)
47    if observation_guid:
48        ospath = "%s%s/" % (ospath, observation_guid)
49    if result_guid:
50        ospath = "%s%s/" % (ospath, result_guid)
51    return ospath       
52       
53def _dispatchResponse(request, response):
54    c = {}
55    c['response'] = mark_safe(response)
56    c.update(csrf(request))
57    return render_to_response('responseTemplate', c)   
Note: See TracBrowser for help on using the repository browser.