source: mauRepo/MolesManager/trunk/src/MolesManager/views/cedaSearch.py @ 8291

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/MolesManager/views/cedaSearch.py@8291
Revision 8291, 1.9 KB checked in by jhorton, 8 years ago (diff)

fixed search quoting issue

Line 
1'''
2Created on 1 Nov 2011
3
4@author: mnagni
5'''
6from django.shortcuts import render_to_response, redirect
7from django.core.context_processors import csrf
8from MolesManager.views import cedaObservationView
9from MolesManager.ceda_guid import CedaGUID
10from MolesManager.moles3epb import Moles3EPB
11
12"""
13def __getResponseByGuid(request, guid):
14    ceda_guid = Moles3EPB.search(CedaGUID, guid, request.moles_session)
15    if ceda_guid and ceda_guid.ceda_observation:
16        return redirect(cedaObservationView.coView, ceda_guid.ceda_observation)
17"""
18
19def __doSearch(request, keywords):
20    '''
21        @param request: an HttpRequest
22        @param keywords: an list of strings
23        @return: the first Observation or None
24        '''
25    if not keywords.startswith("'"):
26        keywords = "'" + keywords
27    if not keywords.endswith("'"):
28        keywords = keywords + "'"
29    obsevations = Moles3EPB.extractObservationByTitleKeywords(keywords, request.moles_session)     
30    titles = []
31    ids = []
32    list_list = []
33    baseCov = "http://" + request.get_host() + "/cov/"
34    O = None
35    for o in obsevations:
36        titles.append("".join(
37                    [baseCov,
38                     str(o.id)
39                    ]))
40        ids.append(o.id)
41        a = "".join(
42            [baseCov,
43            str(o.id)])
44        list_list.append((a, o.description)) 
45        O = o
46    return list_list
47
48
49def coSearch(request):
50    c = {}   
51    if 'searchTerm' in request.POST:
52        c['searchResults'] = __doSearch(request, request.POST['searchTerm'])
53           
54    c.update(csrf(request))
55    if c == {} :
56        return render_to_response('cedaObservation.html', c) 
57    else :
58        found = False
59    try:
60        a = c['searchResults']
61        found = True
62    except Exception, ex:
63        pass
64    if not found:
65            return render_to_response('cedaSearch.html', c)
66    return render_to_response('cedaSearchResults.html', c)
Note: See TracBrowser for help on using the repository browser.