8

Use a form to clean the instance

This commit is contained in:
Todd Dembrey
2017-10-23 15:00:31 +01:00
parent c6ff2801c5
commit 44cc95617e
3 changed files with 54 additions and 19 deletions

View File

@@ -26,6 +26,8 @@ from wagtail.wagtailcore.models import Page
from wagtail_personalisation.rules import AbstractBaseRule
from wagtail_personalisation.utils import count_active_days
from .forms import SegmentAdminForm
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
@@ -103,6 +105,8 @@ class Segment(ClusterableModel):
objects = SegmentQuerySet.as_manager()
base_form_class = SegmentAdminForm
def __init__(self, *args, **kwargs):
Segment.panels = [
MultiFieldPanel([
@@ -131,12 +135,6 @@ class Segment(ClusterableModel):
def __str__(self):
return self.name
def clean(self):
if self.is_static and not self.is_consistent and not self.count:
raise ValidationError({
'count': _('Static segments with non-static compatible rules must include a count.'),
})
@property
def is_static(self):
return self.type == self.TYPE_STATIC