File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,24 @@ def disp_remote_addr(self,obj):
30
30
disp_remote_addr .short_description = "IP Address"
31
31
32
32
class LogEntryAdminMixin (object ):
33
+
34
+ #GOIP API used to get user location details.
35
+ headers = {
36
+ 'accept' : "application/json" ,
37
+ 'content-type' : "application/json"
38
+ }
39
+ response = requests .request ("GET" , settings .AUDITLOG_GOIP_API , headers = headers )
40
+ response_dict = json .loads (response .text ) #converting response to dictionary
41
+ tz_from_response = response_dict ["time_zone" ]
42
+
33
43
def created (self , obj ):
44
+ Audit_data = LogEntry .objects .all ()
45
+ for audit_obj in Audit_data :
46
+ new_ts = audit_obj .timestamp .strftime ("%m/%d/%Y %I:%M %p" )
47
+ new_ts = audit_obj .timestamp .strptime (new_ts ,"%m/%d/%Y %I:%M %p" )
48
+ system_tz = pytz .timezone ('UTC' )
49
+ local_tz = pytz .timezone (LogEntryAdminMixin .tz_from_response ) #local tz set as timezone from response
50
+ local_ts = system_tz .localize (new_ts ).astimezone (local_tz ) #returns datetime in the local timezone
34
51
return obj .timestamp .strftime ('%b. %d, %Y, %I:%M %p' ) #Displays date in diff format
35
52
created .short_description = 'Date'
36
53
You can’t perform that action at this time.
0 commit comments