Skip to content

Commit

Permalink
Merge pull request ckan#32 from ckan/restore_routes
Browse files Browse the repository at this point in the history
Restore report.org route and reports redirect
  • Loading branch information
Zharktas authored Feb 7, 2023
2 parents bac3dc6 + 29b7faf commit ea3e1c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions ckanext/report/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
report = Blueprint(u'report', __name__)


def redirect_to_index():
return t.redirect_to(t.url_for('report.index'))


def index():
try:
reports = t.get_action('report_list')({}, {})
Expand Down Expand Up @@ -46,15 +50,20 @@ def view(report_name, organization=None, refresh=False):
org = report['option_defaults'].get('organization')
if org:
# org is not supplied, but this report has a default value
return t.redirect_to(t.url_for('report.view', report_name=report_name, organization=org, **args))
return t.redirect_to(t.url_for('report.org', report_name=report_name, organization=org, **args))

org_in_params = t.request.args.get('organization')
if org_in_params:
# organization should only be in the url - let the param overwrite
# the url.
# remove organization form arguments
# remove organization from form arguments
args = {k: v for k, v in args.items(multi=True) if k != 'organization'}
return t.redirect_to(t.url_for('report.org', report_name=report_name, organization=org_in_params, **args))

elif org_in_params == "":
# remove empty organization from form arguments
args = {k: v for k, v in args.items(multi=True) if k != 'organization'}
return t.redirect_to(t.url_for('report.view', report_name=report_name, organization=org_in_params, **args))
return t.redirect_to(t.url_for('report.view', report_name=report_name, **args))

# options
options = Report.add_defaults_to_options(t.request.args, report['option_defaults'])
Expand Down Expand Up @@ -154,8 +163,9 @@ def view(report_name, organization=None, refresh=False):


report.add_url_rule(u'/report', view_func=index)
report.add_url_rule(u'/reports', 'reports', view_func=redirect_to_index)
report.add_url_rule(u'/report/<report_name>', view_func=view, methods=['GET', 'POST'])
report.add_url_rule(u'/report/<report_name>/<organization>', view_func=view)
report.add_url_rule(u'/report/<report_name>/<organization>', 'org', view_func=view)


def get_blueprints():
Expand Down
2 changes: 1 addition & 1 deletion ckanext/report/templates/report/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block breadcrumb_content %}
<li>{{ h.nav_link(_('Reports'), named_route='report.index') }}</li>
<li>{{ h.nav_link(report.title, named_route='report.view' if '/organization' in request.environ.get('PATH_INFO', '') else 'report.view', report_name=report_name) }}</li>
<li>{{ h.nav_link(report.title, named_route='report.view', report_name=report_name) }}</li>
{% endblock%}

{% block primary_content_inner %}
Expand Down

0 comments on commit ea3e1c1

Please sign in to comment.