コード例 #1
0
ファイル: models.py プロジェクト: yacine15/django-htk
 def update_locale_info_by_ip_from_request(self, request):
     """Update user info by IP Address
     
     Store last_login_ip only when logging in
     Store country resolved from IP
     Store timezone resolved from IP
     
     Caller: api.auth.decorators.register_or_login_user
     
     Unknown whether this code throws an exception, but catch it upstream if any
     """
     try:
         ip = extract_request_ip(request)
         if ip and self.last_login_ip != ip:
             self.last_login_ip = ip
             try:
                 from htk.lib.geoip.utils import get_country_code_by_ip
                 from htk.lib.geoip.utils import get_timezone_by_ip
                 detected_country = get_country_code_by_ip(ip) or ''
                 detected_timezone = get_timezone_by_ip(ip) or ''
                 self.detected_country = detected_country
                 self.detected_timezone = detected_timezone
             except:
                 # couldn't find geoip records for ip, just be quiet for now
                 pass
             finally:
                 self.save()
     except:
         # error extracting IP or saving
         rollbar.report_exc_info(request=request)
コード例 #2
0
ファイル: models.py プロジェクト: WhitespaceCrew/django-htk
 def update_locale_info_by_ip_from_request(self, request):
     """Update user info by IP Address
     
     Store last_login_ip only when logging in
     Store country resolved from IP
     Store timezone resolved from IP
     
     Caller: api.auth.decorators.register_or_login_user
     
     Unknown whether this code throws an exception, but catch it upstream if any
     """
     try:
         ip = extract_request_ip(request)
         if ip and self.last_login_ip != ip:
             self.last_login_ip = ip
             try:
                 from htk.lib.geoip.utils import get_country_code_by_ip
                 from htk.lib.geoip.utils import get_timezone_by_ip
                 detected_country = get_country_code_by_ip(ip) or ''
                 detected_timezone = get_timezone_by_ip(ip) or ''
                 self.detected_country = detected_country
                 self.detected_timezone = detected_timezone
             except:
                 # couldn't find geoip records for ip, just be quiet for now
                 pass
             finally:
                 self.save()
     except:
         # error extracting IP or saving
         rollbar.report_exc_info(request=request)
コード例 #3
0
ファイル: models.py プロジェクト: PocketGM/django-htk
 def update_locale_info_by_ip_from_request(self, request):
     """Update user info by IP Address
     
     Store last_login_ip only when logging in
     Store country resolved from IP
     Store timezone resolved from IP
     
     Caller: api.auth.decorators.register_or_login_user
     
     Unknown whether this code throws an exception, but catch it upstream if any
     """
     try:
         ip = extract_request_ip(request)
         if ip and self.last_login_ip != ip:
             self.last_login_ip = ip
             gi_country = get_geoip_country()
             gi_city = get_geoip_city()
             self.detected_country = gi_country.country_code_by_addr(ip)
             self.detected_timezone = gi_city.time_zone_by_addr(ip)
             self.save()
     except:
         # couldn't find geoip records for ip, just be quiet for now
         #rollbar.report_exc_info(request=request)
         pass