Skip to content

Commit cde1a74

Browse files
committed
removal(dev): resource controller;
- Do not use resource controller interface.
1 parent 3ade246 commit cde1a74

File tree

2 files changed

+6
-51
lines changed

2 files changed

+6
-51
lines changed

ckanext/language_domains/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
def _get_domain_index(current_domain: str, language_domains: Dict[str, str]) -> int:
2020
for _lang_code, lang_domains in language_domains.items():
21-
for index, domain in enumerate(lang_domains):
22-
if current_domain == domain:
23-
return index
21+
try:
22+
return lang_domains.index(current_domain)
23+
except ValueError:
24+
return 0
2425
return 0
2526

2627

@@ -152,8 +153,8 @@ def local_url(url_to_amend: str, **kw: Any):
152153
root_paths = json.loads(root_paths)
153154
root_path = root_paths.get(host, '').rstrip('/')
154155
if root_path:
155-
# FIXME this can be written better once the merge
156-
# into the ecportal core is done - Toby
156+
# FIXME this can be written better once
157+
# the merge into the portal core is done
157158
# we have a special root specified so use that
158159
if default_locale:
159160
root_path = re.sub('/{{LANG}}', '', root_path)

ckanext/language_domains/plugin.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class LanguageDomainsPlugin(plugins.SingletonPlugin):
2323
plugins.implements(plugins.IConfigurer)
2424
plugins.implements(plugins.ITemplateHelpers)
2525
plugins.implements(plugins.IBlueprint)
26-
plugins.implements(plugins.IResourceController, inherit=True)
2726

2827
# IMiddleware
2928
def make_middleware(self, app: CKANApp, config: 'CKANConfig') -> CKANApp:
@@ -50,51 +49,6 @@ def get_helpers(self) -> Dict[str, Callable[..., Any]]:
5049
def get_blueprint(self) -> List[Blueprint]:
5150
return [language_domain_views]
5251

53-
# IResourceController
54-
def before_resource_show(self, resource_dict: Dict[str, Any]) -> Dict[str, Any]:
55-
# FIXME: is there a better way to store res_url in SOLR to prevent this
56-
# for everytime a Resource is shown???
57-
language_domains = plugins.toolkit.config.get(
58-
'ckanext.language_domains.domain_map', '')
59-
if not language_domains:
60-
language_domains = {}
61-
else:
62-
language_domains = json.loads(language_domains)
63-
64-
try:
65-
current_language = plugins.toolkit.h.lang()
66-
current_domain = plugins.toolkit.request.url
67-
uri_parts = urlsplit(current_domain)
68-
current_domain = uri_parts.netloc
69-
_scheme, _host = helpers._get_correct_language_domain()
70-
except RuntimeError:
71-
current_language = 'en'
72-
default_domain = plugins.toolkit.config.get('ckan.site_url', '')
73-
uri_parts = urlsplit(default_domain)
74-
current_domain = _host = uri_parts.netloc
75-
_scheme = uri_parts.scheme
76-
77-
domain_index_match = helpers._get_domain_index(
78-
current_domain, language_domains)
79-
80-
for lang_code, lang_domains in language_domains.items():
81-
if (
82-
resource_dict.get('url', '').startswith(
83-
f'{_scheme}://{lang_domains[domain_index_match]}') and
84-
_host != lang_domains[domain_index_match]
85-
):
86-
uri_parts = urlsplit(resource_dict['url'])
87-
path = str(uri_parts.path)
88-
if path.startswith(f'/{lang_code}/'):
89-
path = path[len(f'/{lang_code}'):]
90-
elif path.startswith(f'/{current_language}/'):
91-
path = path[len(f'/{current_language}'):]
92-
resource_dict['url'] = uri_parts._replace(
93-
netloc=_host, path=path).geturl()
94-
break
95-
96-
return resource_dict
97-
9852

9953
class LanguageDomainMiddleware(object):
10054
def __init__(self, app: Any, config: 'CKANConfig'):

0 commit comments

Comments
 (0)