2006-05-02 09:31:56 +08:00
from django . db import models
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
from django . utils . translation import ugettext_lazy as _
2007-09-14 15:12:47 +08:00
from django . http import get_host
2006-05-02 09:31:56 +08:00
class SiteManager ( models . Manager ) :
def get_current ( self ) :
from django . conf import settings
2007-07-12 13:23:47 +08:00
try :
sid = settings . SITE_ID
except AttributeError :
from django . core . exceptions import ImproperlyConfigured
raise ImproperlyConfigured ( " You ' re using the Django \" sites framework \" without having set the SITE_ID setting. Create a site in your database and set the SITE_ID setting to fix this error. " )
return self . get ( pk = sid )
2006-05-02 09:31:56 +08:00
class Site ( models . Model ) :
2007-08-05 13:14:46 +08:00
domain = models . CharField ( _ ( ' domain name ' ) , max_length = 100 )
name = models . CharField ( _ ( ' display name ' ) , max_length = 50 )
2006-05-02 09:31:56 +08:00
objects = SiteManager ( )
class Meta :
db_table = ' django_site '
verbose_name = _ ( ' site ' )
verbose_name_plural = _ ( ' sites ' )
ordering = ( ' domain ' , )
class Admin :
list_display = ( ' domain ' , ' name ' )
search_fields = ( ' domain ' , ' name ' )
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
def __unicode__ ( self ) :
2006-05-02 09:31:56 +08:00
return self . domain
2007-07-12 13:28:04 +08:00
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 ) :
2007-09-14 15:12:47 +08:00
self . domain = self . name = get_host ( request )
2007-07-12 13:28:04 +08:00
2007-09-13 22:40:08 +08:00
def __unicode__ ( self ) :
return self . domain
2007-07-12 13:28:04 +08:00
def save ( self ) :
raise NotImplementedError ( ' RequestSite cannot be saved. ' )
def delete ( self ) :
raise NotImplementedError ( ' RequestSite cannot be deleted. ' )