From 8a1fd4afdac35ba43a862b371a76d37edb71149c Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 27 Mar 2012 07:29:01 +0000 Subject: [PATCH] move fallback location test (email TLD) into the backend --- pandora/user/models.py | 9 ++++++++- static/js/pandora/statisticsDialog.js | 13 ++++--------- static/js/pandora/usersDialog.js | 5 +---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pandora/user/models.py b/pandora/user/models.py index 8dfa7f4e..6cce2dff 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -69,12 +69,19 @@ class SessionData(models.Model): self.location = u'%s, %s' % (city, country) self.location_sort = u'%s, %s' % (country, city) else: - self.location_sort = self.location = country + self.location_sort = self.location = country else: self.location_sort = self.location = None except: self.location_sort = self.location = None pass + if self.location == None and self.user and self.user.email: + tld = self.user.email.split('.')[-1] + if tld in ['edu', 'gov', 'mil']: + tld = 'us' + country = ox.get_country_name(tld) + if country: + self.location_sort = self.location = country def save(self, *args, **kwargs): if self.user: diff --git a/static/js/pandora/statisticsDialog.js b/static/js/pandora/statisticsDialog.js index 4125bf13..3ea24860 100644 --- a/static/js/pandora/statisticsDialog.js +++ b/static/js/pandora/statisticsDialog.js @@ -93,10 +93,10 @@ pandora.ui.statisticsDialog = function() { $tabPanel; - Ox.getJSON('/static/json/deleteme.json', function(result) { - /* + //Ox.getJSON('/static/json/deleteme.json', function(result) { + ///* pandora.api.findUsers({ - keys: ['browser', 'email', 'firstseen', 'lastseen', 'level', 'location', 'system'], + keys: ['browser', 'firstseen', 'lastseen', 'level', 'location', 'system'], query: { conditions: [{key: 'level', value: 'robot', operator: '!='}], operator: '&' @@ -104,7 +104,7 @@ pandora.ui.statisticsDialog = function() { range: [0, 1000000], sort: [{key: 'username', operator: '+'}] }, function(result) { - */ + //*/ var data = {}, flagCountry = {}, @@ -144,11 +144,6 @@ pandora.ui.statisticsDialog = function() { data[mode].day[day][hour] = (data[mode].day[day][hour] || 0) + 1; data[mode].hour[hour] = (data[mode].hour[hour] || 0) + 1; }); - if (!item.location) { - item.location = (Ox.getCountryByCode( - item.email.split('.').pop().replace(/(edu|gov|mil)/i, 'us') - ) || {}).name || ''; - } if (item.location) { split = item.location.split(', ') if (split.length == 1) { diff --git a/static/js/pandora/usersDialog.js b/static/js/pandora/usersDialog.js index c49cb0ee..4b40be6a 100644 --- a/static/js/pandora/usersDialog.js +++ b/static/js/pandora/usersDialog.js @@ -170,10 +170,7 @@ pandora.ui.usersDialog = function() { width: 16 }, { - format: function(value, data) { - value = value || (Ox.getCountryByCode( - data.email.split('.').pop().replace(/(edu|gov|mil)/i, 'us') - ) || {}).name || ''; + format: function(value) { return Ox.Element({ element: '', tooltip: value