#14385 closed (duplicate)
Standardize Site/RequestSite access; looser coupling of sites framework in contrib
| Reported by: | Gabriel Hurley | Owned by: | Gabriel Hurley | 
|---|---|---|---|
| Component: | Contrib apps | Version: | dev | 
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
A few days ago I started this thread on the Django Developers list in order to solve a number of tickets at the same time. The gist:
All of these tickets relate to needing access to the current domain, whether that's through a Site instance, or through a RequestSite instance. To facilitate this, the provided patch adds a utility function, django.contrib.sites.models.get_current_site which takes a request as an argument and returns either a Site or RequestSite instance.
Using that utility function, a lot of repetitious code could be removed and streamlined, and several tickets were trivial to resolve.
Included in this patch:
- Adds the django.contrib.sites.models.get_current_sitefunction.
- Provides a note in the contrib.sites docs regarding the function.
- Converts to contrib.sites tests from doctests to unit tests and adds a test for get_current_site
- Resolves #8960 by allowing django.contrib.contenttypes.views.shortcutto use either a Site or RequesSite object.
- Converts contrib.contenttypes tests from doctests to unit tests and adds a test for #8960.
- Resolves #10235 and #10909 by using get_current_sitein the Sitemaps framework.
- Adds test case for #10235/#10909.
- Updates django.contrib.syndication.viewsto use `get_current_site.
- Updates django.contrib.gis.sitemaps.viewsto useget_current_siteas per #10608.
- Updates django.contrib.auth.views.loginto useget_current_site.
The patch passes the full test suite under WinXP/Py2.6/SQLite.
This patch would completely fix #8960, #10235, and #10909. The remainder of #10608 is actually invalid, because the remaining places where contrib apps rely on contrib.sites the model has a direct relation to Site, or there is no way to access a request object to use RequestSite. Any further decoupling in contrib would require backwards-incompatible rewrites.
Duplicate of #14386... Trac is being buggy at the moment :-/