satchmo_category url reversal issues

Create issue
Issue #1135 resolved
John-Scott Atlakson created an issue

In <<changeset 73f5d2f98b53>> which closed ticket <<issue 977>>, the regex was changed to capture multiple parent category slugs as a single string to pass into the view. For example, with a url of "p1-category/p2-category/category-slug/" it will now capture "p1-category/p2-category/" as the parent_slugs arg whereas before this changeset, it only captured "p2-category/".

Unfortunately this change now requires a dummy parent_slugs arg to be passed in when reversing. This breaks templates that were using {% url satchmo_category slug='my-category-slug' %}. Now you have to pass in {% url satchmo_category parent_slugs='' slug='my-category-slug' %}.

I'm not sure why this was changed given that parent_slugs is totally ignored by the view and to properly reverse this url requires you to pass in a full string like "p1-category/p2-category/", you can't pass in a list of parent slugs.

Anyway, assuming there is some valid use case for keeping this change, the following regex solves my issue while keeping the behavior gained in <<changeset 73f5d2f98b53>>: {{{

!python

r'^(?P<parent_slugs>([-\w]+/)*)?(?P<slug>[-\w]+)/$' }}}

This will still pass in the full "p1-category/p2-category/" to the view but does not require any dummy args when reversing.

Comments (5)

  1. Tay Ray Chuan

    I didn't manage to find any instances where we did a {% url satchmo_category %} resolution without parent_slugs, could you point them out?

    Unless - you're referring to your own templates?

  2. John-Scott Atlakson reporter

    Right, I mean custom templates. I ran into this while trying to upgrade an existing site to the latest release candidate.

  3. Tay Ray Chuan

    There you go.

    I was about to suggest you update your templates, but I think there isn't much to lose by being backward-friendly.

  4. Log in to comment