Skip to content

Commit b799c2f

Browse files
committed
chore: v2.12 support
1 parent 6c8d593 commit b799c2f

32 files changed

Lines changed: 554 additions & 308 deletions

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
strategy:
2121
matrix:
2222
include:
23+
- ckan-version: "2.12"
24+
ckan-image: "ckan/ckan-dev:2.12"
2325
- ckan-version: "2.11"
2426
ckan-image: "ckan/ckan-dev:2.11-py3.10"
2527
- ckan-version: "2.10"
2628
ckan-image: "ckan/ckan-dev:2.10-py3.10"
27-
- ckan-version: "2.9"
28-
ckan-image: "ckan/ckan-dev:2.9-py3.9"
2929
fail-fast: false
3030

3131
name: CKAN ${{ matrix.ckan-version }}
@@ -70,4 +70,3 @@ jobs:
7070
ckan -c test.ini db upgrade -p pages
7171
- name: Run tests
7272
run: pytest --ckan-ini=test.ini --cov=ckanext.pages --cov-report=term-missing --cov-append --disable-warnings ckanext/pages/tests
73-

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ This extension gives you an easy way to add simple pages to CKAN.
88

99
By default you can add pages to the main CKAN menu.
1010

11-
Tested on CKAN 2.9 and 2.10.
12-
13-
Note: For CKAN 2.7 and 2.8 use v0.3.7 or older versions.
11+
Tested on CKAN 2.10 and newer.
1412

1513
## Installation
1614

