From 053dc1df73b879ed6f87a0be249f388cea10700d Mon Sep 17 00:00:00 2001 From: Rob Moorman Date: Wed, 31 May 2017 15:09:29 +0200 Subject: [PATCH 1/2] Add naturaltime for active segments --- README.rst | 7 +++---- docs/getting_started.rst | 6 +++--- sandbox/sandbox/settings.py | 1 + .../wagtail_personalisation/segment/dashboard.html | 6 +++--- tests/sandbox/settings.py | 1 + 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index f14cbf79..7fe0da01 100644 --- a/README.rst +++ b/README.rst @@ -38,16 +38,15 @@ To install the package with pip:: pip install wagtail-personalisation -Next, include the ``wagtail_personalisation`` and -``wagtail.contrib.modeladmin`` app in your project's ``INSTALLED_APPS``: +Next, add the required apps in your ``INSTALLED_APPS`` setting: .. code-block:: python INSTALLED_APPS = [ - # ... + # Required apps + 'django.contrib.humanize', 'wagtail.contrib.modeladmin', 'wagtail_personalisation', - # ... ] Make sure that ``django.contrib.sessions.middleware.SessionMiddleware`` has diff --git a/docs/getting_started.rst b/docs/getting_started.rst index b07acb5e..5c166f1b 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -16,13 +16,13 @@ The Wagxperience app runs in the Wagtail CMS. You can find out more here_. pip install wagtail-personalisation -2. Add the module and ``wagtail.contrib.modeladmin`` to your ``INSTALLED_APPS``:: +2. Add the required apps in your ``INSTALLED_APPS`` setting:: INSTALLED_APPS = [ - # ... + # Required apps + 'django.contrib.humanize', 'wagtail.contrib.modeladmin', 'wagtail_personalisation', - # ... ] 3. Update your database:: diff --git a/sandbox/sandbox/settings.py b/sandbox/sandbox/settings.py index 736e00e9..14b961e1 100644 --- a/sandbox/sandbox/settings.py +++ b/sandbox/sandbox/settings.py @@ -53,6 +53,7 @@ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', + 'django.contrib.humanize', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', diff --git a/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html b/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html index 7b725112..f42cddc6 100644 --- a/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html +++ b/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html @@ -1,5 +1,5 @@ {% extends "modeladmin/wagtail_personalisation/segment/base.html" %} -{% load i18n l10n staticfiles modeladmin_tags wagtail_personalisation_filters %} +{% load humanize i18n l10n staticfiles modeladmin_tags wagtail_personalisation_filters %} {% block toggle_view %}to List {% endblock%} @@ -31,8 +31,8 @@

{{ segment }}

{{ segment.visit_count|localize }} {% trans "time" %}{{ segment.visit_count|pluralize }}
  • - {% trans "This segment has been active for" %} - {{ segment.enable_date|days_since:segment.disable_date }} {% trans "day" %}{{ segment.enable_date|days_since:segment.disable_date|pluralize }} + {% trans "This segment has been active since" %} + {{ segment.enable_date|naturaltime }}
  • diff --git a/tests/sandbox/settings.py b/tests/sandbox/settings.py index a8aff385..c395163b 100644 --- a/tests/sandbox/settings.py +++ b/tests/sandbox/settings.py @@ -82,6 +82,7 @@ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', + 'django.contrib.humanize', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', From 7c222421335f36bcf784be4526c2aa08404d4c6d Mon Sep 17 00:00:00 2001 From: Rob Moorman Date: Wed, 31 May 2017 17:41:23 +0200 Subject: [PATCH 2/2] Pluralize visit count --- src/wagtail_personalisation/rules.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wagtail_personalisation/rules.py b/src/wagtail_personalisation/rules.py index c6f1ee7c..86be8837 100644 --- a/src/wagtail_personalisation/rules.py +++ b/src/wagtail_personalisation/rules.py @@ -4,7 +4,7 @@ from datetime import datetime from django.db import models -from django.template.defaultfilters import slugify +from django.template.defaultfilters import pluralize, slugify from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ from modelcluster.fields import ParentalKey @@ -251,9 +251,10 @@ def description(self): 'title': _('These users visited {}').format( self.counted_page ), - 'value': _('{} {} times').format( + 'value': _('{} {} time{}').format( self.get_operator_display(), - self.count + self.count, + pluralize(self.count) ), }