Re: HTML generation vs PSP vs Templating Engines

2005-11-20 Thread riplin
>> Using templates means that the code can work with different templates,
>> and this should be seamless, it also means that different code can be
>> used with the templates, for example if different languages are used.

> This seems to contradict your statement that you dislike 'embedding
> code or html in each other', since the scenarios you describe still
> involve embedding presentation logic in markup. (The only templating
> systems that *completely* separate logic from markup are the DOM-style
> ones.)

Perhaps that is why I implemented my own mechanisms for templating. My
templates contain no logic at all and can be used from my Python
programs, Cobol or C equally well.

Contrarywise, my Python programs choose at runtime the required
template (depending on configuration, user request or other) and then
the same program code will output HTML, XML, EDIFACT, CSV, printed
report or other dependant entirely on the content of the template file.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-19 Thread has
[EMAIL PROTECTED] wrote:
> I dislike embedding code or html in each other, apart from the
> 'impurity' of mixing code and user interface it makes them inseparable.
>
> Using templates means that the code can work with different templates,
> and this should be seamless, it also means that different code can be
> used with the templates, for example if different languages are used.

This seems to contradict your statement that you dislike 'embedding
code or html in each other', since the scenarios you describe still
involve embedding presentation logic in markup. (The only templating
systems that *completely* separate logic from markup are the DOM-style
ones.)

I assume what you really meant is that you don't like embedding *model*
logic in markup, which is generally good design practice. However,
templating systems that use Python for presentation logic (Karrigell,
PSP, Nevow, HTMLTemplate, etc) certainly don't force you to put model
logic into the template; you are quite entitled to keep that separate
as per MVC. They just don't *enforce* the model logic/presentation
logic separation as some authoritarian custom language-based systems
do.

HTH

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-19 Thread Luis M. Gonzalez
I meant that it is not strictly necessary to use templates in
Karrigell, although you can use Cheetah if you want.
I'm not used to templates mainly because I'm familiar with the way PHP
works and, for simple dynamic sites like those I work on, this is the
simpliest approach.
Another reason is that I'm a little bit lazy for learning yet another
language, be it a python-like one or a template one.

Also, I feel that Python is easy enough for having to resort to another
language.
I usually create my pages with Dreamweaver or any other visual tool,
and once the design is ready, I add a few python lines to it which,
combined with modules that are separated from the html code, work
wonders on my sites.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-19 Thread riplin
> No templates, no python-like or special languages, only pure and simple 
> python.

> You can embedd python into html or, if it better suits your programming
> style, you can embed html into python. Why don't you give it a try?

I dislike embedding code or html in each other, apart from the
'impurity' of mixing code and user interface it makes them inseparable.

Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.

The main advantage, for me, is that different outputs formats can be
created without changing the code. If the user wants a set of data in a
table then the html template is used, if they want a csv file of the
data, that is just a different template name.  A printed report: same
code just a different template name. XML, simple text, postscript,
EDIFACT file, all done with same code, different template. Just arrange
for the name of the template file to be a parameter on the URL and the
various outputs can be selected by the user.

I did, however, write my own templating module, they are quite easy to
do.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-18 Thread has
[EMAIL PROTECTED] wrote:

> Could someone that has used all the different ways mentioned above for
> dynamic HTML
> content, suggest what the pros and cons of the different methods are?

Not used them all - as you say, there's a plethora of options - but to
give you a general idea of the territory...

First choice you have is between HTML generators vs. HTML templating
systems:

- HTML generators create all markup from scratch. Useful when producing
arbitrary markup/layout whose entire structure must be determined
programmatically, e.g. applying paragraph and character styling to a
big chunk of text, creating arbitrary HTML form layouts based on other
input. Examples: htmlgen (crusty, HTML 3.1-era), Nevow's Stan engine.

- HTML templates insert individual items of data into a mostly static
block of HTML markup written in advance by e.g. a graphic designer.
Useful when creating documents that are fairly regular in structure -
most fall into this category - as it's much easier to create the
repetitious parts using standard HTML editing tools than write code to
produce it all programmatically.

Sometimes you might combine the two methods, using an HTML generator to
create sections of markup from arbitrary input which is then inserted
into a full-page template to produce the finished HTML document.


Assuming a templating-based solution is the appropriate choice for you
(which it most likely is), there are three general approaches to choose
from:

1. Systems that embed markup in code. This is a fairly small category.
It's fairly programmer-friendly since you've direct access to all
language features, but hostile to web designers as you have to pull
your HTML markup apart and insert it into program code to produce the
final template, making it a pain to modify that markup later. Examples:
ad-hoc solutions using Python's string interpolation, the Quixote
framework's built-in templating support, Karrigell (though it supports
some aspects of approach 2 as well).

2. Systems that embed code in markup. This is the most common category
with a fair amount of variety and capabilities to choose from. Lots of
obviously PHP/ASP-inspired designs. Two sub-categories: systems that
embed standard Python code, e.g. PSP, and systems that embed a custom
language, e.g. Cheetah. Some provide no restrictions on what you can
get up to within embedded code, others restrict functionality to
enforce a strict separation between presentation logic and model logic.
Embedding styles also vary: some mix code statements and markup
directly (e.g. Cheetah), some embed code statements in special <%...%>
style tags (e.g. PSP), some hide all code within HTML tag attributes
(e.g. TAL, Kid), providing varying degrees of designer-friendliness as
a result.

