Browse files

Added RequestSite class to sites framework

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 06fc225 commit dcd5750d7ac6692428e431010772f1941406d576 @adrianholovaty adrianholovaty committed Jul 12, 2007
Showing with 35 additions and 0 deletions.
  1. +17 −0 django/contrib/sites/
  2. +18 −0 docs/sites.txt
@@ -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 = = request.META['SERVER_NAME']
+ def save(self):
+ raise NotImplementedError('RequestSite cannot be saved.')
+ def delete(self):
+ raise NotImplementedError('RequestSite cannot be deleted.')
@@ -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``.

0 comments on commit dcd5750

Please sign in to comment.