[Sugestion] Redirect based on schema name
- Dominant language
- Python
- Stars
- 102
- Forks
- 182
- PR merge metrics
- No merged PRs in 30d
Description
I didn't know if this feature already exist, so I created a redir for my schemas.
For example:
- Create the schema called "application".
- Create package called "pokemon-go".
- If I go to http://ckan/dataset/pokemon-go will redirect to http://ckan/application/pokemon-go
I use the event "before_view".
Here the code:
```
def before_view(self, pkg_dict):
# Redirect to correct URL based on schema name
schema_expected = pkg_dict['type']
schema_current = str(h.full_current_url()).replace(g.site_url, '').split('/')[1]
if (schema_current != schema_expected):
actions_accepted = ['read','edit','new']
if (c.action in actions_accepted and c.controller=='package'):
from pylons.controllers.util import redirect
url_current = h.full_current_url()
url_current = str(url_current).replace(g.site_url+'/'+schema_current, g.site_url+'/'+schema_expected)
# print('redir_to',url_current)
# print(schema_expected)
# print(schema_current)
redirect(url_current.replace(g.site_url,''))
return pkg_dict
```
See ya.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the before_view hook and redirect example included in the issue, then inspect how CKAN package actions and schema names are routed. Verify the behavior for the package read, edit, and new actions, including URLs whose schema already matches. Done means the requested schema-based redirect works without breaking normal package navigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100