cambio da Controller di ckan 2.6 a Blueprint di Flask per ckan 2.10
This commit is contained in:
parent
e3d28b6c52
commit
48e3f914d3
|
@ -19,6 +19,9 @@ class D4SciencePlugin(plugins.SingletonPlugin):
|
|||
# plugins.implements(plugins.IClick)
|
||||
# plugins.implements(plugins.ITemplateHelpers)
|
||||
# plugins.implements(plugins.IValidators)
|
||||
|
||||
#ckan 2.10
|
||||
plugins.implements(plugins.IBlueprint)
|
||||
|
||||
|
||||
# IConfigurer
|
||||
|
@ -43,6 +46,17 @@ class D4SciencePlugin(plugins.SingletonPlugin):
|
|||
|
||||
# def get_blueprint(self):
|
||||
# return views.get_blueprints()
|
||||
|
||||
def get_blueprint(self):
|
||||
blueprint = Blueprint('foo', self.__module__)
|
||||
rules = [
|
||||
('/foo', 'custom_action', custom_action),
|
||||
('/group', 'group_index', custom_group_index),
|
||||
]
|
||||
for rule in rules:
|
||||
blueprint.add_url_rule(*rule)
|
||||
|
||||
return blueprint
|
||||
|
||||
# IClick
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import logging
|
||||
from ckan.controllers.home import HomeController
|
||||
# from ckan.controllers.home import HomeController
|
||||
import ckan.plugins as p
|
||||
from ckan.common import OrderedDict, _, g, c
|
||||
from ckan.common import _, g, c
|
||||
from collections import OrderedDict
|
||||
|
||||
import ckan.lib.search as search
|
||||
import ckan.model as model
|
||||
import ckan.logic as logic
|
||||
|
@ -9,6 +11,9 @@ import ckan.lib.maintain as maintain
|
|||
import ckan.lib.base as base
|
||||
import ckan.lib.helpers as h
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
|
||||
# Created by Francesco Mangiacrapa
|
||||
# francesco.mangiacrapa@isti.cnr.it
|
||||
# ISTI-CNR Pisa (ITALY)
|
||||
|
@ -71,5 +76,7 @@ class d4SHomeController():
|
|||
% g.site_title
|
||||
h.flash_notice(msg, allow_html=True)
|
||||
|
||||
return base.render('home/index.html', cache_force=True)
|
||||
#return base.render('home/index.html', cache_force=True)
|
||||
#ckan 2.10 :
|
||||
return render_template('home/index.html')
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import re
|
||||
|
||||
import ckan.controllers.group as group
|
||||
#import ckan.controllers.group as group
|
||||
import ckan.plugins as plugins
|
||||
import logging
|
||||
import datetime
|
||||
|
@ -25,7 +25,7 @@ from ckan.common import c, request, _
|
|||
'''
|
||||
Created by Francesco Mangiacrapa, see: #8964
|
||||
'''
|
||||
class OrganizationVREController(group.GroupController):
|
||||
class OrganizationVREController(plugins.toolkit.DefaultGroupForm): #changed for 2.10 : GroupController -> defaultGroupForm
|
||||
''' The organization controller is for Organizations, which are implemented
|
||||
as Groups with is_organization=True and group_type='organization'. It works
|
||||
the same as the group controller apart from:
|
||||
|
|
|
@ -10,9 +10,12 @@ import ckan.lib.helpers as h
|
|||
import sqlalchemy as sa
|
||||
from ckanext.d4science_theme.controllers.organization import OrganizationVREController
|
||||
from ckanext.d4science_theme.controllers.home import d4SHomeController
|
||||
from ckan.controllers.home import HomeController
|
||||
#from ckan.controllers.home import HomeController
|
||||
from ckan.config.middleware.common_middleware import TrackingMiddleware
|
||||
from ckan.plugins import IRoutes
|
||||
#from ckan.plugins import IRoutes
|
||||
from flask import Blueprint
|
||||
|
||||
|
||||
|
||||
from ckan.common import (
|
||||
g
|
||||
|
@ -218,7 +221,10 @@ class D4Science_ThemePlugin(plugins.SingletonPlugin, toolkit.DefaultDatasetForm)
|
|||
plugins.implements(plugins.IDatasetForm)
|
||||
plugins.implements(plugins.ITemplateHelpers)
|
||||
plugins.implements(plugins.IFacets)
|
||||
plugins.implements(IRoutes, inherit=True)
|
||||
#plugins.implements(IRoutes, inherit=True)
|
||||
|
||||
#ckan 2.10
|
||||
plugins.implements(plugins.IBlueprint)
|
||||
|
||||
# IConfigurer
|
||||
def update_config(self, config_):
|
||||
|
@ -312,9 +318,9 @@ class D4Science_ThemePlugin(plugins.SingletonPlugin, toolkit.DefaultDatasetForm)
|
|||
#Overriding package_extras_save method
|
||||
model_save.package_extras_save = _package_extras_save
|
||||
|
||||
#Overriding index home controller
|
||||
d4sHC = d4SHomeController()
|
||||
HomeController.index = d4sHC.index
|
||||
#Overriding index home controller - rimosso in ckan 2.10
|
||||
#d4sHC = d4SHomeController()
|
||||
# HomeController.index = d4sHC.index
|
||||
|
||||
#OVERRIDING BASE SQL ALCHEMY ENGINE INSTANCE
|
||||
TrackingMiddleware.__init__ = _init_TrackingMiddleware
|
||||
|
@ -380,25 +386,37 @@ class D4Science_ThemePlugin(plugins.SingletonPlugin, toolkit.DefaultDatasetForm)
|
|||
|
||||
return facets_dict
|
||||
|
||||
def before_map(self, map):
|
||||
"""This IRoutes implementation overrides the standard
|
||||
``/user/register`` behaviour with a custom controller. You
|
||||
might instead use it to provide a completely new page, for
|
||||
example.
|
||||
Note that we have also provided a custom register form
|
||||
template at ``theme/templates/user/register.html``.
|
||||
"""
|
||||
# Hook in our custom user controller at the points of creation
|
||||
# and edition.
|
||||
#
|
||||
#map.connect('/type', controller='ckanext.d4science_theme.controllers.type::d4STypeController', action='index')
|
||||
map.connect('/type', controller='ckanext.d4science_theme.controllers.systemtype:d4STypeController', action='index')
|
||||
''' Added by Francesco Mangiacrapa, see: #8964 '''
|
||||
organization_vre = OrganizationVREController()
|
||||
map.connect('/organization_vre', controller='ckanext.d4science_theme.controllers.organization:OrganizationVREController', action='index')
|
||||
map.connect('/organization_vre/{id}', controller='ckanext.d4science_theme.controllers.organization:OrganizationVREController', action='read')
|
||||
map.redirect('/types', "/type")
|
||||
return map
|
||||
#changed to migrate to ckan 2.10:
|
||||
def get_blueprint(self):
|
||||
d4sHC = d4SHomeController()
|
||||
blueprint = Blueprint('d4s', self.__module__)
|
||||
rules = [
|
||||
('/', 'index', d4sHC.index),
|
||||
]
|
||||
for rule in rules:
|
||||
blueprint.add_url_rule(*rule)
|
||||
|
||||
return blueprint
|
||||
|
||||
# def before_map(self, map):
|
||||
# """This IRoutes implementation overrides the standard
|
||||
# ``/user/register`` behaviour with a custom controller. You
|
||||
# might instead use it to provide a completely new page, for
|
||||
# example.
|
||||
# Note that we have also provided a custom register form
|
||||
# template at ``theme/templates/user/register.html``.
|
||||
# """
|
||||
# # Hook in our custom user controller at the points of creation
|
||||
# # and edition.
|
||||
# #
|
||||
# #map.connect('/type', controller='ckanext.d4science_theme.controllers.type::d4STypeController', action='index')
|
||||
# map.connect('/type', controller='ckanext.d4science_theme.controllers.systemtype:d4STypeController', action='index')
|
||||
# ''' Added by Francesco Mangiacrapa, see: #8964 '''
|
||||
# organization_vre = OrganizationVREController()
|
||||
# map.connect('/organization_vre', controller='ckanext.d4science_theme.controllers.organization:OrganizationVREController', action='index')
|
||||
# map.connect('/organization_vre/{id}', controller='ckanext.d4science_theme.controllers.organization:OrganizationVREController', action='read')
|
||||
# map.redirect('/types', "/type")
|
||||
# return map
|
||||
|
||||
|
||||
def _add_or_update_facet(self, facet_key, facet_value, facets_dict, display_after_facet='organization'):
|
||||
|
|
Loading…
Reference in New Issue