| 1 | # -*- encoding: UTF-8 -*- |
|---|
| 2 | |
|---|
| 3 | from genshi.template import MarkupTemplate |
|---|
| 4 | |
|---|
| 5 | tmpl = MarkupTemplate('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|---|
| 6 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 7 | <html xmlns="http://www.w3.org/1999/xhtml" |
|---|
| 8 | xmlns:py="http://genshi.edgewall.org/" |
|---|
| 9 | xmlns:xi="http://www.w3.org/2001/XInclude"> |
|---|
| 10 | <head></head> |
|---|
| 11 | <body> |
|---|
| 12 | |
|---|
| 13 | <?python |
|---|
| 14 | def order(field): |
|---|
| 15 | if field + " asc" in query["o"]: |
|---|
| 16 | return field + " desc" |
|---|
| 17 | else: |
|---|
| 18 | return field + " asc" |
|---|
| 19 | ?> |
|---|
| 20 | |
|---|
| 21 | ${order("bar desc")} |
|---|
| 22 | ${order("foo asc")} |
|---|
| 23 | |
|---|
| 24 | </body> |
|---|
| 25 | </html> |
|---|
| 26 | ''') |
|---|
| 27 | |
|---|
| 28 | stream = tmpl.generate(query=dict(o='foo asc')) |
|---|
| 29 | |
|---|
| 30 | print stream.render() |
|---|