source: mauRepo/MolesManager/trunk/src/MolesManager/views/cedaObservationView.py @ 8325

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

Great improvement on how SA alchemy session is managed

Line 
1'''
2Created on 1 Nov 2011
3
4@author: mnagni
5'''
6from django.shortcuts import render_to_response
7from django.core.context_processors import csrf
8from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation
9from MolesManager.moles3epb import Moles3EPB
10from MolesManager.djencoder import DJEncoder
11from django.utils.safestring import mark_safe
12
13
14def coView(request, obs_id_str):
15    obs_id = int(obs_id_str)
16    return splash(request, obs_id)   
17
18def splash(request, obs_id):
19    """
20        Processes and display a given CEDA_Observation id
21        @param request: an HTTP request
22        @param obs_id: the CEDA_Observation id
23        @return: an HTTPResponse 
24    """
25    record = None
26    if obs_id:
27        record = _getCedaObservation(request, obs_id)
28    return _finalizeResponse(request, record)
29   
30def _finalizeResponse(request, record):
31    c = {}
32    if record:
33        c['coObs'] = mark_safe(DJEncoder().escapeForJSON(DJEncoder().encode(record)))
34        guid = request.moles3EPB.retrieveGUIDFromInstance(record)
35        if guid:
36            c['guid'] = guid.id
37            print c['guid']
38        print c['coObs'] 
39   
40    c.update(csrf(request))
41    return render_to_response('cedaObservation.html', c)
42
43def _getCedaObservation(request, obs_id):   
44    eagerloadthese = ['identifier.authority', 'resultTime.position.dateTime8601.month', \
45                      'resultAccumulation', 'relatedParty.party', 'result.source.function', 'permission', \
46                      'geographicExtent', 'phenomenonTime', 'keywords', 'description', \
47                      'inSupportOf.abstract', 'dataLineage']
48    return request.moles3EPB.searchSelectiveLoad(CEDA_Observation, obs_id, eagerloadthese)
49    #return Moles3EPB.searchEager(CEDA_Observation, obs_id)
Note: See TracBrowser for help on using the repository browser.