Skip to content

Commit

Permalink
CKAN 2.10 replace controllers & Iroutes with blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
thepsalmist committed Mar 25, 2024
1 parent 2203a00 commit cb48a10
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 36 deletions.
41 changes: 41 additions & 0 deletions ckanext/openafrica/blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from flask import Blueprint
from ckan.plugins.toolkit import render

openafrica = Blueprint('datapusher', __name__)

def toc():
return render('home/about/toc.html')

def accessibility():
return render('home/about/accessibility.html')

def coc():
return render('home/about/coc.html')

def moderation():
return render('home/about/moderation.html')

def faq():
return render('home/about/faq.html')

def privacy():
return render('home/about/privacy.html')

def contact():
return render('home/about/contact.html')

def atlas():
return render('atlas.html')

rules = [
("/about/terms-and-conditions", "toc", toc),
("/about/accessibility", "accessibility", accessibility),
("/about/code-of-conduct", "coc", coc),
("/about/moderation-policy", "moderation", moderation),
("/about/faq", "faq", faq),
("/about/privacy", "privacy", privacy)
]

for rule in rules:
openafrica.add_url_rule(*rule)

81 changes: 45 additions & 36 deletions ckanext/openafrica/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from . import blueprint


class OpenAfricaPlugin(plugins.SingletonPlugin):
u"""
openAFRICA templating plugin.
"""
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IRoutes, inherit=True)
plugins.implements(plugins.ITemplateHelpers)
plugins.implements(plugins.IBlueprint)

def update_config(self, config):
u"""
Expand All @@ -45,42 +46,50 @@ def update_config(self, config):
# toolkit.add_resource('fanstatic', 'openafrica')
toolkit.add_resource('assets', 'openafrica')

def before_map(self, map):
u"""
Called before the routes map is generated. ``before_map`` is before any
other mappings are created so can override all other mappings.
:param map: Routes map object
:returns: Modified version of the map object
# IBlueprint
def get_blueprint(self):
"""
CKAN uses Flask Blueprints in the /ckan/views dir for user and dashboard
:return:
"""
map.connect('/about/terms-and-conditions',
controller='ckanext.openafrica.controller:CustomPageController',
action='toc')
map.connect('/about/accessibility',
controller='ckanext.openafrica.controller:CustomPageController',
action='accessibility')
map.connect('/about/code-of-conduct',
controller='ckanext.openafrica.controller:CustomPageController',
action='coc')
map.connect('/about/moderation-policy',
controller='ckanext.openafrica.controller:CustomPageController',
action='moderation')
map.connect('/about/faq',
controller='ckanext.openafrica.controller:CustomPageController',
action='faq')
map.connect('/about/privacy',
controller='ckanext.openafrica.controller:CustomPageController',
action='privacy')
map.connect('/about/contact-us',
controller='ckanext.openafrica.controller:CustomPageController',
action='contact')
map.connect('/about/suggest-a-dataset',
controller='ckanext.openafrica.controller:CustomPageController',
action='suggest_a_dataset')
map.connect('/atlas-for-africa',
controller='ckanext.openafrica.controller:CustomPageController',
action='atlas')
return map
return blueprint.openafrica

# def before_map(self, map):
# u"""
# Called before the routes map is generated. ``before_map`` is before any
# other mappings are created so can override all other mappings.

# :param map: Routes map object
# :returns: Modified version of the map object
# """
# map.connect('/about/terms-and-conditions',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='toc')
# map.connect('/about/accessibility',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='accessibility')
# map.connect('/about/code-of-conduct',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='coc')
# map.connect('/about/moderation-policy',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='moderation')
# map.connect('/about/faq',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='faq')
# map.connect('/about/privacy',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='privacy')
# map.connect('/about/contact-us',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='contact')
# map.connect('/about/suggest-a-dataset',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='suggest_a_dataset')
# map.connect('/atlas-for-africa',
# controller='ckanext.openafrica.controller:CustomPageController',
# action='atlas')
# return map

def get_helpers(self):
u"""
Expand Down

0 comments on commit cb48a10

Please sign in to comment.