Skip to content

Commit

Permalink
Merge pull request #7923 from JVickery-TBS/fix/pluggable-helpers-for-…
Browse files Browse the repository at this point in the history
…views

Use Pluggable Helpers for Views
  • Loading branch information
smotornyuk committed Nov 24, 2023
2 parents b4f9014 + 77e2149 commit 60faa6b
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions changes/7923.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
View modules use pluggable `ckan.plugins.toolkit.h` instead of `ckan.lib.helpers`
2 changes: 1 addition & 1 deletion ckan/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import ckan.lib.app_globals as app_globals
import ckan.lib.base as base
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.logic as logic
import ckan.model as model
Expand Down
4 changes: 2 additions & 2 deletions ckan/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask import Blueprint

import ckan.lib.base as base
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
from ckan.common import _, current_user
from ckan.views.user import _extra_template_variables
from ckan.types import Context
Expand All @@ -24,7 +24,7 @@ def before_request() -> None:

# flask types do not mention that it's possible to return a response
# from the `before_request` callback
return h.redirect_to(u'user.login') # type: ignore
return h.redirect_to(u'user.login')
return None


Expand Down
15 changes: 8 additions & 7 deletions ckan/views/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from ckan.common import asbool, current_user

import ckan.lib.base as base
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
from ckan.lib.helpers import Page
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.logic as logic
import ckan.model as model
Expand Down Expand Up @@ -315,7 +316,7 @@ def search(package_type: str) -> str:

extra_vars[u'sort_by_selected'] = query[u'sort']

extra_vars[u'page'] = h.Page(
extra_vars[u'page'] = Page(
collection=query[u'results'],
page=page,
url=pager_url,
Expand All @@ -341,7 +342,7 @@ def search(package_type: str) -> str:
log.error(u'Dataset search error: %r', se.args)
extra_vars[u'query_error'] = True
extra_vars[u'search_facets'] = {}
extra_vars[u'page'] = h.Page(collection=[])
extra_vars[u'page'] = Page(collection=[])

# FIXME: try to avoid using global variables
g.search_facets_limits = {}
Expand Down Expand Up @@ -643,7 +644,7 @@ def get(self,
)
)
)
resources_json = h.json.dumps(data.get(u'resources', []))
resources_json = h.dump_json(data.get(u'resources', []))
# convert tags if not supplied in data
if data and not data.get(u'tag_string'):
data[u'tag_string'] = u', '.join(
Expand Down Expand Up @@ -676,7 +677,7 @@ def get(self,
u'dataset_type': package_type,
u'form_style': u'new'
}
errors_json = h.json.dumps(errors)
errors_json = h.dump_json(errors)

# TODO: remove
g.resources_json = resources_json
Expand Down Expand Up @@ -787,7 +788,7 @@ def get(self,
)

pkg = context.get(u"package")
resources_json = h.json.dumps(data.get(u'resources', []))
resources_json = h.dump_json(data.get(u'resources', []))
user = current_user.name
try:
check_access(
Expand Down Expand Up @@ -817,7 +818,7 @@ def get(self,
u'dataset_type': package_type,
u'form_style': u'edit'
}
errors_json = h.json.dumps(errors)
errors_json = h.dump_json(errors)

# TODO: remove
g.pkg = pkg
Expand Down
5 changes: 3 additions & 2 deletions ckan/views/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from dateutil.tz import tzutc
from feedgen.feed import FeedGenerator
from ckan.common import _, config, request, current_user
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
from ckan.lib.helpers import _url_with_params
import ckan.lib.base as base
import ckan.logic as logic
import ckan.plugins as plugins
Expand Down Expand Up @@ -394,7 +395,7 @@ def custom() -> Response:

feed_url = _feed_url(request.args, controller=u'feeds', action=u'custom')

atom_url = h._url_with_params(u'/feeds/custom.atom', search_params.items())
atom_url = _url_with_params(u'/feeds/custom.atom', search_params.items())

alternate_url = _alternate_url(request.args)
site_title = config.get(u'ckan.site_title')
Expand Down
11 changes: 6 additions & 5 deletions ckan/views/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from codecs import BOM_UTF8

import ckan.lib.base as base
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
from ckan.lib.helpers import Page
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.logic as logic
import ckan.lib.search as search
Expand Down Expand Up @@ -180,7 +181,7 @@ def index(group_type: str, is_organization: bool) -> str:
else:
msg = str(e)
h.flash_error(msg)
extra_vars["page"] = h.Page([], 0)
extra_vars["page"] = Page([], 0)
extra_vars["group_type"] = group_type
return base.render(
_get_group_template(u'index_template', group_type), extra_vars)
Expand All @@ -198,7 +199,7 @@ def index(group_type: str, is_organization: bool) -> str:
}
page_results = _action(u'group_list')(context, data_dict_page_results)

extra_vars["page"] = h.Page(
extra_vars["page"] = Page(
collection=global_results,
page=page,
url=h.pager_url,
Expand Down Expand Up @@ -342,9 +343,9 @@ def pager_url(q: Any = None, page: Optional[int] = None):
except search.SearchError as se:
log.error(u'Group search error: %r', se.args)
extra_vars["query_error"] = True
extra_vars["page"] = h.Page(collection=[])
extra_vars["page"] = Page(collection=[])
else:
extra_vars["page"] = h.Page(
extra_vars["page"] = Page(
collection=query['results'],
page=page,
url=pager_url,
Expand Down
2 changes: 1 addition & 1 deletion ckan/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import ckan.logic as logic
import ckan.lib.base as base
import ckan.lib.search as search
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h

from ckan.common import g, config, current_user, _
from ckan.types import Context, Response
Expand Down
2 changes: 1 addition & 1 deletion ckan/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import ckan.lib.base as base
import ckan.lib.datapreview as lib_datapreview
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.lib.uploader as uploader
import ckan.logic as logic
Expand Down
5 changes: 3 additions & 2 deletions ckan/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import ckan.lib.authenticator as authenticator
import ckan.lib.base as base
import ckan.lib.captcha as captcha
from ckan.lib.helpers import helper_functions as h
from ckan.lib.helpers import Page
from ckan.lib.dictization import model_dictize
import ckan.lib.helpers as h
import ckan.lib.mailer as mailer
import ckan.lib.maintain as maintain
import ckan.lib.navl.dictization_functions as dictization_functions
Expand Down Expand Up @@ -117,7 +118,7 @@ def index():
users_list.limit(limit).offset(offset)
]

page = h.Page(
page = Page(
collection=users,
page=page_number,
presliced_list=True,
Expand Down
2 changes: 1 addition & 1 deletion ckan/views/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask import Blueprint

import ckan.lib.base as base
import ckan.lib.helpers as h
from ckan.lib.helpers import helper_functions as h
from ckan.common import _, request
from ckan.types import Response

Expand Down
3 changes: 1 addition & 2 deletions ckanext/stats/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from flask import Blueprint

from ckan.plugins.toolkit import render
import ckan.lib.helpers as h
from ckan.plugins.toolkit import render, h
import ckanext.stats.stats as stats_lib


Expand Down

0 comments on commit 60faa6b

Please sign in to comment.