Skip to content

Commit

Permalink
[#2733] turn echo is off
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Aug 23, 2012
1 parent baed742 commit f82c5d1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
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
12 changes: 11 additions & 1 deletion ckanext/datastore/db.py
Expand Up @@ -45,7 +45,7 @@ def _get_engine(context, data_dict):
engine = _engines.get(connection_url)

if not engine:
engine = sqlalchemy.create_engine(connection_url, echo=True)
engine = sqlalchemy.create_engine(connection_url)
_engines[connection_url] = engine
return engine

Expand Down Expand Up @@ -429,6 +429,13 @@ def search_data(context, data_dict):

_validate_int(limit, 'limit')
_validate_int(offset, 'offset')
#convert to ints so that return dict looks correct
data_dict['limit'] = int(limit)
data_dict['offset'] = int(offset)

##pretend there is a limit so we get a count
if limit == 0:
limit = 1

sort = _sort(context, data_dict.get('sort'), field_ids)

Expand All @@ -453,6 +460,9 @@ def search_data(context, data_dict):
converted_row = {}
if not data_dict['total']:
data_dict['total'] = row['_full_count']
# we have the total now so we do not need any records
if data_dict['limit'] == 0:
break
for field in result_fields:
converted_row[field['id']] = convert(row[field['id']],
field['type'])
Expand Down
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 f82c5d1

Please sign in to comment.