22import logging
33from html import escape as html_escape
44
5- from six . moves . urllib .parse import quote
5+ from urllib .parse import quote
66
77from ckan .plugins import toolkit as tk
88
1111
1212from ckanext .pages import actions
1313from ckanext .pages import auth
14- from ckanext .pages import blueprint
14+ from ckanext .pages import blueprint , config as cfg
1515
1616from ckan .lib .plugins import DefaultTranslation
1717
2121
2222def build_pages_nav_main (* args ):
2323
24- about_menu = tk . asbool ( tk . config . get ( 'ckanext.pages. about_menu' , True ) )
25- group_menu = tk . asbool ( tk . config . get ( 'ckanext.pages. group_menu' , True ) )
26- org_menu = tk . asbool ( tk . config . get ( 'ckanext.pages. organization_menu' , True ) )
27- root_path = tk .config . get ( 'ckan.root_path' , '/' )
24+ about_menu = cfg . about_menu ( )
25+ group_menu = cfg . group_menu ( )
26+ org_menu = cfg . organization_menu ( )
27+ root_path = tk .config [ 'ckan.root_path' ] or ""
2828
2929 new_args = []
3030 for arg in args :
@@ -62,12 +62,12 @@ def build_pages_nav_main(*args):
6262
6363
6464def render_content (content ):
65- allow_html = tk . asbool ( tk . config . get ( 'ckanext.pages. allow_html' , False ) )
65+ allow_html = cfg . allow_html ( )
6666 return tk .h .render_markdown (content , allow_html = allow_html )
6767
6868
6969def get_wysiwyg_editor ():
70- return tk . config . get ( 'ckanext.pages. editor' , '' )
70+ return cfg . editor ( )
7171
7272
7373def get_recent_blog_posts (number = 5 , exclude = None ):
@@ -90,20 +90,37 @@ class PagesPluginBase(p.SingletonPlugin, DefaultTranslation):
9090 p .implements (p .ITranslation , inherit = True )
9191
9292
93+ @tk .blanket .auth_functions ({
94+ 'ckanext_pages_show' : auth .pages_show ,
95+ 'ckanext_pages_update' : auth .pages_update ,
96+ 'ckanext_pages_delete' : auth .pages_delete ,
97+ 'ckanext_pages_list' : auth .pages_list ,
98+ 'ckanext_pages_upload' : auth .pages_upload ,
99+ 'ckanext_org_pages_show' : auth .org_pages_show ,
100+ 'ckanext_org_pages_update' : auth .org_pages_update ,
101+ 'ckanext_org_pages_delete' : auth .org_pages_delete ,
102+ 'ckanext_org_pages_list' : auth .org_pages_list ,
103+ 'ckanext_group_pages_show' : auth .group_pages_show ,
104+ 'ckanext_group_pages_update' : auth .group_pages_update ,
105+ 'ckanext_group_pages_delete' : auth .group_pages_delete ,
106+ 'ckanext_group_pages_list' : auth .group_pages_list ,
107+ })
108+ @tk .blanket .helpers ({
109+ 'build_nav_main' : build_pages_nav_main ,
110+ 'render_content' : render_content ,
111+ 'pages_get_wysiwyg_editor' : get_wysiwyg_editor ,
112+ 'get_recent_blog_posts' : get_recent_blog_posts ,
113+ })
114+ @tk .blanket .blueprints ([blueprint .pages ])
115+ @tk .blanket .config_declarations
93116class PagesPlugin (PagesPluginBase ):
94117 p .implements (p .IConfigurer , inherit = True )
95- p .implements (p .ITemplateHelpers , inherit = True )
96118 p .implements (p .IActions , inherit = True )
97- p .implements (p .IAuthFunctions , inherit = True )
98119 p .implements (p .IConfigurable , inherit = True )
99- p .implements (p .IBlueprint )
100-
101- def get_blueprint (self ):
102- return [blueprint .pages ]
103120
104121 def update_config (self , config ):
105- self .organization_pages = tk . asbool ( config . get ( 'ckanext.pages.organization' , False ) )
106- self .group_pages = tk . asbool ( config . get ( 'ckanext.pages.group' , False ) )
122+ self .organization_pages = cfg . enable_organization_pages ( )
123+ self .group_pages = cfg . enable_group_pages ( )
107124
108125 tk .add_template_directory (config , 'theme/templates_main' )
109126 if self .group_pages :
@@ -117,14 +134,6 @@ def update_config(self, config):
117134 tk .add_public_directory (config , 'assets/vendor/ckeditor/' )
118135 tk .add_public_directory (config , 'assets/vendor/ckeditor/skins/moono-lisa' )
119136
120- def get_helpers (self ):
121- return {
122- 'build_nav_main' : build_pages_nav_main ,
123- 'render_content' : render_content ,
124- 'pages_get_wysiwyg_editor' : get_wysiwyg_editor ,
125- 'get_recent_blog_posts' : get_recent_blog_posts ,
126- }
127-
128137 def get_actions (self ):
129138 actions_dict = {
130139 'ckanext_pages_show' : actions .pages_show ,
@@ -152,23 +161,6 @@ def get_actions(self):
152161 actions_dict .update (group_actions )
153162 return actions_dict
154163
155- def get_auth_functions (self ):
156- return {
157- 'ckanext_pages_show' : auth .pages_show ,
158- 'ckanext_pages_update' : auth .pages_update ,
159- 'ckanext_pages_delete' : auth .pages_delete ,
160- 'ckanext_pages_list' : auth .pages_list ,
161- 'ckanext_pages_upload' : auth .pages_upload ,
162- 'ckanext_org_pages_show' : auth .org_pages_show ,
163- 'ckanext_org_pages_update' : auth .org_pages_update ,
164- 'ckanext_org_pages_delete' : auth .org_pages_delete ,
165- 'ckanext_org_pages_list' : auth .org_pages_list ,
166- 'ckanext_group_pages_show' : auth .group_pages_show ,
167- 'ckanext_group_pages_update' : auth .group_pages_update ,
168- 'ckanext_group_pages_delete' : auth .group_pages_delete ,
169- 'ckanext_group_pages_list' : auth .group_pages_list ,
170- }
171-
172164
173165class TextBoxView (p .SingletonPlugin ):
174166
0 commit comments