Skip to content

Commit

Permalink
[#1251] recline default view and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Nov 13, 2013
1 parent 35c2184 commit fa49b54
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
45 changes: 42 additions & 3 deletions ckan/lib/cli.py
Expand Up @@ -2070,7 +2070,7 @@ def command(self):
print self.usage

def create_views(self, view_types):
supported_types = ['text','webpage', 'pdf', 'image']
supported_types = ['text','webpage', 'pdf', 'image', 'grid']
if not view_types:
print self.usage
return
Expand Down Expand Up @@ -2242,8 +2242,6 @@ def create_pdf_views(self):

print '''pdf resource views are being created'''

import ckanext.pdfpreview.plugin as pdfplugin

results = model.Session.execute(
'''select resource.id, format
from resource
Expand All @@ -2267,3 +2265,44 @@ def create_pdf_views(self):

print '''%s pdf resource views created!''' % count

def create_grid_views(self):
import ckan.model as model
import ckan.logic as logic
import ckanext.datastore.db as db
import pylons
import sqlalchemy

if not p.plugin_loaded('datastore'):
print 'Datastore needs to loaded to make the grid views.'
return

if not p.plugin_loaded('recline_grid'):
print 'Please enable recline_grid extension to make the grid views.'
return

print '''Grid resource views are being created'''

user = logic.get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
context = {'model': model, 'session': model.Session, 'user': user['name']}

data_dict = {}
data_dict['connection_url'] = pylons.config['ckan.datastore.write_url']

resources_sql = sqlalchemy.text(u'''SELECT name FROM "_table_metadata"
WHERE alias_of is null''')
results = db._get_engine(data_dict).execute(resources_sql)

count = 0
for row in results:
res = logic.get_action('resource_view_list')(context, {'id': row[0]})
if res:
continue
count += 1
resource_view = {'resource_id': row[0],
'view_type': 'recline_grid',
'title': 'Grid view',
'description': 'View of data within the DataStore'}
logic.get_action('resource_view_create')(context, resource_view)

print '''%s grid resource views created!''' % count

14 changes: 14 additions & 0 deletions ckanext/datapusher/logic/action.py
Expand Up @@ -153,6 +153,20 @@ def datapusher_hook(context, data_dict):
task['state'] = status
task['last_updated'] = str(datetime.datetime.now())


if status == 'complete' and p.plugin_loaded('recline_grid'):
view_list = p.toolkit.get_action('resource_view_list')(context, {
'id': res_id})

if not view_list:
view = {'resource_id': res_id,
'view_type': 'recline_grid',
'title': 'Grid view',
'description': 'View of data within the DataStore'
}
view_list = p.toolkit.get_action('resource_view_create')(context,
view)

p.toolkit.get_action('task_status_update')(context, task)


Expand Down

0 comments on commit fa49b54

Please sign in to comment.