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

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

added record author to table

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    for o in obsevations:
35        a = "".join(
36            [baseCov,
37            str(o.id)])
38        auth_query = Moles3EPB.observationAuthor(o.id, request.moles_session)
39        ath = auth_query.all()
40        ath0 = ath[0]
41        list_list.append((a, o.description, ath0.role)) 
42    return list_list
43
44
45def coSearch(request):
46    c = {}   
47    if 'searchTerm' in request.POST:
48        c['searchResults'] = __doSearch(request, request.POST['searchTerm'])
49           
50    c.update(csrf(request))
51    if c == {} :
52        return render_to_response('cedaObservation.html', c) 
53    else :
54        found = False
55    try:
56        a = c['searchResults']
57        found = True
58    except Exception, ex:
59        pass
60    if not found:
61            return render_to_response('cedaSearch.html', c)
62    return render_to_response('cedaSearchResults.html', c)
Note: See TracBrowser for help on using the repository browser.