diff --git a/src/personalisation/models.py b/src/personalisation/models.py index d2fe281..8438445 100644 --- a/src/personalisation/models.py +++ b/src/personalisation/models.py @@ -37,6 +37,13 @@ class AbstractBaseRule(models.Model): def __str__(self): return "Abstract segmentation rule" + def encoded_name(self): + """Returns a string with a slug for the rule""" + return slugify(self.__str__().lower()) + + def description(self): + return "Abstract segmentation rule" + class Meta: abstract = True @@ -67,6 +74,18 @@ class TimeRule(AbstractBaseRule): def __str__(self): return _('Time Rule') + def description(self): + description = { + 'title': _('These users visit between'), + 'value': _('{} and {}'), + } + + description['value'] = description['value'].format( + self.start_time, + self.end_time) + + return description + @python_2_unicode_compatible class DayRule(AbstractBaseRule): @@ -115,6 +134,20 @@ class DayRule(AbstractBaseRule): def __str__(self): return _('Day Rule') + def description(self): + description = { + 'title': _('These users visit on'), + 'value': _('{}'), + } + + days = [self.mon] + + description['value'] = description['value'].format( + self.start_time, + self.end_time) + + return description + @python_2_unicode_compatible class ReferralRule(AbstractBaseRule): @@ -326,6 +359,13 @@ class Segment(ClusterableModel): """Returns a string with a slug for the segment""" return slugify(self.name.lower()) + def get_rules(self): + rules = AbstractBaseRule.__subclasses__() + segment_rules = [] + for rule in rules: + segment_rules += rule.objects.filter(segment=self) + return segment_rules + def check_status_change(sender, instance, *args, **kwargs): """Check if the status has changed. Alter dates accordingly.""" diff --git a/src/personalisation/templates/modeladmin/personalisation/segment/index.html b/src/personalisation/templates/modeladmin/personalisation/segment/index.html index f3bdd0f..fec2920 100644 --- a/src/personalisation/templates/modeladmin/personalisation/segment/index.html +++ b/src/personalisation/templates/modeladmin/personalisation/segment/index.html @@ -35,42 +35,13 @@ diff --git a/src/personalisation/wagtail_hooks.py b/src/personalisation/wagtail_hooks.py index af9ba4e..a46bef3 100644 --- a/src/personalisation/wagtail_hooks.py +++ b/src/personalisation/wagtail_hooks.py @@ -6,15 +6,17 @@ from django.conf.urls import include, url from django.shortcuts import reverse from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ +from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register +from wagtail.contrib.modeladmin.views import IndexView +from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook +from wagtail.wagtailcore import hooks + from personalisation import admin_urls from personalisation.app_settings import segments_adapter from personalisation.models import PersonalisablePage, Segment from personalisation.utils import impersonate_other_page -from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register -from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook -from wagtail.wagtailcore import hooks -logger = logging.getLogger() +logger = logging.getLogger(__name__) @hooks.register('register_admin_urls') @@ -28,9 +30,14 @@ def register_admin_urls(): ] +class SegmentModelIndexView(IndexView): + pass + + class SegmentModelAdmin(ModelAdmin): """The base model for the Segments administration interface.""" model = Segment + index_view_class = SegmentModelIndexView menu_icon = 'group' add_to_settings_menu = False list_display = ('status', 'name', 'create_date', 'edit_date')