location sort, fixes #701 user agent string fixes #704, #702 user ox for country name fixes #705 system/user agent sort should be case insensitve fixes #706
This commit is contained in:
parent
22c5e10672
commit
105e91d6dd
2 changed files with 13 additions and 9 deletions
|
@ -34,6 +34,7 @@ class SessionData(models.Model):
|
||||||
info = DictField(default={})
|
info = DictField(default={})
|
||||||
|
|
||||||
location = models.CharField(max_length=255, null=True)
|
location = models.CharField(max_length=255, null=True)
|
||||||
|
location_sort = models.CharField(max_length=255, null=True)
|
||||||
system = models.CharField(max_length=255, null=True)
|
system = models.CharField(max_length=255, null=True)
|
||||||
browser = models.CharField(max_length=255, null=True)
|
browser = models.CharField(max_length=255, null=True)
|
||||||
|
|
||||||
|
@ -49,8 +50,8 @@ class SessionData(models.Model):
|
||||||
def parse_data(self):
|
def parse_data(self):
|
||||||
if self.useragent:
|
if self.useragent:
|
||||||
ua = ox.parse_useragent(self.useragent)
|
ua = ox.parse_useragent(self.useragent)
|
||||||
self.browser= ua['browser']['string']
|
self.browser = ua['browser']['string'].lower()
|
||||||
self.system = ua['system']['string']
|
self.system = ua['system']['string'].lower()
|
||||||
if not self.browser:
|
if not self.browser:
|
||||||
self.browser = None
|
self.browser = None
|
||||||
if not self.system:
|
if not self.system:
|
||||||
|
@ -60,12 +61,14 @@ class SessionData(models.Model):
|
||||||
g = GeoIP()
|
g = GeoIP()
|
||||||
location = g.city(self.ip)
|
location = g.city(self.ip)
|
||||||
if location:
|
if location:
|
||||||
self.location = u'%s, %s' % (location['city'].decode('latin-1'),
|
city = location['city'].decode('latin-1')
|
||||||
location['country_name'].decode('latin-1'))
|
country = ox.get_country_name(location['country_code'])
|
||||||
|
self.location = u'%s, %s' % (city, country)
|
||||||
|
self.location_sort = u'%s, %s' % (country, city)
|
||||||
else:
|
else:
|
||||||
self.location = None
|
self.location_sort = self.location = None
|
||||||
except:
|
except:
|
||||||
self.location = None
|
self.location_sort = self.location = None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
@ -109,8 +112,9 @@ class SessionData(models.Model):
|
||||||
return self.user and ox.toAZ(self.user.id) or self.session_key
|
return self.user and ox.toAZ(self.user.id) or self.session_key
|
||||||
|
|
||||||
def json(self, keys=None, user=None):
|
def json(self, keys=None, user=None):
|
||||||
|
ua = ox.parse_useragent(self.useragent or '')
|
||||||
j = {
|
j = {
|
||||||
'browser': self.browser,
|
'browser': ua['browser']['string'],
|
||||||
'disabled': False,
|
'disabled': False,
|
||||||
'email': '',
|
'email': '',
|
||||||
'firstseen': self.firstseen,
|
'firstseen': self.firstseen,
|
||||||
|
@ -123,7 +127,7 @@ class SessionData(models.Model):
|
||||||
'notes': '',
|
'notes': '',
|
||||||
'numberoflists': 0,
|
'numberoflists': 0,
|
||||||
'screensize': self.screensize,
|
'screensize': self.screensize,
|
||||||
'system': self.system,
|
'system': ua['system']['string'],
|
||||||
'timesseen': self.timesseen,
|
'timesseen': self.timesseen,
|
||||||
'username': self.username or '',
|
'username': self.username or '',
|
||||||
'useragent': self.useragent,
|
'useragent': self.useragent,
|
||||||
|
|
|
@ -436,7 +436,7 @@ def order_query(qs, sort):
|
||||||
'ip': 'ip',
|
'ip': 'ip',
|
||||||
'lastseen': 'lastseen',
|
'lastseen': 'lastseen',
|
||||||
'level': 'level',
|
'level': 'level',
|
||||||
'location': 'location',
|
'location': 'location_sort',
|
||||||
'screensize': 'screensize',
|
'screensize': 'screensize',
|
||||||
'system': 'system',
|
'system': 'system',
|
||||||
'timesseen': 'timesseen',
|
'timesseen': 'timesseen',
|
||||||
|
|
Loading…
Reference in a new issue