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

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

Incomplete - # 22534: Add versiojn number to the gui page
 http://team.ceda.ac.uk/trac/ceda/ticket/22534

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
11from cedaMoles.MolesManager.molesSessionMiddleware import mm_render_to_response
12
13def getResponseByGuid(request, guid):
14    ceda_guid = request.moles3EPB.search(CedaGUID, guid)
15    if ceda_guid and ceda_guid.ceda_observation:
16        return cedaObservationView.objView(request, ceda_guid.ceda_observation)
17    if ceda_guid and ceda_guid.ceda_observationcollection:
18        return cedaObservationCollectionView.objView(request, ceda_guid.ceda_observationcollection)   
19
20def __doSearch(request, keywords):
21    '''
22        @param request: an HttpRequest
23        @param keywords: an list of strings
24        @return: the first Observation or None
25        '''
26    observations = request.moles3EPB.extractObservationByTitleKeywords(keywords) 
27   
28    list_list = []
29    baseCov = "http://" + request.get_host() + "/"
30    for guid, o in observations.iteritems():
31       
32        a = "".join([baseCov, guid])
33        try:
34            if o.identifier[0].code is not None:
35                list_list.append((a, o.identifier[0].code, o.description))
36                print a, o.identifier[0].code, o.description
37        except Exception as e:
38            print e
39    return list_list
40
41def _appendAuthors(party):
42    res = None
43    for item in party:
44        res = ("%s%s,") % (res, item.name)
45    if len(res) > 1:
46        return res[:len(res)-1]
47    return res
48
49
50def coSearch(request):
51    context = {}   
52    if 'searchTerm' in request.POST:
53        context['searchResults'] = __doSearch(request, request.POST['searchTerm'])
54           
55    context.update(csrf(request))
56    if context == {} :
57        return render_to_response('cedaObservation.html', context) 
58    else :
59        found = False
60    try:
61        a = context['searchResults']
62        found = True
63    except Exception, ex:
64        pass
65    if not found:
66            return mm_render_to_response(request, context, 'cedaSearch.html')
67    return mm_render_to_response(request, context, 'cedaSearchResults.html')
Note: See TracBrowser for help on using the repository browser.