Skip to content

Reversing press URLs on journal sites in path mode #4577

Description

@joemull

Problem description

When forming Janeway URLs in path mode, the press level of a site is often identified by the absence of a journal code, rather than the presence of a key or argument or path segment.

As a result, there is currently no way to dynamically build a named URL at the press level when working within the context of a journal page. This makes it difficult to create journal-level interfaces that refer to press interfaces and guide users between them.

Example:

<p> Note: This page lists all users with a role in
<i>{{ request.journal.name }}</i>. If a broader search is needed,
try <a href="{{ request.press.url }}/user/all/">All Users
at the press level</a>.</p>
{% comment %} The above URL is hardcoded because there is no other
way to form a press URL on a journal page at the moment. {% endcomment %}

You can do request.press.site_url or journal.press.site_url in most cases, but these are just context variables pointing to the press landing page. They do not take arguments and so cannot be used to reverse named urls.

The template tag site_url also does not work because, on path mode, it prepends the journal code.

@register.simple_tag(takes_context=True)
def site_url(context, url_name=None, *args):
request = context.get('request')
if url_name is not None:
path = reverse(url_name, args=args)
else:
path = None
if request and request.site_type:
return request.site_type.site_url(path=path)
else:
return path

This means the formed URL will always refer back to the journal. If you do {% site_url "press_all_users" %} that will just put out example.org/JOURNAL/press/user/all.

Proposed solution

An additional template tag press_url that allows you to reverse any press url, regardless of current page / request context. It could be used like this:

If a broader search is needed,
          try <a href="{% press_url 'press_all_users' %}">All Users
          at the press level</a>.

Alternative considered

An additional argument on the site_url template tag for a boolean called press. If True, the tag will use press as the site_type rather than the site_type of the request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions