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

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

Updated search page to give something a little more meaningful in the results. Now has the title field as a link to the appropriate object with the description below.

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 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    titles = []
27    ids = []
28    list_list = []
29    baseCov = "http://" + request.get_host() + "/cov/"
30    for o in observations:
31        a = "".join([baseCov, str(o.id)])
32        try:
33            if o.identifier[0].code is not None:
34                list_list.append((a, o.identifier[0].code, o.description))
35        except Exception as e:
36            print e
37    return list_list
38
39def _appendAuthors(party):
40    res = None
41    for item in party:
42        res = ("%s%s,") % (res, item.name)
43    if len(res) > 1:
44        return res[:len(res)-1]
45    return res
46
47
48def coSearch(request):
49    c = {}   
50    if 'searchTerm' in request.POST:
51        c['searchResults'] = __doSearch(request, request.POST['searchTerm'])
52           
53    c.update(csrf(request))
54    if c == {} :
55        return render_to_response('cedaObservation.html', c) 
56    else :
57        found = False
58    try:
59        a = c['searchResults']
60        found = True
61    except Exception, ex:
62        pass
63    if not found:
64            return render_to_response('cedaSearch.html', c)
65    return render_to_response('cedaSearchResults.html', c)
Note: See TracBrowser for help on using the repository browser.