Skip to content

Commit

Permalink
Merge branch 'develop' into feature/djangoconf-sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
pjstevns committed May 26, 2018
2 parents 5b8d578 + 3a86c18 commit 5536adc
Show file tree
Hide file tree
Showing 35 changed files with 1,401 additions and 107 deletions.
36 changes: 12 additions & 24 deletions .travis.yml
Expand Up @@ -4,33 +4,11 @@ language: python

matrix:
include:
# Django 1.9, Wagtail 1.9
- python: 2.7
env: TOXENV=py27-django19-wagtail19
- python: 3.5
env: TOXENV=py35-django19-wagtail19
- python: 3.6
env: TOXENV=py36-django19-wagtail19
env: lint

# Django 1.10, Wagtail 1.10
- python: 2.7
env: TOXENV=py27-django110-wagtail110
- python: 3.5
env: TOXENV=py35-django110-wagtail110
- python: 3.6
env: TOXENV=py36-django110-wagtail110

# Django 1.11, Wagtail 1.10
- python: 2.7
env: TOXENV=py27-django111-wagtail110
- python: 3.5
env: TOXENV=py35-django111-wagtail110
- python: 3.6
env: TOXENV=py36-django111-wagtail110

allow_failures:
- python: 3.5
env: TOXENV=lint
env: TOXENV=py27-django111-wagtail113

install:
- pip install tox codecov
Expand All @@ -41,3 +19,13 @@ script:
after_success:
- tox -e coverage-report
- codecov

deploy:
provider: pypi
distributions: sdist bdist_wheel
user: praekelt.org
password:
secure: IxPnc95OFNQsl7kFfLlLc38KfHh/W79VXnhEkdb2x1GZznOsG167QlhpAnyXIJysCQxgMMwLMuPOOdk1WIxOpGNM1/M80hNzPAfxMYWPuwposDdwoIc8SyREPJt16BXWAY+rAH8SHxld9p1YdRbOEPSSglODe4dCmQWsCbKjV3aKv+gZxBvf6pMxUglp2fBIlCwrE77MyMYh9iW0AGzD6atC2xN9NgAm4f+2WFlKCUL/MztLhNWdvWEiibQav6Tts7p8tWrsBVzywDW2IOy3O0ihPgRdISZ7QrxhiJTjlHYPAy4eRGOnYSQXvp6Dy8ONE5a6Uv5g3Xw2UmQo85sSMUs2VxR0G7d+PQgL0A7ENBQ5i7eSAFHYs8EswiGilW2A7mM4qRXwg9URLelYSdkM+aNXvR+25dCsXakiO4NjCz/BPgNzxPeQLlBdxR5vHugeM/XYuhy6CHlZrR/uueaO0X8RyhJcqeDjBy58IrwYS3Mpj7QCfBpQ9PqsqXEWV9BKwKiBXM2+3hkhawFDWa0GW2PDbORKtSLy/ORfGLx5Y9qxQYKEGvFQA3iqkTjrLj+KeUziKtuvEAcvsdBIJVIxeoHwdl+qqxEm8A7YuRBnWVxWc3jE6wBXboeFP92gVe/ueoXmY22riK9Ja0pli3TyNga8by9WM8Qp4D2ZqkVXHwg=
on:
tags: true
condition: $TOXENV = py27-django111-wagtail113
47 changes: 47 additions & 0 deletions CHANGES
@@ -1,3 +1,50 @@
0.11.3
==================
- Bugfix: Handle errors when testing an invalid visit count rule

0.11.2
==================
- Bugfix: Stop populating static segments when the count is reached

0.11.1
==================
- Populate entirely static segments from registered Users not active Sessions

0.11.0
==================
- Bug Fix: Query rule should not be static
- Enable retrieval of user data for static rules through csv download

0.10.9
==================
- Bug Fix: Display the number of users in a static segment on dashboard

0.10.8
==================
- Don't add users to exclude list for dynamic segments
- Store segments a user is excluded from in the session

0.10.7
==================
- Bug Fix: Ensure static segment members are show the survey immediately
- Records users excluded by randomisation on the segment
- Don't re-check excluded users

0.10.6
==================
- Accepts and stores randomisation percentage for segment
- Adds users to segment based on random number relative to percentage

0.10.5
==================
- Count how many users match a segments rules before saving the segment
- Stores count on the segment and displays in the dashboard
- Enables testing users against rules if there isn't an active request

0.10.0
==================
- Adds static and dynamic segments

0.9.1 (tbd)
==================

Expand Down
5 changes: 4 additions & 1 deletion MANIFEST.in
@@ -1,3 +1,6 @@
include README.rst

recursive-include src
recursive-include src *

recursive-exclude src __pycache__
recursive-exclude src *.py[co]
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -55,10 +55,10 @@
# built documents.
#
# The short X.Y version.
version = '0.9.1'
version = '0.11.3'

# The full version, including alpha/beta/rc tags.
release = '0.9.1'
release = '0.11.3'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
10 changes: 5 additions & 5 deletions frontend/scss/dashboard.scss
Expand Up @@ -86,18 +86,18 @@
padding: 0;
margin: 0;
list-style: none;
.stat_card {
display: inline-block;
margin-bottom: 5px;
margin-right: 10px;
}
}

.block_container .block span.icon::before {
margin-right: 0.3em;
vertical-align: bottom;
}

.block_container .block .inspect_container .inspect li {
display: inline-block;
margin-bottom: 5px;
}

