Added regex to detect if a col class added to fieldrowpanel. If not, add default

This commit is contained in:
Chris Rogers 2016-03-10 15:18:42 +00:00 committed by Matt Westcott
parent ba807e5f45
commit b559f411be

View file

@ -3,6 +3,8 @@ from __future__ import absolute_import, unicode_literals
import warnings
import django
import re
import math
from django import forms
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
@ -347,6 +349,14 @@ class FieldRowPanel(object):
self.classname = classname
def bind_to_model(self, model):
col_count = " col" + str(int(math.floor(12 / len(self.children))))
# If child panel doesn't have a col# class then append default based on
# number of columns
for child in self.children:
if re.match("^.*?(col)[1-9]{1}(?![3-9])[0-2]{0,1}.*?$", child.classname) is None:
child.classname += col_count
return type(str('_FieldRowPanel'), (BaseFieldRowPanel,), {
'model': model,
'children': [child.bind_to_model(model) for child in self.children],