Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKAN 2.10 replace controllers & IRoutes with blueprints #54

Merged
merged 13 commits into from
Jun 5, 2024
42 changes: 42 additions & 0 deletions ckanext/openafrica/blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from flask import Blueprint
from ckan.plugins.toolkit import render

openafrica = Blueprint('openafrica', __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),
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
("/about/accessibility", "accessibility", accessibility),
("/about/code-of-conduct", "coc", coc),
("/about/moderation-policy", "moderation", moderation),
("/about/faq", "faq", faq),
("/about/privacy", "privacy", privacy),
("/about/contact-us", "contact", contact)
]

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

49 changes: 0 additions & 49 deletions ckanext/openafrica/controller.py

This file was deleted.

50 changes: 11 additions & 39 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
Copy link
Member

@kilemensi kilemensi Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer absolute imports.



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.IConfigurer, inherit=True)
plugins.implements(plugins.ITemplateHelpers, inherit=True)
plugins.implements(plugins.IBlueprint)
Comment on lines +33 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do some plugins use inherit and others don't? (This is for just my understanding).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the blueprint, we only need custom routes to handle our /about/<>/ urls hence though it was not necessary to extend CKAN core's Blueprints. On the other plugins, we inherit helper functions & configurations such as url_for, link_for et.al from CKAN core


def update_config(self, config):
u"""
Expand All @@ -42,45 +43,16 @@ def update_config(self, config):
"""
toolkit.add_template_directory(config, 'templates')
toolkit.add_public_directory(config, 'public')
# 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):
"""
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
CKAN uses Flask Blueprints to extend urls
:return:
"""
return blueprint.openafrica


def get_helpers(self):
u"""
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/dataset-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% block flash %}
<div class="flash-messages">
{% block flash_inner %}
{% for message in h.flash.pop_messages() | list %}
{% for message in h.flash.pop_messages | list %}
<div class="alert fade in {{ message.category }}">
{{ h.literal(message) }}
</div>
Expand Down
4 changes: 2 additions & 2 deletions ckanext/openafrica/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<!-- Be sure to leave the brand out there if you want it shown -->
{% block header_logo %}
{% if g.site_logo %}
<a class="logo brand" href="{{ h.url('home') }}"><img src="{{ g.site_logo }}" alt="{{ g.site_title }}"
<a class="logo brand" href="{{ h.url_for('home.index') }}"><img src="{{ g.site_logo }}" alt="{{ g.site_title }}"
title="{{ g.site_title }}" /></a>
{% else %}
<a class="brand" href="{{ h.url('home') }}"><img
<a class="brand" href="{{ h.url_for('home.index') }}"><img
src="https://cloud.githubusercontent.com/assets/877919/14067805/7e3ff5ae-f476-11e5-88eb-059d88816232.png"
alt="{{ g.site_title }}" title="{{ g.site_title }}" /></a>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/accessibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('Accessibility'), controller='ckanext.openafrica.controller:CustomPageController', action='accessibility' %}</li>
<li class="active">{% link_for _('Accessibility'), named_route='openafrica.accessibility' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/coc.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('Code of Conduct'), controller='ckanext.openafrica.controller:CustomPageController', action='coc' %}</li>
<li class="active">{% link_for _('Code of Conduct'), named_route='openafrica.coc' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('Contact Us'), controller='ckanext.openafrica.controller:CustomPageController', action='contact' %}</li>
<li class="active">{% link_for _('Contact Us'), named_route='openafrica.contact' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('FAQs'), controller='ckanext.openafrica.controller:CustomPageController', action='faq' %}</li>
<li class="active">{% link_for _('FAQs'), named_route='openafrica.faq' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/moderation.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('Moderation Policy'), controller='ckanext.openafrica.controller:CustomPageController', action='moderation' %}</li>
<li class="active">{% link_for _('Moderation Policy'), named_route='openafrica.moderation' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/privacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('Privacy'), controller='ckanext.openafrica.controller:CustomPageController', action='privacy' %}</li>
<li class="active">{% link_for _('Privacy'), named_route='openafrica.privacy' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/home/about/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li >{% link_for _('About'), controller='home', action='about' %}</li>
<li class="active">{% link_for _('Terms & Conditions'), controller='ckanext.openafrica.controller:CustomPageController', action='toc' %}</li>
<li class="active">{% link_for _('Terms & Conditions'), named_route='openafrica.toc' %}</li>
{% endblock %}

{% block primary %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/openafrica/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% block flash %}
<div class="flash-messages">
{% block flash_inner %}
{% for message in h.flash.pop_messages() | list %}
{% for message in h.flash.pop_messages | list %}
<div class="alert fade in {{ message.category }}">
{{ h.literal(message) }}
</div>
Expand Down