Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added RequestSite class to sites framework

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5653 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dcd5750d7ac6692428e431010772f1941406d576 1 parent 06fc225
@adrianholovaty adrianholovaty authored
Showing with 35 additions and 0 deletions.
  1. +17 −0 django/contrib/sites/models.py
  2. +18 −0 docs/sites.txt
View
17 django/contrib/sites/models.py
@@ -26,3 +26,20 @@ class Admin:
def __unicode__(self):
return self.domain
+
+class RequestSite(object):
+ """
+ A class that shares the primary interface of Site (i.e., it has
+ ``domain`` and ``name`` attributes) but gets its data from a Django
+ HttpRequest object rather than from a database.
+
+ The save() and delete() methods raise NotImplementedError.
+ """
+ def __init__(self, request):
+ self.domain = self.name = request.META['SERVER_NAME']
+
+ def save(self):
+ raise NotImplementedError('RequestSite cannot be saved.')
+
+ def delete(self):
+ raise NotImplementedError('RequestSite cannot be deleted.')
View
18 docs/sites.txt
@@ -320,3 +320,21 @@ Here's how Django uses the sites framework:
.. _flatpages framework: ../flatpages/
.. _syndication framework: ../syndication/
.. _authentication framework: ../authentication/
+
+``RequestSite`` objects
+=======================
+
+**New in Django development version**
+
+Some ``django.contrib`` applications take advantage of the sites framework but
+are architected in a way that doesn't *require* the sites framework to be
+installed in your database. (Some people don't want to, or just aren't *able*
+to install the extra database table that the sites framework requires.) For
+those cases, the framework provides a ``RequestSite`` class, which can be used
+as a fallback when the database-backed sites framework is not available.
+
+A ``RequestSite`` object has a similar interface to a normal ``Site`` object,
+except its ``__init__()`` method takes an ``HttpRequest`` object. It's able to
+deduce the ``domain`` and ``name`` by looking at the request's domain. It has
+``save()`` and ``delete()`` methods to match the interface of ``Site``, but
+the methods raise ``NotImplementedError``.
Please sign in to comment.
Something went wrong with that request. Please try again.