def getcurrentsite(http_post, path_info, query_string): """ Returns the site id and the page cache key based on the request. """ url = u'http://%s/%s' % (smart_unicode(http_post.rstrip('/')), \ smart_unicode(path_info.lstrip('/'))) pagecachekey = '%s?%s' % (smart_unicode(path_info), \ smart_unicode(query_string)) hostdict = fjcache.hostcache_get() if not hostdict: hostdict = {} if url not in hostdict: default, ret = None, None for site in models.Site.objects.all(): if url.startswith(site.url): ret = site break if not default or site.default_site: default = site if not ret: if default: ret = default else: # Somebody is requesting something, but the user didn't create # a site yet. Creating a default one... ret = models.Site(name='Default Feedjack Site/Planet', \ url='www.feedjack.org', \ title='Feedjack Site Title', \ description='Feedjack Site Description. ' \ 'Please change this in the admin interface.') ret.save() hostdict[url] = ret.id fjcache.hostcache_set(hostdict) return hostdict[url], pagecachekey
def save(self): if not self.template: self.template = 'default' # there must be only ONE default site defs = Site.objects.filter(default_site=True) if not defs: self.default_site = True elif self.default_site: for tdef in defs: if tdef.id != self.id: tdef.default_site = False tdef.save() self.url = self.url.rstrip('/') fjcache.hostcache_set({}) super(Site, self).save()