Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
b22d6c47
Kaydet (Commit)
b22d6c47
authored
Kas 18, 2013
tarafından
Christopher Medrela
Kaydeden (comit)
Tim Graham
Şub 06, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #17005 -- Added CurrentSiteMiddleware to set the current site on each request.
Thanks jordan at aace.org for the suggestion.
üst
c43c469a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
0 deletions
+60
-0
middleware.py
django/contrib/sites/middleware.py
+10
-0
tests.py
django/contrib/sites/tests.py
+11
-0
sites.txt
docs/ref/contrib/sites.txt
+20
-0
middleware.txt
docs/ref/middleware.txt
+13
-0
1.7.txt
docs/releases/1.7.txt
+6
-0
No files found.
django/contrib/sites/middleware.py
0 → 100644
Dosyayı görüntüle @
b22d6c47
from
.models
import
Site
class
CurrentSiteMiddleware
(
object
):
"""
Middleware that sets `site` attribute to request object.
"""
def
process_request
(
self
,
request
):
request
.
site
=
Site
.
objects
.
get_current
()
django/contrib/sites/tests.py
Dosyayı görüntüle @
b22d6c47
...
...
@@ -5,6 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError
from
django.http
import
HttpRequest
from
django.test
import
TestCase
,
modify_settings
,
override_settings
from
.middleware
import
CurrentSiteMiddleware
from
.models
import
Site
from
.requests
import
RequestSite
from
.shortcuts
import
get_current_site
...
...
@@ -79,3 +80,13 @@ class SitesFrameworkTests(TestCase):
self
.
assertRaises
(
ValidationError
,
site
.
full_clean
)
site
.
domain
=
"test
\n
test"
self
.
assertRaises
(
ValidationError
,
site
.
full_clean
)
class
MiddlewareTest
(
TestCase
):
def
test_request
(
self
):
""" Makes sure that the request has correct `site` attribute. """
middleware
=
CurrentSiteMiddleware
()
request
=
HttpRequest
()
middleware
.
process_request
(
request
)
self
.
assertEqual
(
request
.
site
.
id
,
settings
.
SITE_ID
)
docs/ref/contrib/sites.txt
Dosyayı görüntüle @
b22d6c47
...
...
@@ -373,6 +373,26 @@ your admin site to have access to all objects (not just site-specific
ones), put ``objects = models.Manager()`` in your model, before you
define :class:`~django.contrib.sites.managers.CurrentSiteManager`.
.. _site-middleware:
Site middleware
===============
.. versionadded:: 1.7
If you often use this pattern::
from django.contrib.sites.models import Site
def my_view(request):
site = Site.objects.get_current()
...
there is simple way to avoid repetitions. Add
:class:`django.contrib.site.middleware.CurrentSiteMiddleware` to
:setting:`MIDDLEWARE_CLASSES`. The middleware sets the ``site`` attribute on
every request object, so you can use ``request.site`` to get the current site.
How Django uses the sites framework
===================================
...
...
docs/ref/middleware.txt
Dosyayı görüntüle @
b22d6c47
...
...
@@ -179,6 +179,19 @@ Session middleware
Enables session support. See the :doc:`session documentation
</topics/http/sessions>`.
Site middleware
---------------
.. module:: django.contrib.site.middleware
:synopsis: Site middleware.
.. class:: CurrentSiteMiddleware
.. versionadded:: 1.7
Adds the ``site`` attribute representing the current site to every incoming
``HttpRequest`` object. See the :ref:`sites documentation <site-middleware>`.
Authentication middleware
-------------------------
...
...
docs/releases/1.7.txt
Dosyayı görüntüle @
b22d6c47
...
...
@@ -358,6 +358,12 @@ Minor features
:class:`~django.middleware.http.ConditionalGetMiddleware` to handle
conditional ``GET`` requests for sitemaps which set ``lastmod``.
:mod:`django.contrib.sites`
^^^^^^^^^^^^^^^^^^^^^^^^^^^
* The new :class:`django.contrib.site.middleware.CurrentSiteMiddleware` allows
setting the current site on each request.
:mod:`django.contrib.staticfiles`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment