Opened 13 years ago

Last modified 2 years ago

#13559 new New feature

Need a contextprocessor for current site

Reported by: Artem Skoretskiy Owned by:
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@…> 13 years ago.
Adds context processor, enables by default, updates docs, and implements tests
sites_context_processor.diff (14.7 KB) - added by Christoph Schindler 11 years ago.
Updated patch for r17913
13559_v3.diff (13.8 KB) - added by Christopher Medrela 11 years ago.

Download all attachments as: .zip

Change History (27)

comment:1 Changed 13 years ago by Russell Keith-Magee

Component: UncategorizedContrib apps
Triage Stage: UnreviewedAccepted

Changed 13 years ago by Joshua Ginsberg <jag@…>

Attachment: django-13559.patch added

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

comment:2 Changed 13 years ago by Joshua Ginsberg <jag@…>

Has patch: set

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

comment:3 Changed 13 years ago by Artem Skoretskiy

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

comment:4 Changed 13 years ago by Gabriel Hurley

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 Changed 13 years ago by Greg Wogan-Browne

Cc: django@… added

comment:6 Changed 13 years ago by Gabriel Hurley

Component: Contrib appscontrib.sites

comment:7 Changed 13 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:8 Changed 12 years ago by Julien Phalip

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

comment:9 Changed 12 years ago by patchhammer

Easy pickings: unset
Patch needs improvement: set

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

comment:10 Changed 12 years ago by min@…

Cc: min@… added
UI/UX: unset

comment:11 Changed 12 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:12 Changed 12 years ago by Artem Skoretskiy

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..

Changed 11 years ago by Christoph Schindler

Updated patch for r17913

comment:13 Changed 11 years ago by Christoph Schindler

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 Changed 11 years ago by Artem Skoretskiy

Easy pickings: set
Patch needs improvement: unset

Thanks, hop!

patchhammer, could you apply the patch over trunk?

comment:15 Changed 11 years ago by Christoph Schindler

Cc: Christoph Schindler added

comment:16 Changed 11 years ago by Christopher Medrela

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

Changed 11 years ago by Christopher Medrela

Attachment: 13559_v3.diff added

comment:17 Changed 11 years ago by Christopher Medrela

Easy pickings: unset

I did some minor changes in hop's patch:

comment:18 Changed 11 years ago by Christopher Medrela

Status: newassigned

comment:19 Changed 11 years ago by Aymeric Augustin

#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 Changed 10 years ago by chrismedrela

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 Changed 10 years ago by Aymeric Augustin

Patch needs improvement: set

See my comments on the pull request.

comment:22 Changed 10 years ago by chrismedrela

Patch needs improvement: unset

comment:23 Changed 9 years ago by Tim Graham

Patch needs improvement: set

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

comment:24 Changed 2 years ago by Mariusz Felisiak

Owner: chrismedrela deleted
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top