#13814: Utility method for getting a Site object
--------------------------+-------------------------------------------------
 Reporter:  ubernostrum   |       Owner:  nobody    
   Status:  new           |   Milestone:            
Component:  Contrib apps  |     Version:  1.2       
 Keywords:                |       Stage:  Unreviewed
Has_patch:  0             |  
--------------------------+-------------------------------------------------
 Fairly often, I find myself writing code which needs a `Site` and which,
 as a general best practice, falls back to `RequestSite` if `contrib.sites`
 isn't installed. Which means writing this code, or something like it, over
 and over:

 {{{
 from django.contrib.sites.models import RequestSite
 from django.contrib.sites.models import Site

 if Site._meta.installed:
     site = Site.objects.get_current()
 else:
     site = RequestSite(some_request_object)
 }}}

 Given how common this idiom will be for code which wants to properly
 support the `RequestSite` fallback, it'd be nice to just have a utility
 method somewhere in `contrib.sites` which could just take an `HttpRequest`
 object and return either a `Site` or a `RequestSite` as appropriate.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13814>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to