Standardize Site/RequestSite access; looser coupling of sites framework in contrib
|Reported by:||gabrielhurley||Owned by:||gabrielhurley|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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_site function.
- 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.shortcut to 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_site in the Sitemaps framework.
- Adds test case for #10235/#10909.
- Updates django.contrib.syndication.views to use `get_current_site.
- Updates django.contrib.gis.sitemaps.views to use get_current_site as per #10608.
- Updates django.contrib.auth.views.login to use get_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.
Change History (10)
comment:1 Changed 6 years ago by gabrielhurley
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Status changed from new to assigned
Changed 6 years ago by gabrielhurley
comment:4 Changed 6 years ago by lukeplant
- Resolution set to fixed
- Status changed from assigned to closed