[web2py] Re: simple table div

2010-11-11 Thread Lance
I like it:)

On 11월11일, 오전7시08분, "Martin.Mulone"  wrote:
> I decided to start to make my own implementation of table maker. The
> diference with sqltable or TABLE(), it use div (more flexible), accept
> web2py helpers as values and is very simple to use.
>
> Example:
>
> http://web2pytesting.appspot.com/tablediv/
>
> Code:
>
> table =
> SIMPLE_TABLE_DIV(fixedwidth=True,maxwidth=500,name="simplet1",number_list=T 
> rue)
> table.add_header([{'caption':'Header 1', 'width': 200},
>   {'caption':'Header 2', 'width': 100},
>   {'caption':'Header 3', 'width':
> 100},
>   ])
> table.add_row(['Value 1','Value 2', 'Value 3'])
> table.add_row(['Value 4','Value 5', 'Value 6'])
> table.add_row(['Value 7','Value 8', 'Value 9'])
>
> If anyone is interested in this or want to contribute, i will put in
> bitbucket.


[web2py] Re: simple table div

2010-11-10 Thread Martín Mulone
this is the model

2010/11/10 Martin.Mulone 

> I decided to start to make my own implementation of table maker. The
> diference with sqltable or TABLE(), it use div (more flexible), accept
> web2py helpers as values and is very simple to use.
>
> Example:
>
> http://web2pytesting.appspot.com/tablediv/
>
> Code:
>
> table =
>
> SIMPLE_TABLE_DIV(fixedwidth=True,maxwidth=500,name="simplet1",number_list=True)
> table.add_header([{'caption':'Header 1', 'width': 200},
>  {'caption':'Header 2', 'width': 100},
>  {'caption':'Header 3', 'width':
> 100},
>  ])
> table.add_row(['Value 1','Value 2', 'Value 3'])
> table.add_row(['Value 4','Value 5', 'Value 6'])
> table.add_row(['Value 7','Value 8', 'Value 9'])
>
> If anyone is interested in this or want to contribute, i will put in
> bitbucket.
>



-- 
My blog: http://martin.tecnodoc.com.ar
My portfolio *spanish*: http://www.tecnodoc.com.ar
Checkout my last proyect instant-press: http://www.instant2press.com
# -*- coding: utf-8 -*- 

# SIMPLE_TABLE_DIV
#
# Build tables, without using table, this use divs
# Coldef and rowdef is not working now,
#

# EXAMPLE

#def index():
#
##Sample table
#table = SIMPLE_TABLE_DIV(fixedwidth=True,maxwidth=500,name="simplet1",number_list=True)
#table.add_header([{'caption':'Header 1', 'width': 200},
#  {'caption':'Header 2', 'width': 100},
#  {'caption':'Header 3', 'width': 100},  
#  ])
#table.add_row(['Value 1','Value 2', 'Value 3'])
#table.add_row(['Value 4','Value 5', 'Value 6'])
#table.add_row(['Value 7','Value 8', 'Value 9'])
#
#
##Sample table with HTML HELPERS
#table2 = SIMPLE_TABLE_DIV(fixedwidth=True,maxwidth=530,name="simplet2")
#table2.add_header([{'caption':'Name', 'width': 200},
#  {'caption':'Surname', 'width': 200},
#  {'caption':'Tel.', 'width': 100},  
#  ])
#table2.add_row(['Michael', A('Douglas',_href="#douglas"), '22-33'])
#table2.add_row(['Bill', A('Kid',_href="#kid"), '33--333'],highlight=True)
#table2.add_row(['Von',A('Durssen',_href="#durssen"), '-'])
#table2.add_row(['Don',A('Jhonson',_href="#durssen"), '-'])
#table2.add_row(['Brad',A('Pitt',_href="#durssen"), '-'])
#
#
##Sample table with HTML HELPERS AND ICONS
#url_edit = URL(request.application,'static','images/edit.png')
#url_apply = URL(request.application,'static','images/apply.png')
#url_disable = URL(request.application,'static','images/disable.png')
#
#table3 = SIMPLE_TABLE_DIV(fixedwidth=True,maxwidth=550,name="simplet3")
#table3.add_header([{'caption':'Name', 'width': 200},
#  {'caption':'Email', 'width': 200},
#  {'caption':'Edit', 'width': 30},
#  {'caption':'Appl.', 'width': 30},
#  {'caption':'Disa.', 'width': 30},
#  ])
#table3.add_row(['Michael Douglas', A('doug...@mail.com',_href="#"), IMG(_src=url_edit), IMG(_src=url_apply), IMG(_src=url_disable)])
#table3.add_row(['Paul Simon', A('p...@mail.com',_href="#"), IMG(_src=url_edit), IMG(_src=url_apply), IMG(_src=url_disable)])
#table3.add_row(['James Hetfield', A('ja...@mail.com',_href="#"), IMG(_src=url_edit), IMG(_src=url_apply), IMG(_src=url_disable)])
#
#return dict(table=table, table2=table2, table3=table3)

class SIMPLE_TABLE_COLUMN(object):

def __init__(self, name="", caption="", width=100, highlight=False ):

self.name = name
self.caption = caption
self.width = width
self.highlight = highlight

class SIMPLE_TABLE_ROW(object):

def __init__(self, values=[], header=None, highlight=False ):
   
self.values = values
self.header = header
self.highlight = highlight

 
class SIMPLE_TABLE_HEADER(object):

def __init__(self, coldef=[], default_width=100):

if not isinstance(coldef, list):
raise SyntaxError, 'something wrong in headers must be a list type'

if coldef != []: 
newcolumns=[]   
for col in coldef:

try:
caption = col['caption']
except KeyError:
raise KeyError, "Not a valid column caption, must contain a caption"

try:
name = col['name']
except KeyError:
name = caption #if there no name use caption

try:
width = int(col['width'])
except:
width = default_width #if there no name use caption