adds referral to the admin and isorts imports
This commit is contained in:
2
Makefile
2
Makefile
@ -25,7 +25,7 @@ flake8:
|
|||||||
|
|
||||||
isort:
|
isort:
|
||||||
pip install isort
|
pip install isort
|
||||||
isort --recursive --check-only --diff src tests
|
isort --recursive src tests
|
||||||
|
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
|
@ -2,15 +2,19 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from personalisation import models
|
from personalisation import models
|
||||||
|
|
||||||
|
|
||||||
class TimeRuleAdmin(admin.ModelAdmin):
|
class TimeRuleAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'start_time', 'end_time')
|
list_display = ('name', 'start_time', 'end_time')
|
||||||
|
|
||||||
class TimeRuleAdminInline(admin.TabularInline):
|
class TimeRuleAdminInline(admin.TabularInline):
|
||||||
model = models.TimeRule
|
model = models.TimeRule
|
||||||
|
|
||||||
|
class ReferralRuleAdminInline(admin.TabularInline):
|
||||||
|
model = models.ReferralRule
|
||||||
|
|
||||||
class SegmentAdmin(admin.ModelAdmin):
|
class SegmentAdmin(admin.ModelAdmin):
|
||||||
list_display = ['name']
|
list_display = ['name']
|
||||||
inlines = (TimeRuleAdminInline,)
|
inlines = (TimeRuleAdminInline, ReferralRuleAdminInline)
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(models.TimeRule, TimeRuleAdmin)
|
admin.site.register(models.TimeRule, TimeRuleAdmin)
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from personalisation import views
|
from personalisation import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^segment/(\d+)/$', views.overview, name='overview'),
|
url(r'^segment/(\d+)/$', views.overview, name='overview'),
|
||||||
]
|
]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from personalisation.models import Segment, AbstractBaseRule
|
from personalisation.models import AbstractBaseRule, Segment
|
||||||
|
|
||||||
|
|
||||||
class SegmentMiddleware(object):
|
class SegmentMiddleware(object):
|
||||||
"""Middleware for testing and putting a user in a segment"""
|
"""Middleware for testing and putting a user in a segment"""
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
# Generated by Django 1.10.3 on 2016-11-07 13:53
|
# Generated by Django 1.10.3 on 2016-11-07 13:53
|
||||||
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
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
# Generated by Django 1.10.3 on 2016-11-07 14:12
|
# Generated by Django 1.10.3 on 2016-11-07 14:12
|
||||||
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
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
# Generated by Django 1.10.3 on 2016-11-08 07:47
|
# Generated by Django 1.10.3 on 2016-11-08 07: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
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
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.models import ClusterableModel
|
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
from modelcluster.models import ClusterableModel
|
||||||
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
||||||
|
|
||||||
|
|
||||||
@ -67,12 +66,16 @@ class TimeRule(AbstractBaseRule):
|
|||||||
super(TimeRule, self).__init__(*args, **kwargs)
|
super(TimeRule, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def test_user(self):
|
def test_user(self):
|
||||||
current_time = datetime.now().time()
|
current_time = self.get_current_time()
|
||||||
starting_time = self.start_time
|
starting_time = self.start_time
|
||||||
ending_time = self.end_time
|
ending_time = self.end_time
|
||||||
|
|
||||||
return starting_time <= current_time <= ending_time
|
return starting_time <= current_time <= ending_time
|
||||||
|
|
||||||
|
def get_current_time(self):
|
||||||
|
"""Mockable function for testing purposes"""
|
||||||
|
return datetime.now().time()
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Referral rule to segment users based on a regex test
|
Referral rule to segment users based on a regex test
|
||||||
|
@ -7,4 +7,4 @@ from django.shortcuts import render
|
|||||||
Segments overview
|
Segments overview
|
||||||
"""
|
"""
|
||||||
def overview(request):
|
def overview(request):
|
||||||
return render(request, 'wagtailadmin/segment.html')
|
return render(request, 'wagtailadmin/segment.html')
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from wagtail.wagtailadmin import widgets
|
|
||||||
from wagtail.wagtailadmin.menu import MenuItem
|
|
||||||
|
|
||||||
from personalisation import admin_urls
|
|
||||||
from wagtail.contrib.modeladmin.helpers import ButtonHelper
|
from wagtail.contrib.modeladmin.helpers import ButtonHelper
|
||||||
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
|
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
|
||||||
|
from wagtail.wagtailadmin import widgets
|
||||||
|
from wagtail.wagtailadmin.menu import MenuItem
|
||||||
from wagtail.wagtailcore import hooks
|
from wagtail.wagtailcore import hooks
|
||||||
|
|
||||||
|
from personalisation import admin_urls
|
||||||
from personalisation.models import Segment
|
from personalisation.models import Segment
|
||||||
|
|
||||||
|
|
||||||
|
12
tests/test_models.py
Normal file
12
tests/test_models.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from personalisation.models import TimeRule
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_create_time_rule():
|
||||||
|
time_rule = TimeRule(name='test', start_time="08:00:00", end_time="23:00:00")
|
||||||
|
|
||||||
|
with mock.patch('TimeRule.get_current_time', return_value=datetime.time(10, 00, 00)):
|
||||||
|
assert time_rule.test_user() is True
|
Reference in New Issue
Block a user