@@ -175,4 +173,3 @@ Released under the GNU Affero General Public License (AGPL) v3.0. See the file `
175173
## History
176174

177175
See the file [CHANGELOG.md](CHANGELOG.md).
178-

ckanext/pages/actions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import ckan.authz as authz
1616

17-
from ckanext.pages import db
17+
from ckanext.pages import db, config as cfg
1818

1919

2020
class HTMLFirstImage(HTMLParser):
@@ -106,8 +106,8 @@ def _pages_update(context, data_dict):
106106
schema = update_pages_schema()
107107

108108
# +1 is the Current state by default while ckanext.pages.revisions_limit is the amounf of previous states
109-
revisions_limit = tk.asint(tk.config.get('ckanext.pages.revisions_limit', '3')) + 1
110-
force_revisions_limit = tk.asbool(tk.config.get('ckanext.pages.revisions_force_limit', False))
109+
revisions_limit = cfg.revisions_limit() + 1
110+
force_revisions_limit = cfg.force_revisions_limit()
111111

112112
data, errors = df.validate(data_dict, schema, context)
113113

ckanext/pages/config.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from __future__ import annotations
2+
3+
import ckan.plugins.toolkit as tk
4+
5+
ABOUT_MENU = "ckanext.pages.about_menu"
6+
GROUP_MENU = "ckanext.pages.group_menu"
7+
ORGANIZATION_MENU = "ckanext.pages.organization_menu"
8+
ALLOW_HTML = "ckanext.pages.allow_html"
9+
EDITOR = "ckanext.pages.editor"
10+
ENABLE_ORGANIZATION_PAGES = "ckanext.pages.organization"
11+
ENABLE_GROUP_PAGES = "ckanext.pages.group"
12+
REVISIONS_LIMIT = "ckanext.pages.revisions_limit"
13+
FORCE_REVISIONS_LIMIT = "ckanext.pages.revisions_force_limit"
14+
FORM = "ckanext.pages.form"
15+
16+
17+
def about_menu() -> bool:
18+
return tk.config[ABOUT_MENU]
19+
20+
21+
def group_menu() -> bool:
22+
return tk.config[GROUP_MENU]
23+
24+
25+
def organization_menu() -> bool:
26+
return tk.config[ORGANIZATION_MENU]
27+
28+
29+
def allow_html() -> bool:
30+
return tk.config[ALLOW_HTML]
31+
32+
33+
def editor() -> str:
34+
return tk.config[EDITOR]
35+
36+
37+
def enable_organization_pages() -> bool:
38+
return tk.config[ENABLE_ORGANIZATION_PAGES]
39+
40+
41+
def enable_group_pages() -> bool:
42+
return tk.config[ENABLE_GROUP_PAGES]
43+
44+
45+
def revisions_limit() -> int:
46+
return tk.config[REVISIONS_LIMIT]
47+
48+
49+
def force_revisions_limit() -> bool:
50+
return tk.config[FORCE_REVISIONS_LIMIT]
51+
52+
53+
def form() -> str:
54+
return tk.config[FORM]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: 1
2+
groups:
3+
- annotation: ckanext-pages
4+
options:
5+
- key: ckanext.pages.about_menu
6+
type: bool
7+
default: true
8+
description: |
9+
Show About page in the main site navigation.
10+
11+
- key: ckanext.pages.group_menu
12+
type: bool
13+
default: true
14+
description: |
15+
Show Groups page in the main site navigation.
16+
17+
- key: ckanext.pages.organization_menu
18+
type: bool
19+
default: true
20+
description: |
21+
Show Organizations page in the main site navigation.
22+
23+
- key: ckanext.pages.allow_html
24+
type: bool
25+
description: |
26+
Allow HTML in pages. If false, only Markdown is allowed.
27+
28+
- key: ckanext.pages.editor
29+
description: |
30+
The text editor to use for pages(ckeditor, markdown, etc.).
31+
32+
- key: ckanext.pages.organization
33+
type: bool
34+
description: |
35+
Allow organizations to have pages.
36+
37+
- key: ckanext.pages.group
38+
type: bool
39+
description: |
40+
Allow groups to have pages.
41+
42+
- key: ckanext.pages.revisions_limit
43+
type: int
44+
default: 3
45+
description: |
46+
The maximum number of revisions to keep for a page. If set to 0, all revisions will be kept.
47+
48+
- key: ckanext.pages.revisions_force_limit
49+
type: bool
50+
description: |
51+
If true, the revisions limit will be enforced. If false, the limit will be advisory only.
52+
53+
- key: ckanext.pages.form
54+
default: "ckanext_pages/base_form.html"
55+
description: |
56+
The template to use for the page form. This can be overridden by extensions to provide custom forms.

ckanext/pages/db.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44

55
from collections import OrderedDict
6-
from six import text_type
76
import sqlalchemy as sa
87
from sqlalchemy import Column, types
98
from sqlalchemy.orm import class_mapper
@@ -34,7 +33,7 @@
3433

3534

3635
def make_uuid():
37-
return text_type(uuid.uuid4())
36+
return str(uuid.uuid4())
3837

3938

4039
class Page(DomainObject, BaseModel):
@@ -120,7 +119,7 @@ def table_dictize(obj, context, **kw):
120119
elif isinstance(value, list):
121120
result_dict[name] = value
122121
else:
123-
result_dict[name] = text_type(value)
122+
result_dict[name] = str(value)
124123

125124
result_dict.update(kw)
126125

ckanext/pages/plugin.py

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from html import escape as html_escape
44

5-
from six.moves.urllib.parse import quote
5+
from urllib.parse import quote
66

77
from ckan.plugins import toolkit as tk
88

@@ -11,7 +11,7 @@
1111

1212
from ckanext.pages import actions
1313
from ckanext.pages import auth
14-
from ckanext.pages import blueprint
14+
from ckanext.pages import blueprint, config as cfg
1515

1616
from ckan.lib.plugins import DefaultTranslation
1717

@@ -21,10 +21,10 @@
2121

2222
def 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

6464
def 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

6969
def get_wysiwyg_editor():
70-
return tk.config.get('ckanext.pages.editor', '')
70+
return cfg.editor()
7171

7272

7373
def 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
93116
class 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

173165
class TextBoxView(p.SingletonPlugin):
174166

ckanext/pages/tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def clean_db(reset_db, migrate_db_for):
6+
reset_db()
7+
migrate_db_for("pages")

ckanext/pages/tests/fixtures.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)