This repository was archived by the owner on Apr 19, 2024. It is now read-only.
File tree 3 files changed +28
-0
lines changed
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import json
1
2
import os .path
2
3
3
4
from django .conf import settings
4
5
from django .http import HttpResponse
5
6
from django .views .decorators .csrf import csrf_exempt
6
7
8
+ from OpenDataCatalog .opendata .models import Resource
7
9
from pycsw import server
8
10
9
11
CONFIGURATION = {
22
24
}
23
25
}
24
26
27
+
28
+ @csrf_exempt
29
+ def data_json (request ):
30
+ """Return data.json representation of site catalog"""
31
+ json_data = []
32
+ for resource in Resource .objects .all ():
33
+ record = {}
34
+ record ['title' ] = resource .name
35
+ record ['description' ] = resource .description
36
+ record ['keyword' ] = resource .csw_keywords .split (',' )
37
+ record ['modified' ] = resource .last_updated
38
+ record ['publisher' ] = resource .organization
39
+ record ['contactPoint' ] = resource .metadata_contact
40
+ record ['mbox' ] = resource .contact_email
41
+ record ['identifier' ] = resource .csw_identifier
42
+ if resource .is_published :
43
+ record ['accessLevel' ] = 'public'
44
+ else :
45
+ record ['accessLevel' ] = 'non-public'
46
+
47
+ json_data .append (record )
48
+
49
+ return HttpResponse (json .dumps (json_data ), 'application/json' )
50
+
25
51
@csrf_exempt
26
52
def csw (request ):
27
53
"""CSW WSGI wrapper"""
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ <h2 class="grid">About</h2>
25
25
< li id ="terms "> < a href ="{{SITE_ROOT}}/terms/ "> Terms</ a > </ li >
26
26
< li id ="feeds "> < a href ="{{SITE_ROOT}}/feeds/ "> RSS Feeds</ a > </ li >
27
27
< li id ="feeds "> < a href ="{{SITE_ROOT}}/catalog/csw?service=CSW&version=2.0.2&request=GetCapabilities "> OGC Catalog Service</ a > </ li >
28
+ < li id ="feeds "> < a href ="{{SITE_ROOT}}/data.json "> Open Data Catalog JSON</ a > </ li >
28
29
{% if perms.opendata.change_resource %}
29
30
< li class ="separator "> </ li >
30
31
< li id ="admin "> < a href ="{{SITE_ROOT}}/_admin_ "> Administration</ a > </ li >
Original file line number Diff line number Diff line change 76
76
(r'^api/submit/$' , 'OpenDataCatalog.api.views.submit' ),
77
77
78
78
url (r'^catalog/' , include ("OpenDataCatalog.catalog.urls" )),
79
+ url (r'^data.json$' , "OpenDataCatalog.catalog.views.data_json" ),
79
80
80
81
# Uncomment the next line to enable the admin:
81
82
url (r'^_admin_/' , include (admin .site .urls )),
You can’t perform that action at this time.
0 commit comments