From 3e254fba04324a3ecef217e7c24b7cfeacdccc48 Mon Sep 17 00:00:00 2001 From: Boris Besemer Date: Thu, 10 Nov 2016 11:29:33 +0100 Subject: [PATCH] adds custom create model form, wip --- src/personalisation/forms.py | 23 +++++++++++++++++++++++ src/personalisation/middleware.py | 4 ++++ src/personalisation/models.py | 2 +- src/personalisation/views.py | 6 ++++++ tests/__init__.py | 0 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/personalisation/forms.py delete mode 100644 tests/__init__.py diff --git a/src/personalisation/forms.py b/src/personalisation/forms.py new file mode 100644 index 0000000..6f9951c --- /dev/null +++ b/src/personalisation/forms.py @@ -0,0 +1,23 @@ +from __future__ import absolute_import, unicode_literals + +from django import forms +from django.conf import settings +from django.utils.translation import ugettext as _ +from wagtail.wagtailcore.models import Page + +from personalisation.models import Segment + + +class SegmentForm(forms.ModelForm): + """ + Custom Segment form for the create view + """ + class Meta: + model = Segment + fields = ( + 'name', + 'status', + ) + + def __init__(self, *args, **kwargs): + super(SegmentForm, self).__init__(*args, **kwargs) diff --git a/src/personalisation/middleware.py b/src/personalisation/middleware.py index 7c088a9..3f1ecd2 100644 --- a/src/personalisation/middleware.py +++ b/src/personalisation/middleware.py @@ -1,4 +1,7 @@ import time +import logging + +logger = logging.getLogger() from personalisation.models import AbstractBaseRule, Segment @@ -27,6 +30,7 @@ class SegmentMiddleware(object): self.add_segment_to_user(segment, request) response = self.get_response(request) + logger.info("User has been added to the following segments: {}".format(request.session['segments'])) return response def test_rules(self, rules, request): diff --git a/src/personalisation/models.py b/src/personalisation/models.py index 8f46458..72b0da0 100644 --- a/src/personalisation/models.py +++ b/src/personalisation/models.py @@ -107,7 +107,7 @@ class TimeRule(AbstractBaseRule): @python_2_unicode_compatible class ReferralRule(AbstractBaseRule): """Referral rule to segment users based on a regex test""" - regex_string = models.TextField() + regex_string = models.TextField(_("Regex string to match the referer with")) panels = [ FieldPanel('regex_string'), diff --git a/src/personalisation/views.py b/src/personalisation/views.py index 62547a0..5bce92a 100644 --- a/src/personalisation/views.py +++ b/src/personalisation/views.py @@ -4,7 +4,10 @@ from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, render from django.urls import reverse +from wagtail.wagtailadmin.views import generic + from personalisation.models import Segment +from personalisation.forms import SegmentForm def overview(request): @@ -26,3 +29,6 @@ def disable(request, segment_id): segment.save() return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + + + diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000