1 | ''' |
---|
2 | Created on 1 Nov 2011 |
---|
3 | |
---|
4 | @author: mnagni |
---|
5 | ''' |
---|
6 | from django.shortcuts import render_to_response, redirect |
---|
7 | from django.core.context_processors import csrf |
---|
8 | from MolesManager.views import cedaObservationView |
---|
9 | from MolesManager.ceda_guid import CedaGUID |
---|
10 | from MolesManager.moles3epb import Moles3EPB |
---|
11 | |
---|
12 | """ |
---|
13 | def __getResponseByGuid(request, guid): |
---|
14 | ceda_guid = Moles3EPB.search(CedaGUID, guid, request.moles_session) |
---|
15 | if ceda_guid and ceda_guid.ceda_observation: |
---|
16 | return redirect(cedaObservationView.coView, ceda_guid.ceda_observation) |
---|
17 | """ |
---|
18 | |
---|
19 | def __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 | obsevations = Moles3EPB.extractObservationByTitleKeywords(keywords, request.moles_session) |
---|
26 | titles = [] |
---|
27 | ids = [] |
---|
28 | list_list = [] |
---|
29 | baseCov = "http://" + request.get_host() + "/cov/" |
---|
30 | O = None |
---|
31 | for o in obsevations: |
---|
32 | titles.append("".join( |
---|
33 | [baseCov, |
---|
34 | str(o.id) |
---|
35 | ])) |
---|
36 | ids.append(o.id) |
---|
37 | a = "".join( |
---|
38 | [baseCov, |
---|
39 | str(o.id)]) |
---|
40 | list_list.append((a, o.description)) |
---|
41 | O = o |
---|
42 | return list_list |
---|
43 | |
---|
44 | |
---|
45 | def coSearch(request): |
---|
46 | c = {} |
---|
47 | if 'searchTerm' in request.POST: |
---|
48 | c['searchResults'] = __doSearch(request, request.POST['searchTerm']) |
---|
49 | |
---|
50 | c.update(csrf(request)) |
---|
51 | if c == {} : |
---|
52 | return render_to_response('cedaObservation.html', c) |
---|
53 | else : |
---|
54 | found = False |
---|
55 | try: |
---|
56 | a = c['searchResults'] |
---|
57 | found = True |
---|
58 | except Exception, ex: |
---|
59 | pass |
---|
60 | if not found: |
---|
61 | return render_to_response('cedaSearch.html', c) |
---|
62 | return render_to_response('cedaSearchResults.html', c) |
---|