source: mauRepo/MolesManager/trunk/cedaMoles/MolesManager/views/cedaSearch.py @ 8503

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/cedaMoles/MolesManager/views/cedaSearch.py@8503
Revision 8503, 2.0 KB checked in by gparton, 8 years ago (diff)
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#, redirect
8from cedaMoles.MolesManager.ceda_guid import CedaGUID
9import cedaObservationView
10import cedaObservationCollectionView
11
12def getResponseByGuid(request, guid):
13    ceda_guid = request.moles3EPB.search(CedaGUID, guid)
14    if ceda_guid and ceda_guid.ceda_observation:
15        return cedaObservationView.objView(request, ceda_guid.ceda_observation)
16    if ceda_guid and ceda_guid.ceda_observationcollection:
17        return cedaObservationCollectionView.objView(request, ceda_guid.ceda_observationcollection)   
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    observations = request.moles3EPB.extractObservationByTitleKeywords(keywords) 
26   
27    list_list = []
28    baseCov = "http://" + request.get_host() + "/"
29    for guid, o in observations.iteritems():
30       
31        a = "".join([baseCov, guid])
32        try:
33            if o.identifier[0].code is not None:
34                list_list.append((a, o.identifier[0].code, o.description))
35                print a, o.identifier[0].code, o.description
36        except Exception as e:
37            print e
38    return list_list
39
40def _appendAuthors(party):
41    res = None
42    for item in party:
43        res = ("%s%s,") % (res, item.name)
44    if len(res) > 1:
45        return res[:len(res)-1]
46    return res
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.