1 | ''' |
---|
2 | Created on 1 Nov 2011 |
---|
3 | |
---|
4 | @author: mnagni |
---|
5 | ''' |
---|
6 | from django.shortcuts import render_to_response |
---|
7 | from django.core.context_processors import csrf |
---|
8 | from django.utils.safestring import mark_safe |
---|
9 | from osImpl.myimpl import COLLECTION, OBSERVATION, RESULT |
---|
10 | from settings import os_engine |
---|
11 | |
---|
12 | def 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 | |
---|
17 | def _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 | |
---|
30 | def doSearchL0(request, format): |
---|
31 | #params = {'q': ['ice', 'snow']} |
---|
32 | return _doSearch(request, format) |
---|
33 | |
---|
34 | def doSearchL1(request, collection_guid, format): |
---|
35 | return _doSearch(request, format, collection_guid) |
---|
36 | |
---|
37 | def doSearchL2(request, collection_guid, observation_guid, format): |
---|
38 | return _doSearch(request, format, collection_guid, observation_guid) |
---|
39 | |
---|
40 | def doSearchL3(request, collection_guid, observation_guid, result_guid, format): |
---|
41 | return _doSearch(request, format, collection_guid, observation_guid, result_guid) |
---|
42 | |
---|
43 | def _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 | |
---|
53 | def _dispatchResponse(request, response): |
---|
54 | c = {} |
---|
55 | c['response'] = mark_safe(response) |
---|
56 | c.update(csrf(request)) |
---|
57 | return render_to_response('responseTemplate', c) |
---|