adds a few docblocks and isorts
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
@@ -43,6 +44,9 @@ class BaseSegmentsAdapter(object):
|
|||||||
|
|
||||||
|
|
||||||
class SessionSegmentsAdapter(BaseSegmentsAdapter):
|
class SessionSegmentsAdapter(BaseSegmentsAdapter):
|
||||||
|
"""
|
||||||
|
Segment adapter that uses Django's session backend.
|
||||||
|
"""
|
||||||
def setup(self, request):
|
def setup(self, request):
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
@@ -96,4 +100,3 @@ class SessionSegmentsAdapter(BaseSegmentsAdapter):
|
|||||||
self.request.session['segments'] = new_segments
|
self.request.session['segments'] = new_segments
|
||||||
|
|
||||||
update_visit_count(self)
|
update_visit_count(self)
|
||||||
|
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
|
|
||||||
|
|
||||||
segments_adapter = import_string(getattr(settings, 'PERSONALISATION_SEGMENTS_ADAPTER', 'personalisation.adapters.SessionSegmentsAdapter'))()
|
segments_adapter = import_string(getattr(settings, 'PERSONALISATION_SEGMENTS_ADAPTER', 'personalisation.adapters.SessionSegmentsAdapter'))()
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from wagtail.wagtailcore import blocks
|
from wagtail.wagtailcore import blocks
|
||||||
|
|
||||||
from personalisation.models import Segment
|
from personalisation.models import Segment
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
# Generated by Django 1.10.1 on 2016-12-11 12:15
|
# Generated by Django 1.10.1 on 2016-12-11 12:15
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import modelcluster.fields
|
import modelcluster.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
# Generated by Django 1.10.5 on 2017-01-10 14:35
|
# Generated by Django 1.10.5 on 2017-01-10 14:35
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import modelcluster.fields
|
import modelcluster.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
# Generated by Django 1.10.7 on 2017-04-20 15:47
|
# Generated by Django 1.10.7 on 2017-04-20 15:47
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import modelcluster.fields
|
import modelcluster.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@@ -2,13 +2,13 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from user_agents import parse
|
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from modelcluster.fields import ParentalKey
|
from modelcluster.fields import ParentalKey
|
||||||
|
from user_agents import parse
|
||||||
from wagtail.wagtailadmin.edit_handlers import (
|
from wagtail.wagtailadmin.edit_handlers import (
|
||||||
FieldPanel, FieldRowPanel, PageChooserPanel)
|
FieldPanel, FieldRowPanel, PageChooserPanel)
|
||||||
|
|
||||||
|
@@ -1,6 +1,13 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def impersonate_other_page(page, other_page):
|
def impersonate_other_page(page, other_page):
|
||||||
|
"""
|
||||||
|
Function to change the page metadata so the user gets to see the
|
||||||
|
non-personalized path and page.
|
||||||
|
:param page: The page to be impersonated
|
||||||
|
:param other_page: The page it should impersonate
|
||||||
|
"""
|
||||||
page.path = other_page.path
|
page.path = other_page.path
|
||||||
page.depth = other_page.depth
|
page.depth = other_page.depth
|
||||||
page.url_path = other_page.url_path
|
page.url_path = other_page.url_path
|
||||||
@@ -8,6 +15,12 @@ def impersonate_other_page(page, other_page):
|
|||||||
|
|
||||||
|
|
||||||
def create_segment_dictionary(segment):
|
def create_segment_dictionary(segment):
|
||||||
|
"""
|
||||||
|
Creates a dictionary with all the required segment
|
||||||
|
information.
|
||||||
|
:param segment: Segment object
|
||||||
|
:return: Dictionary with name, id, timestamp and persistent state.
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
"encoded_name": segment.encoded_name(),
|
"encoded_name": segment.encoded_name(),
|
||||||
"id": segment.pk,
|
"id": segment.pk,
|
||||||
|
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, reverse
|
from django.shortcuts import get_object_or_404, reverse
|
||||||
|
|
||||||
from personalisation.models import PersonalisablePage, Segment
|
from personalisation.models import PersonalisablePage, Segment
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import factory
|
import factory
|
||||||
|
|
||||||
from personalisation import rules
|
from personalisation import rules
|
||||||
@@ -45,4 +46,3 @@ class VisitCountRuleFactory(factory.DjangoModelFactory):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = rules.VisitCountRule
|
model = rules.VisitCountRule
|
||||||
|
|
||||||
|
@@ -6,12 +6,10 @@ import pytest
|
|||||||
|
|
||||||
from personalisation.models import Segment
|
from personalisation.models import Segment
|
||||||
from personalisation.rules import TimeRule
|
from personalisation.rules import TimeRule
|
||||||
|
|
||||||
from tests.factories.segment import SegmentFactory
|
|
||||||
from tests.factories.rule import (
|
from tests.factories.rule import (
|
||||||
QueryRuleFactory, ReferralRuleFactory, TimeRuleFactory,
|
DayRuleFactory, DeviceRuleFactory, QueryRuleFactory, ReferralRuleFactory,
|
||||||
DayRuleFactory, VisitCountRuleFactory, DeviceRuleFactory)
|
TimeRuleFactory, VisitCountRuleFactory)
|
||||||
|
from tests.factories.segment import SegmentFactory
|
||||||
|
|
||||||
"""Factory tests"""
|
"""Factory tests"""
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
@@ -8,10 +8,10 @@ from freezegun import freeze_time
|
|||||||
from wagtail.wagtailcore.models import Page
|
from wagtail.wagtailcore.models import Page
|
||||||
from wagtail_factories import SiteFactory
|
from wagtail_factories import SiteFactory
|
||||||
|
|
||||||
from tests.factories.segment import SegmentFactory
|
|
||||||
from tests.factories.rule import (
|
from tests.factories.rule import (
|
||||||
QueryRuleFactory, ReferralRuleFactory, TimeRuleFactory,
|
DayRuleFactory, DeviceRuleFactory, QueryRuleFactory, ReferralRuleFactory,
|
||||||
DayRuleFactory, VisitCountRuleFactory, DeviceRuleFactory)
|
TimeRuleFactory, VisitCountRuleFactory)
|
||||||
|
from tests.factories.segment import SegmentFactory
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
Reference in New Issue
Block a user