Django

Code

Changeset 5653

Show
Ignore:
Timestamp:
07/12/07 00:28:04 (2 years ago)
Author:
adrian
Message:

Added RequestSite? class to sites framework

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/sites/models.py

    r5652 r5653  
    2727    def __unicode__(self): 
    2828        return self.domain 
     29 
     30class RequestSite(object): 
     31    """ 
     32    A class that shares the primary interface of Site (i.e., it has 
     33    ``domain`` and ``name`` attributes) but gets its data from a Django 
     34    HttpRequest object rather than from a database. 
     35 
     36    The save() and delete() methods raise NotImplementedError. 
     37    """ 
     38    def __init__(self, request): 
     39        self.domain = self.name = request.META['SERVER_NAME'] 
     40 
     41    def save(self): 
     42        raise NotImplementedError('RequestSite cannot be saved.') 
     43 
     44    def delete(self): 
     45        raise NotImplementedError('RequestSite cannot be deleted.') 
  • django/trunk/docs/sites.txt

    r5064 r5653  
    321321.. _syndication framework: ../syndication/ 
    322322.. _authentication framework: ../authentication/ 
     323 
     324``RequestSite`` objects 
     325======================= 
     326 
     327**New in Django development version** 
     328 
     329Some ``django.contrib`` applications take advantage of the sites framework but 
     330are architected in a way that doesn't *require* the sites framework to be 
     331installed in your database. (Some people don't want to, or just aren't *able* 
     332to install the extra database table that the sites framework requires.) For 
     333those cases, the framework provides a ``RequestSite`` class, which can be used 
     334as a fallback when the database-backed sites framework is not available. 
     335 
     336A ``RequestSite`` object has a similar interface to a normal ``Site`` object, 
     337except its ``__init__()`` method takes an ``HttpRequest`` object. It's able to 
     338deduce the ``domain`` and ``name`` by looking at the request's domain. It has 
     339``save()`` and ``delete()`` methods to match the interface of ``Site``, but 
     340the methods raise ``NotImplementedError``.