def site(self): if not hasattr(self, "_site"): site = cache.get('site') if site is not None: self._site = site else: #q = models.GqlQuery("SELECT * FROM Site WHERE num = 1") q = Site.objects.filter(num=1) if q.count() == 1: site = q[0] if site.l10n is None: site.l10n = 'en' if site.meta is None: site.meta = '' cache.set('site', site, 86400) self._site = site else: site = Site() site.num = 1 site.title = 'V2EX' site.domain = 'v2ex.appspot.com' site.slogan = 'way to explore' site.l10n = 'en' site.description = '' site.meta = '' site.save() cache.set('site', site, 86400) self._site = site return self._site
def GetSite(): site = cache.get('site') if site is not None: return site else: q = Site.objects.all() #("SELECT * FROM Site WHERE num = 1") if q.count() >= 1: site = q[0] if site.l10n is None: site.l10n = 'en' if site.meta is None: site.meta = '' cache.set('site', site, 86400) return site else: site = Site() site.num = 1 site.title = 'DJANGO-V2EX' site.domain = 'localhost:8000' #'www.v2ex.com' site.slogan = 'v2ex way to explore django' site.l10n = 'en' site.description = 'Python shake, Code rock!' site.meta = '' site.home_categories = u'\u5206\u4eab\u4e0e\u63a2\u7d22\nV2EX\niOS\nGeek\n\u6e38\u620f\nApple\n\u751f\u6d3b\nInternet\n\u57ce\u5e02\n\u54c1\u724c\n' site.save() cache.set('site', site, 86400) return site