def timezone(self): try: return self.request.timezone except AttributeError, e: logger.error(unicode(e)) from film20.geo.models import BaseTimeZone return BaseTimeZone.tzid_for_country(_settings.COUNTRY_CODE)
cached_geo = cache.get(key) if cached_geo is not None and cached_geo.get('accuracy') <= accuracy * 2: geo = cached_geo else: if self.set_country_and_tz_by_lat_lng(request, geo): cache.set(key, geo) if not 'country_code' in geo: langs = request.META.get('HTTP_ACCEPT_LANGUAGE', '') langs = [l.strip() for l in langs.split(',')] if langs: match = re.match("(\w\w)(-(\w\w))?", langs[0]) if match: lang, _, code = match.groups() country_code = (code or lang).upper() timezone = BaseTimeZone.tzid_for_country(country_code) if timezone: geo['country_code'] = country_code geo['timezone'] = timezone geo['source'] = 'accept_language' if not 'country_code' in geo: geo['country_code'] = settings.COUNTRY_CODE geo['timezone'] = BaseTimeZone.tzid_for_country(settings.COUNTRY_CODE) geo['source'] = 'settings' request._geo = geo return geo @classmethod def profile_post_save(cls, sender, instance, created, *args, **kw):
if cached_geo is not None and cached_geo.get( 'accuracy') <= accuracy * 2: geo = cached_geo else: if self.set_country_and_tz_by_lat_lng(request, geo): cache.set(key, geo) if not 'country_code' in geo: langs = request.META.get('HTTP_ACCEPT_LANGUAGE', '') langs = [l.strip() for l in langs.split(',')] if langs: match = re.match("(\w\w)(-(\w\w))?", langs[0]) if match: lang, _, code = match.groups() country_code = (code or lang).upper() timezone = BaseTimeZone.tzid_for_country(country_code) if timezone: geo['country_code'] = country_code geo['timezone'] = timezone geo['source'] = 'accept_language' if not 'country_code' in geo: geo['country_code'] = settings.COUNTRY_CODE geo['timezone'] = BaseTimeZone.tzid_for_country( settings.COUNTRY_CODE) geo['source'] = 'settings' request._geo = geo return geo @classmethod