I think it is better if you use .join() to concatenate the selectors, or
create a function in a model file to return the properties.
file models/css.py
<code>
def return_css(company_id):
rows = db(....==company_id).select(......)
oldselector = None
css = []
for row in rows:
if row.selector!=oldselector:
css.append(dict(selector=row.selector,\
property=row.property,\
value=row.value
)
)
oldselector=row.selector
code = ''
for c in css:
code = code + '%(selector)s{%(property)s:%(value)s;}' % c
return code
</code>
(may be you need to improve the code above)
and in view you do
{{=return_css(xyz)}}
or in your code in view
{{oldselector=None}}
{{for row in rows}}
{{if row.selector!=oldselector}}
{{=row.selector}} {
{{oldselector=row.selector}}
{{pass}}
{{=row.property}}:{{=row.value:}};
}
{{pass}}
2010/9/27 annet <[email protected]>
> I have a table in which users can insert css declarations to customize
> a page. In a controller I retrieve these declarations, and in a view I
> would like them to be inserted in the head section.
>
> This is what the rows object contains:
>
> declaration_id 1
> declaration.company_id 263
> declaration_selector #header
> declaration_property background-color
> declaration.value #4169E1
>
> declaration_id 1
> declaration.company_id 263
> declaration_selector #header
> declaration_property color
> declaration.value #FFFFFF
>
>
> This is what the head section should contain:
>
> #header{background-color:#4169E1;color:#FFFFFF;}
>
>
> I started off like this:
>
> {{oldselector=None}}
> {{for row in rows}}
> {{if row.selector!=oldselector}}
> {{=row.selector}} {
> {{oldselector=row.selector}}
> {{pass}}
> {{=row.property}}:{{=row.value:}};
> {{pass}}
>
>
> The problem is that I can't figure out how to insert the closing } in:
> #header{background-color:#4169E1;color:#FFFFFF;}
>
> I hope one of you could help me solve this problem.
>
> Furthermore, I wonder whether this is right approach or whether there
> is a better way to implement this.
>
>
> Kind regards,
>
> Annet.
--
http://rochacbruno.com.br