Some code cleanup.

fixed #76
This commit is contained in:
Antoine Nguyen
2011-07-27 10:49:55 +02:00
parent 81a03d6c65
commit 893dcfdb3f
6 changed files with 77 additions and 60 deletions
+23
View File
@@ -1,4 +1,13 @@
# -*- coding: utf-8 -*-
"""
:mod:`tables` --- simple tabular renderer
-----------------------------------------
This module offers a simple (I hope so) interface to render tabular
data. For a given Table class, it generates the corresponding HTML
output (using standard tags like <table> and co.).
"""
import inspect
import lxml
from django.utils.translation import ugettext as _
@@ -6,6 +15,8 @@ from django.template import Template, Context
from django.template.loader import render_to_string
class Column:
"""Simple column representation
"""
sortable = True
def __init__(self, name, **kwargs):
@@ -22,6 +33,11 @@ class Column:
class SelectionColumn(Column):
"""Specific column: selection
A 'selection' column contains only checkboxes (one per row). It is
usefull to select rows for grouped actions (modify, delete, etc.)
"""
def __str__(self):
return "<input type='checkbox' name='selectall' id='selectall' />"
@@ -30,6 +46,10 @@ class SelectionColumn(Column):
% (self.name, value, value, selection and "checked" or "")
class ImgColumn(Column):
"""Specific column: image
This kind of column only contains images tags (<img>).
"""
sortable = False
def __str__(self):
@@ -164,6 +184,9 @@ class Table(object):
except AttributeError:
return value
def __str__(self):
return self.render()
def render(self):
if len(self.rows):
t = Template("""