Opened 5 years ago

Last modified 11 months ago

#13559 assigned New feature

Need a contextprocessor for current site

Reported by: tonnzor Owned by: chrismedrela
Component: contrib.sites Version: master
Severity: Normal Keywords:
Cc: tonn81@…, django@…, min@…, tonnzor, hop, 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@…> 5 years ago.
Adds context processor, enables by default, updates docs, and implements tests
sites_context_processor.diff (14.7 KB) - added by hop 3 years ago.
Updated patch for r17913
13559_v3.diff (13.8 KB) - added by krzysiumed 3 years ago.

Download all attachments as: .zip

Change History (26)

comment:1 Changed 5 years ago by russellm

  • Component changed from Uncategorized to Contrib apps
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

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

comment:2 Changed 5 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 5 years ago by tonnzor

  • Cc tonn81@… added
  • milestone set to 1.3
  • Version changed from 1.2 to SVN

comment:4 Changed 5 years ago by gabrielhurley

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 5 years ago by wogan

  • Cc django@… added

comment:6 Changed 4 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.sites

comment:7 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:8 Changed 4 years ago by julien

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

comment:9 Changed 4 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

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

comment:10 Changed 4 years ago by min@…

  • Cc min@… added
  • UI/UX unset

comment:11 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:12 Changed 3 years ago by tonnzor

  • Cc tonnzor 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 3 years ago by hop

Updated patch for r17913

comment:13 Changed 3 years ago by hop

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 3 years ago by tonnzor

  • Easy pickings set
  • Patch needs improvement unset

Thanks, hop!

patchhammer, could you apply the patch over trunk?

comment:15 Changed 3 years ago by hop

  • Cc hop added

comment:16 Changed 3 years ago by krzysiumed

  • Cc krzysiumed@… added
  • Owner changed from nobody to krzysiumed

Changed 3 years ago by krzysiumed

comment:17 Changed 3 years ago by krzysiumed

  • Easy pickings unset

I did some minor changes in hop's patch:

comment:18 Changed 3 years ago by krzysiumed

  • Status changed from new to assigned

comment:19 Changed 2 years ago by aaugustin

#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 17 months ago by chrismedrela

  • Owner changed from krzysiumed to chrismedrela

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

comment:21 Changed 15 months ago by aaugustin

  • Patch needs improvement set

See my comments on the pull request.

comment:22 Changed 15 months ago by chrismedrela

  • Patch needs improvement unset

comment:23 Changed 11 months ago by timo

  • Patch needs improvement set

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

Note: See TracTickets for help on using tickets.
Back to Top