source: mauRepo/MolesManager/trunk/src/MolesManager/views/cedaBrowse.py @ 8318

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/MolesManager/views/cedaBrowse.py@8318
Revision 8318, 4.6 KB checked in by jhorton, 9 years ago (diff)

added exception handling to try and make code a little more resilient

Line 
1'''
2@created on 8 may 2012
3@author jah
4'''
5from django.shortcuts import render_to_response
6from django.core.context_processors import csrf
7from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation
8from MolesManager.moles3epb import Moles3EPB
9from MolesManager.djencoder import DJEncoder
10from django.utils.safestring import mark_safe
11
12def browseView(request, obs_id_str):
13    obs_id = int(obs_id_str)
14    record = None
15    guid = None
16    c = {}
17    if obs_id:
18        record = _getCedaObservation(request, obs_id)
19        guid = Moles3EPB.retrieveGUIDFromInstance(record, request.moles_session)
20        c['guid'] = guid.id
21    c['abstract'] = record.inSupportOf.abstract
22    for v in record.identifier:
23        if v.authority.title == 'ceda_title':
24            c['title'] = v.code
25        if v.authority.title == 'moles2url':
26            c['moles2url'] = v.code
27    for v in record.relatedParty:
28        if v.role.name == 'cl_author':
29            c['author'] = v.party[0].name
30        if v.role.name == 'cl_pointofcontact':
31            try:
32                c['email_contact_addr'] = v.party[0].contactInfo[0].address.electronicMailAddress[0];
33                c['email_contact_name'] = v.party[0].name;
34            except:
35                c['email_contact_addr'] = "";
36                c['email_contact_name'] = "";
37        if v.role.name == 'cl_publisher':
38            try:
39                c['publisher'] = v.party[0].name
40            except:
41                c['publisher'] = ""
42        if v.role.name == 'cl_coinvestigator':
43            try:
44                c['co_investigator'] = v.party[0].name;
45            except:
46                c['co_investigator'] = "";
47    pubyear = record.resultTime.position.dateTime8601.year;
48    c['citation'] = mark_safe(c['author'] + ";" + c['co_investigator'] + "(" + pubyear + ")" + c['title'] + " " + c['publisher'] + " Available from : <a href=\"http://www.ceda.ac.uk/datacat/" + c['guid'] + "\" target=\"_blank\">http://www.ceda.ac.uk/datacat/" + c['guid'] +"</a>");
49    c['status'] = record.publicationState.value
50    c['last_update_year'] = record.resultTime.position.dateTime8601.year
51    c['last_update_month'] = record.resultTime.position.dateTime8601.month
52    c['last_update_day'] = record.resultTime.position.dateTime8601.day
53    c['phenomenon_begin_year'] = record.phenomenonTime.begin.position.date8601.year;
54    c['phenomenon_begin_month'] = record.phenomenonTime.begin.position.date8601.month;
55    c['phenomenon_begin_day'] = record.phenomenonTime.begin.position.date8601.day;
56    c['phenomenon_end_year'] = record.phenomenonTime.end.position.date8601.year;
57    c['phenomenon_end_month'] = record.phenomenonTime.end.position.date8601.month;
58    c['phenomenon_end_day'] = record.phenomenonTime.end.position.date8601.day;
59    c['vertical_extent'] = record.verticalExtent;
60    c['resolution'] = record.resolution;
61    c['observed_property'] = record.observedProperty;
62    c['parameters'] = record.parameter;
63    c['project_details'] = record.inSupportOf.relatedParty;
64    c['procedure'] = record.procedure;
65    c['lineage'] = record.dataLineage;
66    c['archive_no_files'] = record.result.numberOfFiles
67    c['geographic_extentE'] = record.geographicExtent[0].eastBoundLongitude
68    c['geographic_extentW'] = record.geographicExtent[0].westBoundLongitude
69    c['geographic_extentN'] = record.geographicExtent[0].northBoundLatitude
70    c['geographic_extentS'] = record.geographicExtent[0].southBoundLatitude
71    c['related_data'] = record.relatedObservation;
72    c['quality_statement'] = record.resultQuality
73    c['keywords'] = record.keywords[0].keyword[0];
74    c['download_link'] = record.result.source[0].linkage
75    c['download_name'] = record.result.source[0].name
76    try:
77        if len(record.permission.useLimitation[0]) != 0:
78            p = record.permission.useLimitation[0].split(' http://')
79            c['permission'] = mark_safe(p[0] + "  <a href=\"http://" + p[1] + "\" target=\"_blank\">" + p[1] + "<\a>");
80        else:
81            c['permission'] = "These data may be open access. Please contact the data centre to enquire about access to these data."
82    except:
83        c['permission'] = "These data may be open access. Please contact the data centre to enquire about access to these data."
84    lk = []
85    for l in record.result.source:
86        ls = l.linkage.strip()
87        if len(ls) != 0:
88          lk.append(ls)
89    c['archive_linkage'] = lk
90    c['documentation'] = record.documentation
91    return render_to_response('cedaBrowse.html', c)
92
93def _getCedaObservation(request, obs_id):
94    #return Moles3EPB.searchEager(CEDA_Observation, obs_id, request.moles_session)
95    return Moles3EPB.search(CEDA_Observation, obs_id, request.moles_session)
Note: See TracBrowser for help on using the repository browser.