2018-01-24 16:07:33 +01:00
|
|
|
""" Models for the history. This history should be able to generate history
|
|
|
|
entries, which looks like human-based browsing, according to a dedicated user
|
|
|
|
interests, keywords...
|
|
|
|
"""
|
|
|
|
|
2018-01-23 18:12:47 +01:00
|
|
|
from django.db import models
|
2018-01-24 16:07:33 +01:00
|
|
|
from profiles.models import BrowserFingerprint
|
|
|
|
|
|
|
|
class HistoryEntry(models.Model):
|
|
|
|
""" A history entry, aka a url, and a timestamp.
|
|
|
|
"""
|
|
|
|
search = models.CharField(max_length=255)
|
|
|
|
timestamp = models.DateTimeField()
|
|
|
|
history = models.ForeignKey(
|
|
|
|
'History',
|
|
|
|
on_delete=models.CASCADE
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "{} : {}".format(self.timestamp, self.search)
|
|
|
|
|
|
|
|
|
|
|
|
class History(models.Model):
|
|
|
|
""" A history for a user, containing some web connections (http, https).
|
|
|
|
Each history is timed, in a human-behaviour manner. """
|
|
|
|
|
|
|
|
start_ts = models.DateTimeField()
|
|
|
|
played = models.BooleanField(default=False)
|
|
|
|
user_agent = models.ForeignKey(
|
|
|
|
BrowserFingerprint,
|
|
|
|
on_delete=models.CASCADE
|
|
|
|
)
|
2018-01-23 18:12:47 +01:00
|
|
|
|
2018-01-24 16:07:33 +01:00
|
|
|
def __str__(self):
|
|
|
|
history_set = self.history_set.order_by('timestamp')
|
|
|
|
return "\n".join(history_set)
|