7

Use the Segment Adapter for retrieving page visits

This fixes the last occurence of directly accessing the session in the
codebase
This commit is contained in:
Michael van Tellingen
2017-05-31 14:14:54 +02:00
parent 31f8a329f2
commit 9705947d3f
2 changed files with 13 additions and 15 deletions

View File

@ -226,23 +226,12 @@ class VisitCountRule(AbstractBaseRule):
operator = self.operator
segment_count = self.count
def get_visit_count(request):
"""Search through the request sessions to get the page visit count
corresponding to the request.
# Local import for cyclic import
from wagtail_personalisation.adapters import get_segment_adapter
:param request: The http request
:type request: django.http.HttpRequest
:returns: A number indicating the amount of visits
to the requested page
:rtype: int
"""
for page in request.session['visit_count']:
if page['path'] == request.path:
return page['count']
visit_count = get_visit_count(request)
adapter = get_segment_adapter(request)
visit_count = adapter.get_visit_count()
if visit_count and operator == "more_than":
if visit_count > segment_count:
return True