summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-07 16:54:09 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-07 16:54:09 +0700
commit7478616937cff56ccb994138831f90eae904e724 (patch)
tree4ad143d9feb6f015ab1626dc9aa0a9400b995dc1
parent0388c78c3bbe0f5a6325fee7bb7b2e6a7d436a5f (diff)
user activity log detail
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py34
-rwxr-xr-xindoteknik_custom/views/user_activity_log.xml10
2 files changed, 44 insertions, 0 deletions
diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py
index 879d5402..9d9694af 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -16,11 +16,44 @@ class UserActivityLog(models.Model):
url = fields.Char(string="URL")
ip_address = fields.Char('IP Address')
ip_address_lookup = fields.Text('IP Address Lookup')
+ ip_location_city = fields.Text('IP Location City')
+ ip_location_country = fields.Text('IP Location Country')
+ ip_location_country_code = fields.Text('IP Location Country Code')
+ ip_location_map = fields.Html('Embedded Map', compute='_compute_ip_location_map', sanitize=False)
res_user_id = fields.Many2one("res.users", string="User")
email = fields.Char(string="Email")
update_product = fields.Boolean(string="Update Product")
product_id = fields.Many2one('product.template', string='Product')
+ def _parse_json(self, json_string, key):
+ result = ''
+ if json_string:
+ json_object = json.loads(json_string)
+ if key in json_object:
+ result = json_object[key]
+ return result
+
+ def _compute_ip_location_map(self):
+ self.ip_location_map = ""
+ ip_location_lat = self._parse_json(self.ip_address_lookup, 'lat')
+ ip_location_lon = self._parse_json(self.ip_address_lookup, 'lon')
+ url = 'https://maps.google.com/maps?q=%s,%s&amp;hl=id&amp;z=15&amp;output=embed' % (ip_location_lat, ip_location_lon)
+ if ip_location_lat and ip_location_lon:
+ self.ip_location_map = "<iframe width='100%' height='500' frameborder='1' scrolling='no' src='"+ url +"'></iframe>"
+
+ def _parse_ip_location(self):
+ domain = [
+ ('ip_address_lookup', '!=', False),
+ ('ip_location_city', '=', False),
+ ('ip_location_country', '=', False),
+ ('ip_location_country_code', '=', False),
+ ]
+ logs = self.search(domain, limit=200, order='create_date asc')
+ for log in logs:
+ log.ip_location_city = self._parse_json(log.ip_address_lookup, 'city')
+ log.ip_location_country = self._parse_json(log.ip_address_lookup, 'country')
+ log.ip_location_country_code = self._parse_json(log.ip_address_lookup, 'countryCode')
+
def _load_ip_address_lookup(self):
domain = [
('ip_address', '!=', False),
@@ -34,6 +67,7 @@ class UserActivityLog(models.Model):
log.ip_address_lookup = json.dumps(ipinfo, indent=4, sort_keys=True)
except:
log.ip_address_lookup = ''
+ self._parse_ip_location()
def record_activity(self):
try:
diff --git a/indoteknik_custom/views/user_activity_log.xml b/indoteknik_custom/views/user_activity_log.xml
index b0082c3b..b8792ee8 100755
--- a/indoteknik_custom/views/user_activity_log.xml
+++ b/indoteknik_custom/views/user_activity_log.xml
@@ -32,9 +32,19 @@
</group>
</group>
<notebook>
+ <page string="IP Lookup Detail">
+ <group>
+ <field name="ip_location_city"/>
+ <field name="ip_location_country"/>
+ <field name="ip_location_country_code"/>
+ </group>
+ </page>
<page string="IP Address Lookup">
<field name="ip_address_lookup"/>
</page>
+ <page string="IP Address Location">
+ <field name="ip_location_map" widget="html" />
+ </page>
</notebook>
</sheet>
</form>