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

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

further exception handling

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            try:
25                c['title'] = v.code
26            except:
27                c['title'] = ""
28        if v.authority.title == 'moles2url':
29            try:
30                c['moles2url'] = v.code
31            except:
32                c['moles2url'] = ""
33    for v in record.relatedParty:
34        if v.role.name == 'cl_author':
35            try:
36                c['author'] = v.party[0].name
37            except:
38                c['author'] = ""
39        if v.role.name == 'cl_pointofcontact':
40            try:
41                c['email_contact_addr'] = v.party[0].contactInfo[0].address.electronicMailAddress[0];
42                c['email_contact_name'] = v.party[0].name;
43            except:
44                c['email_contact_addr'] = "";
45                c['email_contact_name'] = "";
46        if v.role.name == 'cl_publisher':
47            try:
48                c['publisher'] = v.party[0].name
49            except:
50                c['publisher'] = ""
51        if v.role.name == 'cl_coinvestigator':
52            try:
53                c['co_investigator'] = v.party[0].name;
54            except:
55                c['co_investigator'] = "";
56    pubyear = record.resultTime.position.dateTime8601.year;
57    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>");
58    try:
59        c['status'] = record.publicationState.value
60    except:
61        c['status'] = ""
62    try:
63        c['last_update_year'] = record.resultTime.position.dateTime8601.year
64    except:
65        c['last_update_year'] = ""
66    try:
67        c['last_update_month'] = record.resultTime.position.dateTime8601.month
68    except:
69        c['last_update_month'] = ""
70    try:
71        c['last_update_day'] = record.resultTime.position.dateTime8601.day
72    except:
73        c['last_update_day'] = ""
74    try:
75        c['phenomenon_begin_year'] = record.phenomenonTime.begin.position.date8601.year;
76    except:
77        c['phenomenon_begin_year'] = ""
78    try:
79        c['phenomenon_begin_month'] = record.phenomenonTime.begin.position.date8601.month;
80    except:
81        c['phenomenon_begin_month'] = ""
82    try:
83        c['phenomenon_begin_day'] = record.phenomenonTime.begin.position.date8601.day;
84    except:
85        c['phenomenon_begin_day'] = ""
86    try:
87        c['phenomenon_end_year'] = record.phenomenonTime.end.position.date8601.year;
88    except:
89        c['phenomenon_end_year'] = ""
90    try:
91        c['phenomenon_end_month'] = record.phenomenonTime.end.position.date8601.month;
92    except:
93        c['phenomenon_end_month'] = ""
94    try:
95        c['phenomenon_end_day'] = record.phenomenonTime.end.position.date8601.day;
96    except:
97        c['phenomenon_end_day'] = ""
98    try:
99        c['vertical_extent'] = record.verticalExtent;
100    except:
101        c['vertical_extent'] = ""
102    try:
103        c['resolution'] = record.resolution;
104    except:
105        c['resolution'] = ""
106    try:
107        c['observed_property'] = record.observedProperty;
108    except:
109        c['observed_property'] = ""
110    try:
111        c['parameters'] = record.parameter;
112    except:
113        c['parameters'] = ""
114    try:
115        c['project_details'] = record.inSupportOf.relatedParty;
116    except:
117        c['project_details'] = ""
118    try:
119        c['procedure'] = record.procedure;
120    except:
121        c['procedure'] = ""
122    try:
123        c['lineage'] = record.dataLineage;
124    except:
125        c['lineage'] = ""
126    try:
127        c['archive_no_files'] = record.result.numberOfFiles
128    except:
129        c['archive_no_files'] = ""
130    try:
131        c['geographic_extentE'] = record.geographicExtent[0].eastBoundLongitude
132        c['geographic_extentW'] = record.geographicExtent[0].westBoundLongitude
133        c['geographic_extentN'] = record.geographicExtent[0].northBoundLatitude
134        c['geographic_extentS'] = record.geographicExtent[0].southBoundLatitude
135    except:
136        c['geographic_extentE'] = 180
137        c['geographic_extentW'] = -180
138        c['geographic_extentN'] = 90
139        c['geographic_extentS'] = -90
140    try:
141        c['related_data'] = record.relatedObservation;
142    except:
143        c['related_data'] = ""
144    try:
145        c['quality_statement'] = record.resultQuality
146    except:
147        c['quality_statement'] = ""
148    try:
149        c['keywords'] = record.keywords[0].keyword[0];
150    except:
151        c['keywords'] = ""
152    try:
153        c['download_link'] = record.result.source[0].linkage
154    except:
155        c['download_link'] = ""
156    try:
157        c['download_name'] = record.result.source[0].name
158    except:
159        c['download_name'] =  ""
160    try:
161        if len(record.permission.useLimitation[0]) != 0:
162            p = record.permission.useLimitation[0].split(' http://')
163            c['permission'] = mark_safe(p[0] + "  <a href=\"http://" + p[1] + "\" target=\"_blank\">" + p[1] + "<\a>");
164        else:
165            c['permission'] = "These data may be open access. Please contact the data centre to enquire about access to these data."
166    except:
167        c['permission'] = "These data may be open access. Please contact the data centre to enquire about access to these data."
168    lk = []
169    for l in record.result.source:
170        ls = l.linkage.strip()
171        if len(ls) != 0:
172          lk.append(ls)
173    c['archive_linkage'] = lk
174    try:
175        c['documentation'] = record.documentation
176    except:
177        c['documentation'] = ""
178    return render_to_response('cedaBrowse.html', c)
179
180def _getCedaObservation(request, obs_id):
181    #return Moles3EPB.searchEager(CEDA_Observation, obs_id, request.moles_session)
182    return Moles3EPB.search(CEDA_Observation, obs_id, request.moles_session)
Note: See TracBrowser for help on using the repository browser.