.block_container .block .inspect_container .inspect li span {
display: block;
font-size: 20px;
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.1
current_version = 0.11.3
commit = true
tag = true
tag_name = {new_version}
Expand All @@ -15,14 +15,14 @@ python_paths = .
[flake8]
ignore = E731
max-line-length = 120
exclude =
exclude =
src/**/migrations/*.py

[wheel]
universal = 1

[coverage:run]
omit =
omit =
src/**/migrations/*.py

[bumpversion:file:setup.py]
Expand Down
16 changes: 5 additions & 11 deletions setup.py
@@ -1,7 +1,6 @@
import re
from setuptools import find_packages, setup


install_requires = [
'wagtail>=2.0,<2.1',
'user-agents>=1.0.1',
Expand All @@ -21,6 +20,7 @@
'pytest-sugar==0.9.1',
'pytest==3.4.2',
'wagtail_factories==1.0.0',
'pytest-mock==1.6.3',
]

docs_require = [
Expand All @@ -33,11 +33,11 @@

setup(
name='wagtail-personalisation',
version='0.9.1',
version='0.12.0',
description='A Wagtail add-on for showing personalized content',
author='Lab Digital BV',
author='Lab Digital BV and others',
author_email='opensource@labdigital.nl',
url='http://labdigital.nl',
url='https://labdigital.nl/',
install_requires=install_requires,
tests_require=tests_require,
extras_require={
Expand All @@ -55,16 +55,10 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Framework :: Django',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2',
'Topic :: Internet :: WWW/HTTP :: Site Management',
],
)
59 changes: 42 additions & 17 deletions src/wagtail_personalisation/adapters.py
Expand Up @@ -66,17 +66,21 @@ def __init__(self, request):
self.request.session.setdefault('segments', [])
self._segment_cache = None

def get_segments(self):
def get_segments(self, key="segments"):
"""Return the persistent segments stored in the request session.
:param key: The key under which the segments are stored
:type key: String
:returns: The segments in the request session
:rtype: list of wagtail_personalisation.models.Segment or empty list
"""
if self._segment_cache is not None:
if key == "segments" and self._segment_cache is not None:
return self._segment_cache

raw_segments = self.request.session['segments']
if key not in self.request.session:
return []
raw_segments = self.request.session[key]
segment_ids = [segment['id'] for segment in raw_segments]

segments = (
Expand All @@ -86,14 +90,17 @@ def get_segments(self):
.in_bulk(segment_ids))

retval = [segments[pk] for pk in segment_ids if pk in segments]
self._segment_cache = retval
if key == "segments":
self._segment_cache = retval
return retval

def set_segments(self, segments):
def set_segments(self, segments, key="segments"):
"""Set the currently active segments
:param segments: The segments to set for the current request
:type segments: list of wagtail_personalisation.models.Segment
:param key: The key under which to store the segments. Optional
:type key: String
"""
cache_segments = []
Expand All @@ -108,8 +115,9 @@ def set_segments(self, segments):
serialized_segments.append(serialized)
segment_ids.add(segment.pk)

self.request.session['segments'] = serialized_segments
self._segment_cache = cache_segments
self.request.session[key] = serialized_segments
if key == "segments":
self._segment_cache = cache_segments

def get_segment_by_id(self, segment_id):
"""Find and return a single segment from the request session.
Expand All @@ -132,18 +140,19 @@ def add_page_visit(self, page):
if page_visits:
for page_visit in page_visits:
page_visit['count'] += 1
page_visit['path'] = page.url_path if page else self.request.path
self.request.session.modified = True
else:
visit_count.append({
'slug': page.slug,
'id': page.pk,
'path': self.request.path,
'path': page.url_path if page else self.request.path,
'count': 1,
})

def get_visit_count(self, page=None):
"""Return the number of visits on the current request or given page"""
path = page.path if page else self.request.path
path = page.url_path if page else self.request.path
visit_count = self.request.session.setdefault('visit_count', [])
for visit in visit_count:
if visit['path'] == path:
Expand All @@ -170,21 +179,37 @@ def refresh(self):
rule_models = AbstractBaseRule.get_descendant_models()

current_segments = self.get_segments()
excluded_segments = self.get_segments("excluded_segments")

# Run tests on all remaining enabled segments to verify applicability.
additional_segments = []
for segment in enabled_segments:
segment_rules = []
for rule_model in rule_models:
segment_rules.extend(rule_model.objects.filter(segment=segment))

result = self._test_rules(segment_rules, self.request,
match_any=segment.match_any)

if result:
if segment.is_static and segment.static_users.filter(id=self.request.user.id).exists():
additional_segments.append(segment)
elif (segment.excluded_users.filter(id=self.request.user.id).exists() or
segment in excluded_segments):
continue
elif not segment.is_static or not segment.is_full:
segment_rules = []
for rule_model in rule_models:
segment_rules.extend(rule_model.objects.filter(segment=segment))

result = self._test_rules(segment_rules, self.request,
match_any=segment.match_any)

if result and segment.randomise_into_segment():
if segment.is_static and not segment.is_full:
if self.request.user.is_authenticated():
segment.static_users.add(self.request.user)
additional_segments.append(segment)
elif result:
if segment.is_static and self.request.user.is_authenticated():
segment.excluded_users.add(self.request.user)
else:
excluded_segments += [segment]

self.set_segments(current_segments + additional_segments)
self.set_segments(excluded_segments, "excluded_segments")
self.update_visit_count()


Expand Down
2 changes: 2 additions & 0 deletions src/wagtail_personalisation/admin_urls.py
Expand Up @@ -13,4 +13,6 @@
views.copy_page_view, name='copy_page'),
url(r'^segment/toggle_segment_view/$',
views.toggle_segment_view, name='toggle_segment_view'),
url(r'^segment/users/(?P<segment_id>[0-9]+)$',
views.segment_user_data, name='segment_user_data'),
]

0 comments on commit 5536adc

Please sign in to comment.