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

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

Complete - # 22489: CEDA Observation Collection - phenomenonTime
 http://team.ceda.ac.uk/trac/ceda/ticket/22489
Complete - # 22488: CEDA Observation Collection - Geographical Extent
 http://team.ceda.ac.uk/trac/ceda/ticket/22488

RevLine 
[8120]1'''
2Created on 1 Nov 2011
3
4@author: mnagni
5'''
6from django.core.context_processors import csrf
[8445]7from django.shortcuts import render_to_response, redirect
8from MolesManager.ceda_guid import CedaGUID
9import cedaObservationView
10import cedaObservationCollectionView
[8120]11
[8445]12def getResponseByGuid(request, guid):
13    ceda_guid = request.moles3EPB.search(CedaGUID, guid)
[8241]14    if ceda_guid and ceda_guid.ceda_observation:
[8445]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)   
[8241]18
[8245]19def __doSearch(request, keywords):
[8120]20    '''
[8289]21        @param request: an HttpRequest
22        @param keywords: an list of strings
23        @return: the first Observation or None
24        '''
[8339]25    obsevations = request.moles3EPB.extractObservationByTitleKeywords(keywords) 
[8289]26    titles = []
27    ids = []
[8290]28    list_list = []
29    baseCov = "http://" + request.get_host() + "/cov/"
[8289]30    for o in obsevations:
[8430]31        a = "".join([baseCov, str(o.id)])
[8434]32        try:
33            responsibleAuthors = request.moles3EPB.observationAuthor(o)
34            if responsibleAuthors is not None:
35                list_list.append((a, o.description, _appendAuthors(responsibleAuthors)))
36        except Exception as e:
37            print e
[8290]38    return list_list
[8120]39
[8430]40def _appendAuthors(party):
41    res = None
42    for item in party:
[8434]43        res = ("%s%s,") % (res, item.name)
[8430]44    if len(res) > 1:
45        return res[:len(res)-1]
46    return res
[8211]47
[8430]48
[8120]49def coSearch(request):
[8245]50    c = {}   
[8241]51    if 'searchTerm' in request.POST:
[8289]52        c['searchResults'] = __doSearch(request, request.POST['searchTerm'])
[8282]53           
[8275]54    c.update(csrf(request))
55    if c == {} :
56        return render_to_response('cedaObservation.html', c) 
57    else :
[8289]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.