Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1251] Updating Recline views for new IResourceView
interface. The only view options that are currently supported are row offset and limit (so the graph in particular is not usable at the moment).
- Loading branch information
1 parent
294ed98
commit 1080ac0
Showing
7 changed files
with
133 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,84 @@ | ||
from logging import getLogger | ||
|
||
from ckan.common import json | ||
import ckan.plugins as p | ||
import ckan.plugins.toolkit as toolkit | ||
|
||
log = getLogger(__name__) | ||
ignore_missing = p.toolkit.get_validator('ignore_missing') | ||
natural_number_validator = p.toolkit.get_validator('natural_number_validator') | ||
|
||
|
||
class ReclinePreview(p.SingletonPlugin): | ||
"""This extension previews resources using recline | ||
This extension implements two interfaces | ||
- ``IConfigurer`` allows to modify the configuration | ||
- ``IResourcePreview`` allows to add previews | ||
""" | ||
class ReclineView(p.SingletonPlugin): | ||
''' | ||
This base class for the Recline view extensions. | ||
''' | ||
p.implements(p.IConfigurer, inherit=True) | ||
p.implements(p.IResourcePreview, inherit=True) | ||
p.implements(p.IResourceView, inherit=True) | ||
|
||
# schema fields that apply to all Recline views | ||
schema = {'offset': [ignore_missing, natural_number_validator], | ||
'limit': [ignore_missing, natural_number_validator]} | ||
|
||
def update_config(self, config): | ||
''' Set up the resource library, public directory and | ||
''' | ||
Set up the resource library, public directory and | ||
template directory for the preview | ||
''' | ||
toolkit.add_public_directory(config, 'theme/public') | ||
toolkit.add_template_directory(config, 'theme/templates') | ||
toolkit.add_resource('theme/public', 'ckanext-reclinepreview') | ||
|
||
def can_preview(self, data_dict): | ||
# if the resource is in the datastore then we can preview it with recline | ||
def can_view(self, data_dict): | ||
if data_dict['resource'].get('datastore_active'): | ||
return True | ||
format_lower = data_dict['resource']['format'].lower() | ||
return format_lower in ['csv', 'xls', 'tsv'] | ||
return False | ||
|
||
def setup_template_variables(self, context, data_dict): | ||
return {'resource_json': json.dumps(data_dict['resource']), | ||
'resource_view_json': json.dumps(data_dict['resource_view'])} | ||
|
||
def view_template(self, context, data_dict): | ||
return 'recline_view.html' | ||
|
||
|
||
class ReclineGrid(ReclineView): | ||
''' | ||
This extension views resources using a Recline grid. | ||
''' | ||
|
||
def info(self): | ||
return {'name': 'recline_grid', | ||
'title': 'Grid', | ||
'schema': self.schema} | ||
|
||
def form_template(self, context, data_dict): | ||
return 'recline_grid_form.html' | ||
|
||
|
||
class ReclineGraph(ReclineView): | ||
''' | ||
This extension views resources using a Recline graph. | ||
''' | ||
|
||
def info(self): | ||
return {'name': 'recline_graph', | ||
'title': 'Graph', | ||
'schema': self.schema} | ||
|
||
def form_template(self, context, data_dict): | ||
return 'recline_graph_form.html' | ||
|
||
|
||
class ReclineMap(ReclineView): | ||
''' | ||
This extension views resources using a Recline map. | ||
''' | ||
|
||
def info(self): | ||
return {'name': 'recline_map', | ||
'title': 'Map', | ||
'schema': self.schema} | ||
|
||
def preview_template(self, context, data_dict): | ||
return 'recline.html' | ||
def form_template(self, context, data_dict): | ||
return 'recline_map_form.html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
ckanext/reclinepreview/theme/templates/recline_graph_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{{ form.input('offset', id='field-offset', label=_('Row offset'), placeholder=_('eg: 0'), value=data.offset, error=errors.offset, classes=['control-medium']) }} | ||
{{ form.input('limit', id='field-limit', label=_('Number of rows'), placeholder=_('eg: 100'), value=data.limit, error=errors.limit, classes=['control-medium']) }} |
4 changes: 4 additions & 0 deletions
4
ckanext/reclinepreview/theme/templates/recline_grid_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{{ form.input('offset', id='field-offset', label=_('Row offset'), placeholder=_('eg: 0'), value=data.offset, error=errors.offset, classes=['control-medium']) }} | ||
{{ form.input('limit', id='field-limit', label=_('Number of rows'), placeholder=_('eg: 100'), value=data.limit, error=errors.limit, classes=['control-medium']) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{{ form.input('offset', id='field-offset', label=_('Row offset'), placeholder=_('eg: 0'), value=data.offset, error=errors.offset, classes=['control-medium']) }} | ||
{{ form.input('limit', id='field-limit', label=_('Number of rows'), placeholder=_('eg: 100'), value=data.limit, error=errors.limit, classes=['control-medium']) }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters