|
|
@ -14,19 +14,22 @@ def send_notification(notification):
|
|
|
|
'title': notification.title,
|
|
|
|
'title': notification.title,
|
|
|
|
'body': mark_safe(notification.message),
|
|
|
|
'body': mark_safe(notification.message),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sound = "default"
|
|
|
|
if notification.image:
|
|
|
|
if notification.image:
|
|
|
|
FCMDevice.objects.send_message(
|
|
|
|
FCMDevice.objects.send_message(
|
|
|
|
Message(notification=NotificationFB(
|
|
|
|
Message(notification=NotificationFB(
|
|
|
|
title=notification_data['title'],
|
|
|
|
title=notification_data['title'],
|
|
|
|
body=notification_data['body'],
|
|
|
|
body=notification_data['body'],
|
|
|
|
image= notification.image
|
|
|
|
image= notification.image,
|
|
|
|
|
|
|
|
sound=sound
|
|
|
|
), data={"image": notification.image})
|
|
|
|
), data={"image": notification.image})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
FCMDevice.objects.send_message(
|
|
|
|
FCMDevice.objects.send_message(
|
|
|
|
Message(notification=NotificationFB(
|
|
|
|
Message(notification=NotificationFB(
|
|
|
|
title=notification_data['title'],
|
|
|
|
title=notification_data['title'],
|
|
|
|
body=notification_data['body']
|
|
|
|
body=notification_data['body'],
|
|
|
|
|
|
|
|
sound=sound
|
|
|
|
))
|
|
|
|
))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -59,6 +62,10 @@ class Visitor(models.Model):
|
|
|
|
flag_url = f"https://osina.ositcom.com/static/images/flags/{self.country.lower()}.svg"
|
|
|
|
flag_url = f"https://osina.ositcom.com/static/images/flags/{self.country.lower()}.svg"
|
|
|
|
return flag_url
|
|
|
|
return flag_url
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
|
|
|
|
def notification_flag_image_url(self):
|
|
|
|
|
|
|
|
flag_url = f"https://flagcdn.com/w640/{self.country.lower()}.svg/"
|
|
|
|
|
|
|
|
return flag_url
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_online(self):
|
|
|
|
def is_online(self):
|
|
|
|
latest_log = self.visitorlog_set.order_by('-visit_date').first()
|
|
|
|
latest_log = self.visitorlog_set.order_by('-visit_date').first()
|
|
|
|
if latest_log and latest_log.left_date is None:
|
|
|
|
if latest_log and latest_log.left_date is None:
|
|
|
@ -94,7 +101,7 @@ class Visitor(models.Model):
|
|
|
|
def send_visitor_notification(self):
|
|
|
|
def send_visitor_notification(self):
|
|
|
|
notification = ChatNotification.objects.create(
|
|
|
|
notification = ChatNotification.objects.create(
|
|
|
|
title="New visitor on Ositcom!",
|
|
|
|
title="New visitor on Ositcom!",
|
|
|
|
image = self.flag_image_url
|
|
|
|
image = self.notification_flag_image_url
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -106,6 +113,20 @@ class VisitorLog(models.Model):
|
|
|
|
referrer = models.URLField(null=True, blank=True)
|
|
|
|
referrer = models.URLField(null=True, blank=True)
|
|
|
|
visit_date = models.DateTimeField(null=True)
|
|
|
|
visit_date = models.DateTimeField(null=True)
|
|
|
|
left_date = models.DateTimeField(null=True)
|
|
|
|
left_date = models.DateTimeField(null=True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def log_duration(self):
|
|
|
|
|
|
|
|
end_time = self.left_date if self.left_date else timezone.now()
|
|
|
|
|
|
|
|
total_seconds = (end_time - self.visit_date).total_seconds()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
duration = timedelta(seconds=total_seconds)
|
|
|
|
|
|
|
|
hours, remainder = divmod(duration.total_seconds(), 3600)
|
|
|
|
|
|
|
|
minutes, seconds = divmod(remainder, 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if hours >= 1:
|
|
|
|
|
|
|
|
return f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return f"{int(minutes):02}:{int(seconds):02}"
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
is_new = not self.pk
|
|
|
|
is_new = not self.pk
|
|
|
|
if self.left_date:
|
|
|
|
if self.left_date:
|
|
|
@ -126,7 +147,7 @@ class VisitorLog(models.Model):
|
|
|
|
def send_visitorlog_notification(self):
|
|
|
|
def send_visitorlog_notification(self):
|
|
|
|
notification = ChatNotification.objects.create(
|
|
|
|
notification = ChatNotification.objects.create(
|
|
|
|
title=f"Visitor navigated to: {self.title}.",
|
|
|
|
title=f"Visitor navigated to: {self.title}.",
|
|
|
|
image=self.visitor.flag_image_url
|
|
|
|
image=self.visitor.notification_flag_image_url
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|