3. DOM-style systems. This is a more recent arrival and a smaller
category. These systems completely separate markup from presentation
logic. Selected HTML elements are flagged using specific named tag
attributes (e.g. id="somename") or simple compiler directives, e.g.
(nevow:render="somename"); the template is then compiled into a simple
templating-oriented (i.e. not w3c) DOM, allowing these elements to be
manipulated programmatically by standard Python scripts. Very designer
and developer friendly, although less experienced programmers may find
the higher level of abstraction involved a bit offputting. Examples:
PyMeld, HTMLTemplate [1], Nevow.Render.


For a fairly extensive list of available systems, see
. Unfortunately they're not
well categorised there, but I can't think of a better, up-to-date list
off the top of my head and most will provide decent overviews so it
shouldn't take too long to take a quick look at each.

Note that some templating engines are embedded into larger web
programming frameworks and may or may not be usable independently.
Conversely, some web frameworks may be coupled to a specific templating
system, while others allow you to choose your own.

HTH

has

--
[1] Disclaimer: I wrote HTMLTemplate. Also, shameless plug:


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-17 Thread Luis M. Gonzalez
With Karrigell (http://karrigell.sf.net/), all you need to know is
Python and HTML.
No templates, no python-like or special languages, only pure and simple
python.

You can embedd python into html or, if it better suits your programming
tyle, you can embed html into python. Why don't you give it a try?

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: HTML generation vs PSP vs Templating Engines

2005-11-16 Thread Sells, Fred
If this is your first try, use cgi, cgitb and html % dictionary as suggested
in this thread.  If your db is mysql, you can actually use os.popen() (or
equivalent) to run a  'mysql -html -e "select * from yaddayadda" to return
html.  you can make that look prettier with css.
here's a quick and dirty I just did.
===snip=
===
#!/usr/bin/python
import os, string, sys, time, cgi, cgitb
cgitb.enable(display=1)
import ezcgi
HTML = """

   table {cell-padding:2; cell-spacing:2; font-family:Arial;}
   th { background-color: lightblue; cell-padding:5; cell-spacing:5;}
   td { background-color: lightgray; padding:5; spacing:5;
font-size:mediumm;}

Snapshot of Administrative Bed Holds



Current Administrative Bed Holds at all
Facilities
%s

%s

Copyright (C) 1996-2005, Adventist Care Centers, Inc.  For Internal Use
Only
http://acc.sunbelt.org";>Home|
http://acc.sunbelt.org/rwb?P001=logout";>Logout
"""

COMMAND = ['mysql --host=acaredb --user=acare --password=acare -D census -H
-e ', 
   '"SELECT facility,wrb Room,description Reason,startdate, note
Explanation',
   'FROM admin_bed_holds h, abhreasons r '
   'WHERE h.reason=r.id   ',
   ' ORDER BY facility;"']
COMMAND = ' '.join(COMMAND)

def select_holds():
x = os.popen(COMMAND)
table = x.read(6000)
return HTML % ('', table)

def execute():
if ezcgi.is_authenticated():
print ezcgi.HTML_CONTENT_TYPE
print select_holds()
else: 
ezcgi.authenticate_user()

if __name__=='__main__':
#print ezcgi.PLAIN_CONTENT_TYPE
#print COMMAND
execute()
===snip=
=
-Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 16, 2005 11:32 AM
To: python-list@python.org
Subject: HTML generation vs PSP vs Templating Engines


Hello everybody,

I am in the process of writing my very first web application in Python,
and I need a way to
generate dynamic HTML pages with data from a database.  I have to say I
am overwhelmed
by the plethora of different frameworks, templating engines, HTML
generation tools etc that
exist. After some thought I decided to leave the various frameworks
aside for the
time being and use mod_python.publisher along with some means of
generating HTML on
the fly.
Could someone that has used all the different ways mentioned above for
dynamic HTML
content, suggest what the pros and cons of the different methods are?

  Thank you very much in advance

  Panos

-- 
http://mail.python.org/mailman/listinfo/python-list

---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-16 Thread thakadu
I just do the following:

I store the form data as a pickeled dictionary. Then I create my
HTML form with something like this:

HTMLout="""..
..


'''

where the field1, field2 etc era the fields on my form.

Then finally:

print HTMLout % dict

where dict has all the values that I previously pickled.
You have to do some additional trickery for  type fields
and checkboxes and so on but its really not difficult.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-16 Thread Damjan
> After some thought I decided to leave the various frameworks
> aside for the time being and use mod_python.publisher along with some
> means of generating HTML on the fly.

I kind of like KID templates the most, you can easyly work with them in any
HTML authoring software, they are easy to use (prety much pythonic).


-- 
damjan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML generation vs PSP vs Templating Engines

2005-11-16 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
> Hello everybody,
> 
> I am in the process of writing my very first web application in Python,
> and I need a way to
> generate dynamic HTML pages with data from a database.  
(snip)
> After some thought I decided to leave the various frameworks
> aside for the
> time being and use mod_python.publisher 

I know this is not exactly an answer to your question, but have you
tried Django ?


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


HTML generation vs PSP vs Templating Engines

2005-11-16 Thread pkassianidis
Hello everybody,

I am in the process of writing my very first web application in Python,
and I need a way to
generate dynamic HTML pages with data from a database.  I have to say I
am overwhelmed
by the plethora of different frameworks, templating engines, HTML
generation tools etc that
exist. After some thought I decided to leave the various frameworks
aside for the
time being and use mod_python.publisher along with some means of
generating HTML on
the fly.
Could someone that has used all the different ways mentioned above for
dynamic HTML
content, suggest what the pros and cons of the different methods are?

  Thank you very much in advance

  Panos

-- 
http://mail.python.org/mailman/listinfo/python-list