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

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

Incomplete - # 22416: CEDA MOLES3 - search function - by title keyword
 http://team.ceda.ac.uk/trac/ceda/ticket/22416

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