Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #37 from tomkralidis/master
Browse files Browse the repository at this point in the history
Implement data.json feed (#31)
  • Loading branch information
ahinz committed Jan 13, 2014
2 parents 7e052cd + 1ab5825 commit 2c9e533
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions OpenDataCatalog/catalog/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
import os.path

from django.conf import settings
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

from OpenDataCatalog.opendata.models import Resource
from pycsw import server

CONFIGURATION = {
Expand All @@ -22,6 +24,30 @@
}
}


@csrf_exempt
def data_json(request):
"""Return data.json representation of site catalog"""
json_data = []
for resource in Resource.objects.all():
record = {}
record['title'] = resource.name
record['description'] = resource.description
record['keyword'] = resource.csw_keywords.split(',')
record['modified'] = resource.last_updated
record['publisher'] = resource.organization
record['contactPoint'] = resource.metadata_contact
record['mbox'] = resource.contact_email
record['identifier'] = resource.csw_identifier
if resource.is_published:
record['accessLevel'] = 'public'
else:
record['accessLevel'] = 'non-public'

json_data.append(record)

return HttpResponse(json.dumps(json_data), 'application/json')

@csrf_exempt
def csw(request):
"""CSW WSGI wrapper"""
Expand Down
1 change: 1 addition & 0 deletions OpenDataCatalog/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h2 class="grid">About</h2>
<li id="terms"><a href="{{SITE_ROOT}}/terms/">Terms</a></li>
<li id="feeds"><a href="{{SITE_ROOT}}/feeds/">RSS Feeds</a></li>
<li id="feeds"><a href="{{SITE_ROOT}}/catalog/csw?service=CSW&amp;version=2.0.2&amp;request=GetCapabilities">OGC Catalog Service</a></li>
<li id="feeds"><a href="{{SITE_ROOT}}/data.json">Open Data Catalog JSON</a></li>
{% if perms.opendata.change_resource %}
<li class="separator"></li>
<li id="admin"><a href="{{SITE_ROOT}}/_admin_">Administration</a></li>
Expand Down
1 change: 1 addition & 0 deletions OpenDataCatalog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
(r'^api/submit/$', 'OpenDataCatalog.api.views.submit'),

url(r'^catalog/', include("OpenDataCatalog.catalog.urls")),
url(r'^data.json$', "OpenDataCatalog.catalog.views.data_json"),

# Uncomment the next line to enable the admin:
url(r'^_admin_/', include(admin.site.urls)),
Expand Down

2 comments on commit 2c9e533

@mheadd
Copy link

@mheadd mheadd commented on 2c9e533 Jan 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@philipashlock
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super awesome! The schema is already based on DCAT, but we're working on a more relaxed version of it for non federal sources so other systems can validate compliance. Currently we're using JSON schema for this and the federally-focused schema is available at: https://github.com/project-open-data/project-open-data.github.io/tree/master/schema/1_0_final

I'll plan to track the progress of this here: project-open-data/project-open-data.github.io#247

Please sign in to comment.