Add FieldList wrapper for grid columns list

needs to be merged with the "forms2" equivalent at some point...
This commit is contained in:
Lance Edgar 2018-01-25 14:43:30 -06:00
parent f32cf3342c
commit 62d1918892

View file

@ -48,6 +48,20 @@ from tailbone.db import Session
from tailbone.util import raw_datetime from tailbone.util import raw_datetime
class FieldList(list):
"""
Convenience wrapper for a field list.
"""
def insert_before(self, field, newfield):
i = self.index(field)
self.insert(i, newfield)
def insert_after(self, field, newfield):
i = self.index(field)
self.insert(i + 1, newfield)
class Grid(object): class Grid(object):
""" """
Core grid class. In sore need of documentation. Core grid class. In sore need of documentation.
@ -63,7 +77,7 @@ class Grid(object):
self.key = key self.key = key
self.data = data self.data = data
self.columns = columns self.columns = FieldList(columns) if columns is not None else None
self.width = width self.width = width
self.request = request self.request = request
self.mobile = mobile self.mobile = mobile
@ -114,6 +128,12 @@ class Grid(object):
if key in self.columns: if key in self.columns:
self.columns.remove(key) self.columns.remove(key)
def insert_before(self, field, newfield):
self.columns.insert_before(field, newfield)
def insert_after(self, field, newfield):
self.columns.insert_after(field, newfield)
def set_joiner(self, key, joiner): def set_joiner(self, key, joiner):
if joiner is None: if joiner is None:
self.joiners.pop(key, None) self.joiners.pop(key, None)