7

Content for the rule modals. WIP

This commit is contained in:
Jasper Berghoef
2016-11-10 12:50:51 +01:00
parent e2ff533e7a
commit 6886a8aaad
6 changed files with 102 additions and 2 deletions

View File

@ -9,4 +9,8 @@ urlpatterns = [
url(r'^segment/(\d+)/$', views.overview, name='overview'),
url(r'^segment/(?P<segment_id>[0-9]+)/enable/$', views.enable, name='enable'),
url(r'^segment/(?P<segment_id>[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"),
]

View File

@ -12,7 +12,11 @@
<form action="{% block form_action %}{{ view.create_url }}{% endblock %}" {% if is_multipart %} enctype="multipart/form-data"
{% endif %} method="POST" novalidate>
{% csrf_token %} {% block form %}{{ edit_handler.render_form_content }}{% endblock %}
{% csrf_token %}
{% block form %}
{{ edit_handler.render_form_content }}
{% endblock %}
<ul class="objects">
<li class="object">

View File

@ -0,0 +1,17 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n staticfiles %}
{% block titletag %}{% trans "Referral Rule" %}{% endblock %}
{% block content %}
<div class="nice-padding">
<h2>Referral</h2>
<p>Choose the number of visits the user has to have made.</p>
</div>
<div class="nice-padding">
<form>
{{ form_fields }}
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n staticfiles %}
{% block titletag %}{% trans "Time Rule" %}{% endblock %}
{% block content %}
<div class="nice-padding">
<h2>Time</h2>
<p>Choose a time segment in which the user visits the site.</p>
</div>
<div class="nice-padding">
<form>
{{ form_fields }}
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n staticfiles %}
{% block titletag %}{% trans "Visit Coint Rule" %}{% endblock %}
{% block content %}
<div class="nice-padding">
<h2>Visit count</h2>
<p>Define a referring page, domain or query the user has to come from.</p>
</div>
<div class="nice-padding">
<form>
{{ form_fields }}
</form>
</div>
{% endblock %}

View File

@ -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,
})