Opened 14 years ago
Last modified 5 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)
Change History (28)
comment:1 by , 14 years ago
Component: | Uncategorized → Contrib apps |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 14 years ago
Attachment: | django-13559.patch added |
---|
comment:2 by , 14 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 , 14 years ago
Cc: | added |
---|---|
milestone: | → 1.3 |
Version: | 1.2 → SVN |
comment:4 by , 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 , 14 years ago
Cc: | added |
---|
comment:6 by , 14 years ago
Component: | Contrib apps → contrib.sites |
---|
comment:7 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:8 by , 14 years ago
See also #10944 which suggests adding a template tag and a method to the Site class for this.
comment:9 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
django-13559.patch fails to apply cleanly on to trunk
comment:10 by , 13 years ago
Cc: | added |
---|---|
UI/UX: | unset |
comment:12 by , 13 years ago
Cc: | 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..
comment:13 by , 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 , 13 years ago
Easy pickings: | set |
---|---|
Patch needs improvement: | unset |
Thanks, hop!
patchhammer, could you apply the patch over trunk?
comment:15 by , 13 years ago
Cc: | added |
---|
comment:16 by , 12 years ago
Cc: | added |
---|---|
Owner: | changed from | to
by , 12 years ago
Attachment: | 13559_v3.diff added |
---|
comment:17 by , 12 years ago
Easy pickings: | unset |
---|
I did some minor changes in hop's patch:
- Repaired a few broken links at /ref/contrib/sites.txt doc.
- Added note at /ref/settings/#template-context-processors.
- Sites tests used django.views.generic.simple.direct_to_template function which comes from old function-based generic views which were permanently deleted. This made some tests broken. django.view.generic.TemplateView is used now and all tests pass.
- Refactored context processors' tests -- joined
ContextProcessorTest
andRequestSiteContextTest
, tests use django.test.utils.override_settings instead of overriding settings insetUp
andtearDown
. - Formatted in PEP8 style.
comment:18 by , 12 years ago
Status: | new → assigned |
---|
comment:19 by , 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 , 11 years ago
Owner: | changed from | to
---|
I've updated the patch: https://github.com/django/django/pull/1938. BTW, krzysiumed is my old nick.
comment:22 by , 11 years ago
Patch needs improvement: | unset |
---|
comment:23 by , 10 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 , 3 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:25 by , 5 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
Adds context processor, enables by default, updates docs, and implements tests