Opened 15 years ago

Last modified 6 months ago

#13559 assigned New feature

Need a contextprocessor for current site

Reported by: Artem Skoretskiy Owned by: Farhan Ali Raza
Component: contrib.sites Version: dev
Severity: Normal Keywords:
Cc: tonn81@…, django@…, min@…, Artem Skoretskiy, Christoph Schindler, krzysiumed@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If you use Sites app you would need to use current site instance in your templates. For that purpose there should be a ContextProcessor in django.contrib.sites application.

The code is quite simple, but it makes no sense to create and store it in user's application:

from django.contrib.sites.models import Site

def current_site(request):
    return {'SITE': Site.objects.get_current()}

I can provide a patch if needed.

Attachments (3)

django-13559.patch (11.3 KB ) - added by Joshua Ginsberg <jag@…> 15 years ago.
Adds context processor, enables by default, updates docs, and implements tests
sites_context_processor.diff (14.7 KB ) - added by Christoph Schindler 13 years ago.
Updated patch for r17913
13559_v3.diff (13.8 KB ) - added by Christopher Medrela 12 years ago.

Download all attachments as: .zip

Change History (28)

comment:1 by Russell Keith-Magee, 15 years ago

Component: UncategorizedContrib apps
Triage Stage: UnreviewedAccepted

by Joshua Ginsberg <jag@…>, 15 years ago

Attachment: django-13559.patch added

Adds context processor, enables by default, updates docs, and implements tests

comment:2 by Joshua Ginsberg <jag@…>, 15 years ago

Has patch: set

Took a stab at it. Let me know if there are changes that should be made to the patch.

comment:3 by Artem Skoretskiy, 14 years ago

Cc: tonn81@… added
milestone: 1.3
Version: 1.2SVN

comment:4 by Gabriel Hurley, 14 years ago

This patch looks good to me, with the one exception: it probably needs a backwards incompatibility note for those spots where you removed the site variable being manually added to the context. If someone was relying on that variable being available in those specific cases and doesn't add the context processor they're going to find their code is suddenly broken.

comment:5 by Greg Wogan-Browne, 14 years ago

Cc: django@… added

comment:6 by Gabriel Hurley, 14 years ago

Component: Contrib appscontrib.sites

comment:7 by Julien Phalip, 14 years ago

Severity: Normal
Type: New feature

comment:8 by Julien Phalip, 14 years ago

See also #10944 which suggests adding a template tag and a method to the Site class for this.

comment:9 by patchhammer, 14 years ago

Easy pickings: unset
Patch needs improvement: set

django-13559.patch fails to apply cleanly on to trunk

comment:10 by min@…, 13 years ago

Cc: min@… added
UI/UX: unset

comment:11 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:12 by Artem Skoretskiy, 13 years ago

Cc: Artem Skoretskiy added

Joshua Ginsberg, could you please update your patch to match current trunk?

I got no luck applying it to the revision given in patch file as well..

by Christoph Schindler, 13 years ago

Updated patch for r17913

comment:13 by Christoph Schindler, 13 years ago

I updated the patch to apply against current trunk.

Had to fix the unit test as well, but I'm not entirely sure it's OK.

comment:14 by Artem Skoretskiy, 13 years ago

Easy pickings: set
Patch needs improvement: unset

Thanks, hop!

patchhammer, could you apply the patch over trunk?

comment:15 by Christoph Schindler, 13 years ago

Cc: Christoph Schindler added

comment:16 by Christopher Medrela, 12 years ago

Cc: krzysiumed@… added
Owner: changed from nobody to Christopher Medrela

by Christopher Medrela, 12 years ago

Attachment: 13559_v3.diff added

comment:17 by Christopher Medrela, 12 years ago

Easy pickings: unset

I did some minor changes in hop's patch:

comment:18 by Christopher Medrela, 12 years ago

Status: newassigned

comment:19 by Aymeric Augustin, 12 years ago

#17005 is about adding a middleware for the same purpose in views.

With that middleware and the request context processor, the current site will be available in {{ request.site }}, but that doesn't rule out a specific context processor in case you don't want the site middleware or the request context processor.

comment:20 by chrismedrela, 11 years ago

Owner: changed from Christopher Medrela to chrismedrela

I've updated the patch: https://github.com/django/django/pull/1938. BTW, krzysiumed is my old nick.

comment:21 by Aymeric Augustin, 11 years ago

Patch needs improvement: set

See my comments on the pull request.

comment:22 by chrismedrela, 11 years ago

Patch needs improvement: unset

comment:23 by Tim Graham, 11 years ago

Patch needs improvement: set

I left comments for improvement on PR. Please uncheck "Patch needs improvement" when you update it, thanks.

comment:24 by Mariusz Felisiak, 3 years ago

Owner: chrismedrela removed
Status: assignednew

comment:25 by Farhan Ali, 6 months ago

Owner: set to Farhan Ali Raza
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top