New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow predicate values to participate in view weighting #1863

Open
mmerickel opened this Issue Jul 30, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@mmerickel
Member

mmerickel commented Jul 30, 2015

Copied from a paste in #pyramid irc:

@view_config(
    name='example',
    renderer='example_v2.mako',
    request_param=('foo', 'version=2'))
@view_config(
    name='example',
    renderer='example.mako',
    request_param='foo')
def example_view(self):
  return {}

# >>> GET /example
# HTTP 404 as expected, `foo` parameter not provided

# >>> GET /example?foo
# This renders the example.mako template

# >>> GET /example?foo&version=2
# This renders the example.mako template. Would want the example_v2.mako template
# to render, as it fits -all- of its request_params, which provide for a stricter match.

# N.B. Shuffling view_config statements around provides a solution, the following does
# follow my expectations, though relies on order in code, which I'd like to avoid:


@view_config(
    name='example',
    renderer='example.mako',
    request_param='foo')
@view_config(
    name='example',
    renderer='example_v2.mako',
    request_param=('foo', 'version=2'))
def example_view(self):
  return {}

Basically the two views have different values for their request_param predicate but they do not conflict and are ambiguously ordered. This strategy only works if the predicate values are mutually exclusive such that no value in one view is a subset of values in another view.

We should add a new sortable attribute to predicates or use the phash itself to contribute to the weighting such that 2 views with the same predicate but different values can be sorted appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment