Skip to content

Commit

Permalink
[#2888] first attempt and datapreview on its own
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Aug 23, 2012
1 parent db9bfe6 commit 3b482dc
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ckan/config/routing.py
Expand Up @@ -194,6 +194,9 @@ def make_map():
)
m.connect('/dataset/{id}.{format}', action='read')
m.connect('/dataset/{id}', action='read')

m.connect('/datapreview/{resource_id}', action='data_preview')

m.connect('/dataset/{id}/resource/{resource_id}',
action='resource_read')
m.connect('/dataset/{id}/resource/{resource_id}/download',
Expand Down
15 changes: 15 additions & 0 deletions ckan/controllers/package.py
Expand Up @@ -794,6 +794,21 @@ def resource_read(self, id, resource_id):
c.related_count = c.pkg.related_count
return render('package/resource_read.html')

def data_preview(self, resource_id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author}

try:
c.resource = get_action('resource_show')(context,
{'id': resource_id})
c.resource_json = json.dumps(c.resource)
c.pkg_dict = c.package
except NotFound:
abort(404, _('Resource not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read resource %s') % id)
return render('package/datapreview.html')

def resource_download(self, id, resource_id):
"""
Provides a direct download by redirecting the user to the url stored
Expand Down
5 changes: 5 additions & 0 deletions ckan/public/scripts/application.js
Expand Up @@ -46,6 +46,11 @@ CKAN.Utils = CKAN.Utils || {};
CKAN.DataPreview.loadPreviewDialog(preload_resource);
}

var isResourceViewNew = $('#ckanext-datapreview').length > 0;
if (isResourceViewNew) {
CKAN.DataPreview.loadPreviewDialog(preload_resource);
}

var isEmbededDataviewer = $('body.package.resource_embedded_dataviewer').length > 0;
if (isEmbededDataviewer) {
CKAN.DataPreview.loadEmbeddedPreview(preload_resource, reclineState);
Expand Down
57 changes: 57 additions & 0 deletions ckan/templates/package/datapreview.html
@@ -0,0 +1,57 @@

<html xmlns:py="http://genshi.edgewall.org/"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:xi="http://www.w3.org/2001/XInclude">

<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<script type="text/javascript">
var preload_resource = ${h.literal(c.resource_json)};
var embedPath = ${h.literal(c.resource_json)};
</script>

<xi:include href="../js_strings.html" />
<xi:include href="../_snippet/data-api-help.html" />
<xi:include href="../snippets/data-viewer-embed-dialog.html" />

<script src="${h.url_for_static('/scripts/vendor/jquery/1.7.1/jquery.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.mustache/jquery.mustache.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/flot/0.7/jquery.flot.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/flot/0.7/jquery.flot.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/leaflet/0.3.1/leaflet.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/json2.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.tmpl/beta1/jquery.tmpl.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.cookie/jquery.cookie.min.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.chosen/0.9.7/chosen.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.placeholder/jquery.placeholder.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jqueryui/1.8.14/jquery-ui.min.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/bootstrap/2.0.3/bootstrap.min.js')}"></script>

<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/underscore/1.1.6/underscore.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/backbone/0.5.1/backbone.js')}"></script>

<xi:include href="../snippets/recline-extra-header.html" />

<link rel="stylesheet" href="${h.url_for_static('/scripts/vendor/leaflet/0.3.1/leaflet.css')}" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="${h.url_for_static('/scripts/vendor/leaflet/0.3.1/leaflet.ie.css')}" />
<![endif]-->
<link rel="stylesheet" href="${h.url_for_static('/scripts/vendor/jqueryui/1.8.14/css/jquery-ui.custom.css')}" type="text/css" media="screen, print" />
<link rel="stylesheet" href="${h.url_for_static('/css/bootstrap.min.css')}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${h.url_for_static('/css/chosen.css')}" type="text/css" />

</head>

<body>
<div id="ckanext-datapreview"></div>
</body>

<xi:include href="../snippets/recline-extra-footer.html" />

<script type="text/javascript" src="${h.url_for_static('/scripts/application.js?lang=${c.locale}')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.mustache/jquery.mustache.js')}"></script>


</html>
27 changes: 27 additions & 0 deletions ckanext/datastore/tests/test_datastore.py
Expand Up @@ -575,6 +575,33 @@ def test_search_limit(self):
assert result['total'] == 2
assert result['records'] == [self.expected_records[0]]


data = {'resource_id': self.data['resource_id'],
'limit': 0}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_search', params=postparams,
extra_environ=auth)
res_dict = json.loads(res.body)
assert res_dict['success'] is True
result = res_dict['result']
assert result['total'] == 2
assert result['records'] == []

#filter returns no results with 0 limit
data = {'resource_id': self.data['resource_id'],
'limit': 0,
'filters': {u'b\xfck': 'annakar'}}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_search', params=postparams,
extra_environ=auth)
res_dict = json.loads(res.body)
assert res_dict['success'] is True
result = res_dict['result']
assert result['total'] == 0
assert result['records'] == []

def test_search_invalid_limit(self):
data = {'resource_id': self.data['resource_id'],
'limit': 'bad'}
Expand Down

0 comments on commit 3b482dc

Please sign in to comment.