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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/HPFos/trunk/src/HPFos/view/view.py@8355
Revision 8355, 4.2 KB checked in by mnagni, 9 years ago (diff)

retrieve the hostURL from the request
minimal home page

  • Property svn:mime-type set to text/plain
Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 1 Nov 2011
30
31@author: Maurizio Nagni
32'''
33from django.shortcuts import render_to_response
34from django.core.context_processors import csrf
35from django.utils.safestring import mark_safe
36from HPFos.settings import os_engine
37from HPFos.osImpl.myimpl import COLLECTION, OBSERVATION, RESULT
38
39hostURL = 'http://localhost:8000'
40
41def _buildHostURL(request):
42    if request.is_secure():
43        return 'https://%s' % (request.get_host())
44    else:
45        return 'http://%s' % (request.get_host())
46
47def getHome(request):
48    context = {}
49    context['hostURL'] = _buildHostURL(request)
50    return _dispatchResponse(request, 'homeTemplate', context)
51
52def getDescription(request, collection_guid = None, observation_guid = None, result_guid = None):
53    ospath = _buildDescriptionOsPath(collection_guid, observation_guid, result_guid)
54    response = os_engine.getDescription(ospath)
55    context = {}
56    context['response'] = mark_safe(response)
57    return _dispatchResponse(request, 'responseTemplate', context)
58
59def _doSearch(request, iformat, collection_guid = None, observation_guid = None, result_guid = None):
60    host = _buildHostURL(request)   
61    #params = {'q': ['ice', 'snow']}
62    params = request.GET.copy()
63    if collection_guid:
64        params[COLLECTION] = collection_guid   
65    if observation_guid:
66        params[OBSERVATION] = observation_guid       
67    if result_guid:
68        params[RESULT] = result_guid               
69   
70    response = os_engine.doSearch(hostURL, iformat, params_values = params, moles3EPB = request.moles3EPB)
71    context = {}
72    context['response'] = mark_safe(response)
73    return _dispatchResponse(request, 'responseTemplate', context)
74
75def doSearchL0(request, iformat):
76    return _doSearch(request, iformat)
77
78def doSearchL1(request, collection_guid, iformat):
79    return _doSearch(request, iformat, collection_guid)
80
81def doSearchL2(request, collection_guid, observation_guid, iformat):
82    return _doSearch(request, iformat, collection_guid, observation_guid)
83
84def doSearchL3(request, collection_guid, observation_guid, result_guid, iformat):
85    return _doSearch(request, iformat, collection_guid, observation_guid, result_guid)   
86
87def _buildDescriptionOsPath(collection_guid = None, observation_guid = None, result_guid = None):
88    ospath = "%s/search/" % (hostURL)
89    if collection_guid:
90        ospath = "%s%s/" % (ospath, collection_guid)
91    if observation_guid:
92        ospath = "%s%s/" % (ospath, observation_guid)
93    if result_guid:
94        ospath = "%s%s/" % (ospath, result_guid)
95    return ospath       
96       
97def _dispatchResponse(request, template, context):
98    context.update(csrf(request))
99    return render_to_response(template, context)   
Note: See TracBrowser for help on using the repository browser.