-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from WorldHealthOrganization/custom_view
Custom view
- Loading branch information
Showing
8 changed files
with
1,188 additions
and
31 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,57 +1,137 @@ | ||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as toolkit | ||
from ckan.lib.plugins import DefaultTranslation | ||
from ckanext.afucn.subresource import create_subresource | ||
from ckan.common import config | ||
|
||
subresource = config.get('ckanext.afucn.subresource', False) | ||
|
||
# -------------------------------------------------------------------- | ||
# Original Plugin Class | ||
# -------------------------------------------------------------------- | ||
class AfucnPlugin(plugins.SingletonPlugin, DefaultTranslation): | ||
plugins.implements(plugins.IConfigurer) | ||
plugins.implements(plugins.IFacets) | ||
plugins.implements(plugins.ITranslation) | ||
plugins.implements(plugins.IResourceController, inherit=True) | ||
|
||
# IConfigurer | ||
|
||
# IConfigurer | ||
def update_config(self, config_): | ||
toolkit.add_template_directory(config_, "templates") | ||
toolkit.add_public_directory(config_, "public") | ||
toolkit.add_resource("assets", "afucn") | ||
|
||
# IFacets | ||
|
||
def dataset_facets(self, facets_dict, package_type): | ||
'''Add new search facet (filter) for datasets. | ||
This must be a field in the dataset (or organization or | ||
group if you're modifying those search facets, just change the function). | ||
''' | ||
# This keeps the existing facet order. | ||
facets_dict['country'] = plugins.toolkit._('Country') | ||
facets_dict['organization'] = plugins.toolkit._('Organization') | ||
facets_dict['groups'] = plugins.toolkit._('Groups') | ||
facets_dict['tags'] = plugins.toolkit._('tags') | ||
facets_dict['res_format'] = plugins.toolkit._('Format') | ||
facets_dict['license_id'] = plugins.toolkit._('License') | ||
|
||
facets_dict['country'] = toolkit._('Country') | ||
facets_dict['organization'] = toolkit._('Organization') | ||
facets_dict['groups'] = toolkit._('Groups') | ||
facets_dict['tags'] = toolkit._('tags') | ||
facets_dict['res_format'] = toolkit._('Format') | ||
facets_dict['license_id'] = toolkit._('License') | ||
return facets_dict | ||
|
||
def group_facets(self, facets_dict, group_type, package_type): | ||
facets_dict['country'] = toolkit._('Country') | ||
facets_dict['organization'] = toolkit._('Organization') | ||
facets_dict['groups'] = toolkit._('Groups') | ||
facets_dict['tags'] = toolkit._('tags') | ||
facets_dict['res_format'] = toolkit._('Format') | ||
facets_dict['license_id'] = toolkit._('License') | ||
return facets_dict | ||
|
||
# This keeps the existing facet order. | ||
facets_dict['country'] = plugins.toolkit._('Country') | ||
facets_dict['organization'] = plugins.toolkit._('Organization') | ||
facets_dict['groups'] = plugins.toolkit._('Groups') | ||
facets_dict['tags'] = plugins.toolkit._('tags') | ||
facets_dict['res_format'] = plugins.toolkit._('Format') | ||
facets_dict['license_id'] = plugins.toolkit._('License') | ||
|
||
def organization_facets(self, facets_dict, organization_type, package_type): | ||
facets_dict['country'] = toolkit._('Country') | ||
facets_dict['organization'] = toolkit._('Organization') | ||
facets_dict['groups'] = toolkit._('Groups') | ||
facets_dict['tags'] = toolkit._('tags') | ||
facets_dict['res_format'] = toolkit._('Format') | ||
facets_dict['license_id'] = toolkit._('License') | ||
return facets_dict | ||
|
||
def organization_facets(self, facets_dict, organization_type, package_type): | ||
# IResourceController | ||
def after_resource_create(self, context, resource_dict): | ||
if subresource: | ||
create_subresource(context, resource_dict) | ||
return | ||
|
||
# This keeps the existing facet order. | ||
facets_dict['country'] = plugins.toolkit._('Country') | ||
facets_dict['organization'] = plugins.toolkit._('Organization') | ||
facets_dict['groups'] = plugins.toolkit._('Groups') | ||
facets_dict['tags'] = plugins.toolkit._('tags') | ||
facets_dict['res_format'] = plugins.toolkit._('Format') | ||
facets_dict['license_id'] = plugins.toolkit._('License') | ||
|
||
return facets_dict | ||
# -------------------------------------------------------------------- | ||
# New Resource View: Portal Map | ||
# -------------------------------------------------------------------- | ||
class PortalMapView(plugins.SingletonPlugin, DefaultTranslation): | ||
plugins.implements(plugins.IConfigurer) | ||
plugins.implements(plugins.IResourceView, inherit=True) | ||
|
||
def update_config(self, config_): | ||
toolkit.add_template_directory(config_, "templates") | ||
toolkit.add_public_directory(config_, "public") | ||
toolkit.add_resource("assets", "afucn") | ||
|
||
def info(self): | ||
return { | ||
'name': 'portal_map', | ||
'title': 'Portal Map', | ||
'icon': 'map', | ||
'iframed': False, | ||
'default_title': 'Portal Map', | ||
'always_available': True, | ||
'preview_enabled': True, | ||
'full_page_edit': False, | ||
} | ||
|
||
def can_view(self, data_dict): | ||
resource = data_dict.get('resource') | ||
fmt = resource.get('format', '').lower() | ||
return fmt in ['csv', 'xls', 'xlsx'] | ||
|
||
def view_template(self, context, data_dict): | ||
return 'views/portal_map.html' | ||
|
||
def view_config(self, context, data_dict): | ||
return {} | ||
|
||
def order(self): | ||
return 2 | ||
|
||
|
||
# -------------------------------------------------------------------- | ||
# New Resource View: Portal Chart | ||
# -------------------------------------------------------------------- | ||
class PortalChartView(plugins.SingletonPlugin, DefaultTranslation): | ||
plugins.implements(plugins.IConfigurer) | ||
plugins.implements(plugins.IResourceView, inherit=True) | ||
|
||
def update_config(self, config_): | ||
toolkit.add_template_directory(config_, "templates") | ||
toolkit.add_public_directory(config_, "public") | ||
toolkit.add_resource("assets", "afucn") | ||
|
||
def info(self): | ||
return { | ||
'name': 'portal_chart', | ||
'title': 'Portal Chart', | ||
'icon': 'chart-pie', | ||
'iframed': False, | ||
'default_title': 'Portal Chart', | ||
'always_available': True, | ||
'preview_enabled': True, | ||
'full_page_edit': False, | ||
} | ||
|
||
def can_view(self, data_dict): | ||
resource = data_dict.get('resource') | ||
fmt = resource.get('format', '').lower() | ||
return fmt in ['csv', 'xls', 'xlsx'] | ||
|
||
def view_template(self, context, data_dict): | ||
return 'views/portal_chart.html' | ||
|
||
def view_config(self, context, data_dict): | ||
return {} | ||
|
||
def order(self): | ||
return 3 | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.