FYI i ended up basically created a custom {% url %} tag, which is a
wrapper for the django standard url tag, but which adds the org_slug
as a parameter.  Its a bit hacky/magical but saved me a bunch of
time.  If any one runs into this issue, email me and I can show you
what I did.

On Jul 8, 4:38 pm, br <robert...@gmail.com> wrote:
>  Here's a snippet from my base urls.py:
>
>     (r'^(?P<org_slug>[\w-]+)/manager/mobile/',
>         include('mobilepolls.manager.urls')),
>     (r'^(?P<org_slug>[\w-]+)/manager/display/',
>         include('screens.manager.urls')),
>     (r'^(?P<org_slug>[\w-]+)/display/', include ('screens.urls')),
>
> Each of those apps then defines its own urls.py with various different
> url patterns.
>
> My problem is that I'm having to repeat the following:
>           {% url . . .  org_slug=organization.slug %}
>
> nearly everywhere I ever use a url tag in a template (probably 50x or
> more), because the org_slug is ubiquitous in almost all urls, but is
> always just retreived from the current user's organization. Doesn't
> seem very DRY and is a bit error-prone.  Is there anyway to automate
> this with a custom tag or middleware or something so that i can just
> assume that "org_slug=organization.slug" part of each url tag or add
> it if there is a org_slug regex param in the url?
>
> Background: We recently added organizations in our application to
> provide a single-DB multi-tenancy of sorts.  A user's organization is
> reflected in most of the URL's he/she navigates to.  As a shortcut to
> not always have to access the organization via the
> user.get_profile().organization, I add the current organization (which
> is just a lazy functional reference to a user profile object's
> organization property) to the request via middleware and to each
> request context via a context processor .
>
> Thanks,
>
> Ben

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to