7

Make the static elements tracked users only

We cannot track anonymous users as the session expires after 10 minutes of
inactivity. This also avoids an issue where there is an error when the user's
session has expired and they navigate a page
This commit is contained in:
Todd Dembrey
2017-11-01 16:43:22 +00:00
parent b8bf27fb99
commit 1f4a4536ab
6 changed files with 86 additions and 40 deletions

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals
from django import forms
from django.conf import settings
from django.contrib.sessions.models import Session
from django.db import models, transaction
from django.template.defaultfilters import slugify
@ -82,7 +83,9 @@ class Segment(ClusterableModel):
"set until the number is reached. After this no more users will be added."
)
)
sessions = models.ManyToManyField(Session)
static_users = models.ManyToManyField(
settings.AUTH_USER_MODEL,
)
objects = SegmentQuerySet.as_manager()
@ -131,7 +134,7 @@ class Segment(ClusterableModel):
@property
def is_full(self):
return self.sessions.count() >= self.count
return self.static_users.count() >= self.count
def encoded_name(self):
"""Return a string with a slug for the segment."""