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)
Change History (27)
comment:1 Changed 13 years ago by
Component: | Uncategorized → Contrib apps |
---|---|
Triage Stage: | Unreviewed → Accepted |
Changed 13 years ago by
Attachment: | django-13559.patch added |
---|
comment:2 Changed 13 years ago by
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
Cc: | tonn81@… added |
---|---|
milestone: | → 1.3 |
Version: | 1.2 → SVN |
comment:4 Changed 13 years ago by
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
Cc: | django@… added |
---|
comment:6 Changed 13 years ago by
Component: | Contrib apps → contrib.sites |
---|
comment:7 Changed 13 years ago by
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:8 Changed 12 years ago by
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
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
django-13559.patch fails to apply cleanly on to trunk
comment:10 Changed 12 years ago by
Cc: | min@… added |
---|---|
UI/UX: | unset |
comment:12 Changed 12 years ago by
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..
comment:13 Changed 11 years ago by
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
Easy pickings: | set |
---|---|
Patch needs improvement: | unset |
Thanks, hop!
patchhammer, could you apply the patch over trunk?
comment:15 Changed 11 years ago by
Cc: | Christoph Schindler added |
---|
comment:16 Changed 11 years ago by
Cc: | krzysiumed@… added |
---|---|
Owner: | changed from nobody to Christopher Medrela |
Changed 11 years ago by
Attachment: | 13559_v3.diff added |
---|
comment:17 Changed 11 years ago by
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 Changed 11 years ago by
Status: | new → assigned |
---|
comment:19 Changed 11 years ago by
#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
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
Patch needs improvement: | set |
---|
See my comments on the pull request.
comment:22 Changed 10 years ago by
Patch needs improvement: | unset |
---|
comment:23 Changed 9 years ago by
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
Owner: | chrismedrela deleted |
---|---|
Status: | assigned → new |
Adds context processor, enables by default, updates docs, and implements tests