emile 9 months ago
parent 855584aca5
commit 8865d257fc

@ -133,22 +133,8 @@ class Visitor(models.Model):
'action': 'new_visitor' 'action': 'new_visitor'
} }
async_to_sync(channel_layer.group_send)("osichat", event) async_to_sync(channel_layer.group_send)("osichat", event)
self.send_visitor_notification()
def send_visitor_notification(self):
first_log = self.visitorlog_set.order_by('visit_date').first()
body = ""
if first_log:
if first_log.title:
body = f"New visitor navigated to {first_log.title}"
elif first_log.url:
body = f"New visitor navigated to {first_log.url}"
notification = ChatNotification.objects.create(
title="New visitor on Ositcom!",
body = body,
image = self.notification_flag_image_url,
type = "Visitor"
)
@ -174,6 +160,7 @@ class VisitorLog(models.Model):
return f"{int(minutes):02}:{int(seconds):02}" return f"{int(minutes):02}:{int(seconds):02}"
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
is_first_log = not VisitorLog.objects.filter(visitor=self.visitor).exists()
if self.left_date: if self.left_date:
action = 'end_log' action = 'end_log'
else: else:
@ -186,6 +173,20 @@ class VisitorLog(models.Model):
'action': action 'action': action
} }
async_to_sync(channel_layer.group_send)("osichat", event) async_to_sync(channel_layer.group_send)("osichat", event)
if is_first_log:
self.send_visitor_notification()
def send_visitor_notification(self):
body = ""
if self.title:
body = f"New visitor navigated to {self.title}"
elif self.url:
body = f"New visitor navigated to {self.url}"
notification = ChatNotification.objects.create(
title="New visitor on Ositcom!",
body = body,
image = self.visitor.notification_flag_image_url,
type = "Visitor"
)

Loading…
Cancel
Save