diff --git a/src/personalisation/admin_urls.py b/src/personalisation/admin_urls.py index 49ac124..ee518d0 100644 --- a/src/personalisation/admin_urls.py +++ b/src/personalisation/admin_urls.py @@ -9,4 +9,8 @@ urlpatterns = [ url(r'^segment/(\d+)/$', views.overview, name='overview'), url(r'^segment/(?P[0-9]+)/enable/$', views.enable, name='enable'), url(r'^segment/(?P[0-9]+)/disable/$', views.disable, name='disable'), + # TODO: These might no longer be needed when using a modal + url(r'^segment/time-rule/$', views.time_rule_embed, name="time_rule_embed"), + url(r'^segment/referral-rule/$', views.referral_rule_embed, name="refferal_rule_embed"), + url(r'^segment/visit-count-rule/$', views.visit_c_rule_embed, name="visit_count_rule_embed"), ] diff --git a/src/personalisation/templates/modeladmin/personalisation/segment/create.html b/src/personalisation/templates/modeladmin/personalisation/segment/create.html index 07830e0..07305ec 100644 --- a/src/personalisation/templates/modeladmin/personalisation/segment/create.html +++ b/src/personalisation/templates/modeladmin/personalisation/segment/create.html @@ -12,7 +12,11 @@
- {% csrf_token %} {% block form %}{{ edit_handler.render_form_content }}{% endblock %} + {% csrf_token %} + + {% block form %} + {{ edit_handler.render_form_content }} + {% endblock %}
  • diff --git a/src/personalisation/templates/wagtailadmin/embeds/referral_rule.html b/src/personalisation/templates/wagtailadmin/embeds/referral_rule.html new file mode 100644 index 0000000..394f763 --- /dev/null +++ b/src/personalisation/templates/wagtailadmin/embeds/referral_rule.html @@ -0,0 +1,17 @@ +{% extends "wagtailadmin/base.html" %} +{% load i18n staticfiles %} +{% block titletag %}{% trans "Referral Rule" %}{% endblock %} + + +{% block content %} +
    +

    Referral

    +

    Choose the number of visits the user has to have made.

    +
    + +
    + + {{ form_fields }} + +
    +{% endblock %} diff --git a/src/personalisation/templates/wagtailadmin/embeds/time_rule.html b/src/personalisation/templates/wagtailadmin/embeds/time_rule.html new file mode 100644 index 0000000..40cbeb9 --- /dev/null +++ b/src/personalisation/templates/wagtailadmin/embeds/time_rule.html @@ -0,0 +1,17 @@ +{% extends "wagtailadmin/base.html" %} +{% load i18n staticfiles %} +{% block titletag %}{% trans "Time Rule" %}{% endblock %} + + +{% block content %} +
    +

    Time

    +

    Choose a time segment in which the user visits the site.

    +
    + +
    +
    + {{ form_fields }} +
    +
    +{% endblock %} diff --git a/src/personalisation/templates/wagtailadmin/embeds/visit_count_rule.html b/src/personalisation/templates/wagtailadmin/embeds/visit_count_rule.html new file mode 100644 index 0000000..91b67f3 --- /dev/null +++ b/src/personalisation/templates/wagtailadmin/embeds/visit_count_rule.html @@ -0,0 +1,17 @@ +{% extends "wagtailadmin/base.html" %} +{% load i18n staticfiles %} +{% block titletag %}{% trans "Visit Coint Rule" %}{% endblock %} + + +{% block content %} +
    +

    Visit count

    +

    Define a referring page, domain or query the user has to come from.

    +
    + +
    +
    + {{ form_fields }} +
    +
    +{% endblock %} diff --git a/src/personalisation/views.py b/src/personalisation/views.py index 62547a0..38de9c6 100644 --- a/src/personalisation/views.py +++ b/src/personalisation/views.py @@ -1,10 +1,12 @@ from __future__ import absolute_import, unicode_literals +from django.forms import ModelForm from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, render from django.urls import reverse -from personalisation.models import Segment +from personalisation.models import ( + ReferralRule, Segment, TimeRule, VisitCountRule) def overview(request): @@ -26,3 +28,42 @@ def disable(request, segment_id): segment.save() return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + +# TODO: Make these requestable from an exsisting page (the create page.) +# This code might become obselete. + +class TimeRuleForm(ModelForm): + """Create a form for the time rule model.""" + class Meta: + model = TimeRule + fields = ['start_time', 'end_time'] + +def time_rule_embed(request): + """Show the content of the time rule modal.""" + return render(request, 'wagtailadmin/embeds/time_rule.html', { + 'form_fields': TimeRuleForm(), + }) + +class ReferralRuleForm(ModelForm): + """Create a form for the referral rule model.""" + class Meta: + model = ReferralRule + fields = ['regex_string'] + +def referral_rule_embed(request): + """Show the content of the referral rule modal.""" + return render(request, 'wagtailadmin/embeds/referral_rule.html', { + 'form_fields': ReferralRuleForm, + }) + +class VisitCountRuleForm(ModelForm): + """Create a form for the visit count rule model.""" + class Meta: + model = VisitCountRule + fields = ['operator', 'count'] + +def visit_c_rule_embed(request): + """Show the content of the visit count rule modal.""" + return render(request, 'wagtailadmin/embeds/visit_count_rule.html', { + 'form_fields': VisitCountRule, + })