how to use twisted.web.template with twisted.web.resource

539 views
Skip to first unread message

CL Chow

unread,
Apr 19, 2011, 11:13:15 AM4/19/11
to pyth...@googlegroups.com
twisted 11.0 introduced twisted.web.template (at last, twisted has it's own templating engine!)
actually the template codes are ported from divmod's nevow, only the part of templating engine.

here is the crude way to use it

from twisted.web.server import Site, NOT_DONE_YET
from twisted.web.resource import Resource
from twisted.internet import reactor

from twisted.web.template import Element, flattenString, XMLString, renderer

class Hello(Element):
    loader = XMLString('''                                                                                                              
<html xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">                                         
<body>                                                                                                                                      
  <div t:render="content" />                                                                                                        
</body>                                                                                                                 
</html>                                                                                                                                     
''')

    @renderer
    def content(self, request, tag):
        return tag('Hello, world!')

class Root(Resource):
    isLeaf = True
    def render_GET(self, request):
        request.write("<!DOCTYPE html>\n")
        flattenString(request, Hello()).addCallback(request.write)
        request.finish()
        return NOT_DONE_YET

site = Site(Root())
reactor.listenTCP(8080, site)
reactor.run()

as mentioned, it is crude
for more information, please read the documentation

Regards,
CL Chow
"Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/"


ycloh

unread,
Apr 19, 2011, 9:32:24 PM4/19/11
to python.my
Have not spent any time with twisted but am generally interested to
find out more about presentation layer frameworks. Generally there
seem to be 2 ways of generating the view i.e. using templates and
through code e.g. pyjamas (or vaadin in the java world).

I *had* the impression that using code would be easier as i only have
to deal with the programming language (python, java) and do not have
to worry about css, javascript (more things to learn). But more
recently, i think we cannot run away from knowing javascript and css
and thus feel that using templates with javascript and css is the way
to go. Can i get opinions/experiences on which is a better approach?
> for more information, please read the documentationhttp://twistedmatrix.com/documents/current/web/howto/twisted-template...http://twistedmatrix.com/documents/current/api/twisted.web.template.html

E A Faisal

unread,
Apr 20, 2011, 12:48:54 AM4/20/11
to pyth...@googlegroups.com
off topic: http://groups.google.com/group/comp.lang.python/msg/8d79c5ee3913f82d?pli=1

--
You received this message because you are subscribed to the Google Groups "python.my" group.
To post to this group, send email to pyth...@googlegroups.com.
To unsubscribe from this group, send email to pythonmy+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pythonmy?hl=en.


CL Chow

unread,
Apr 20, 2011, 12:50:39 AM4/20/11
to pyth...@googlegroups.com
My Story,
I too when I was new to web programming, this idea of doing everything in code is easier.
But overtime, I noticed myself to be restricted to the widget engine, I have to spend more time hacking it to get the things I want to work.
And because I'm using some unpopular web widget, I have to hope things to be fixed in updates, or I fix them myself, which costs me more time.
I was using some widget engine offered by Symfony (PHP), years later the developer team dropped it.

My Opinion,
If you are making an "enterprise" application which doesn't or will not include a designer,
you need it fast, you know your crowd, you know your widget engine,
go ahead. It's faster and easier than you to learn html, css, and js.

My Experience, My Tools,
It is not that horrible to do layout with html, css and js.
I always think that it's better for you to understand how dom works first.
If you are really interested, these are some frameworks to help you get started.
For css layout, I use 960.gs for most of my projects.
It is a css framework based on grid layout system.
It is always recommended to understand css before you start using a css framework, although you can use it right away :)
For js, I choose jquery, understanding css selector is all you need to manipulate dom.
And you don't have to worry much on cross browsers support.
You can start ajax right away with jquery too :)
jquery has it's own css + animation + interaction libraries too, called jqueryui.
Also, browsers extensions such as firebug and webdeveloper toolbar will get your debugging life easier.

Your Choice,
It's still up to you :)
If you are willing to get started with html, css, js or getting started web programming with python,
I am willing to share :)
I believe a lot in the list are python web programming gurus.

Thank you.

Regards,
CL Chow
"Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/"




On Wed, Apr 20, 2011 at 9:32 AM, ycloh <yitc...@gmail.com> wrote:

sweemeng ng

unread,
Apr 20, 2011, 1:02:16 AM4/20/11
to pyth...@googlegroups.com
i still think we should use right tools for the right stuff, so I use js+html+css for the layout.
You have the flexibility to choose the best widgets and the library you want to use. A bit more flexible too I find

but then i didn't try pyjamas yet.

ycloh

unread,
Apr 20, 2011, 1:22:17 AM4/20/11
to python.my
It is about what we are comfortable with and i do think that if we are
to do web development, we will need to get comfortable with javascript
and css. This is probably driven somewhat by the need to make web
pages more interactive through the use of ajax. It does seem like
doing ajax using django is still quite a bit of work since ajax is not
baked in. Even if we adopt jquery as the javascript library, there is
a need to write specific callbacks for each of the ajax calls. I
wonder if there is anything in the python world that comes close to
JSF 2 in the java world. At work, we use primefaces and it has ajax
baked in, which makes life simpler in a sense, but of course you lose
some control. In the python web frameworks, the closest i have seen is
the ajax support in the web2py project. Please correct me if i am
wrong here.

So, i wonder if anyone has used JSF with jython for the controller/
domain layers (typical java layering architecture)?



On Apr 20, 12:50 pm, CL Chow <klrkdek...@gmail.com> wrote:
> My Story,
> I too when I was new to web programming, this idea of doing everything in
> code is easier.
> But overtime, I noticed myself to be restricted to the widget engine, I have
> to spend more time hacking it to get the things I want to work.
> And because I'm using some unpopular web widget, I have to hope things to be
> fixed in updates, or I fix them myself, which costs me more time.
> I was using some widget engine offered by Symfony (PHP), years later the
> developer team dropped it.
>
> My Opinion,
> If you are making an "enterprise" application which doesn't or will not
> include a designer,
> you need it fast, you know your crowd, you know your widget engine,
> go ahead. It's faster and easier than you to learn html, css, and js.
>
> My Experience, My Tools,
> It is not that horrible to do layout with html, css and js.
> I always think that it's better for you to understand how
> dom<http://en.wikipedia.org/wiki/Document_Object_Model> works
> first.
> If you are really interested, these are some frameworks to help you get
> started.
> For css layout, I use 960.gs for most of my projects.
> It is a css framework based on
> grid<http://en.wikipedia.org/wiki/Grid_(page_layout)>layout system.
> It is always recommended to understand css before you start using a css
> framework, although you can use it right away :)
> For js, I choose jquery <http://jquery.com/>, understanding css selector is
> all you need to manipulate dom.
> And you don't have to worry much on cross browsers support.
> You can start ajax right away with jquery too :)
> jquery has it's own css + animation + interaction libraries too, called
> jqueryui <http://jqueryui.com/>.
> Also, browsers extensions such as firebug <http://getfirebug.com/> and
> webdeveloper
> toolbar <http://chrispederick.com/work/web-developer/> will get your
> debugging life easier.
>
> Your Choice,
> It's still up to you :)
> If you are willing to get started with html, css, js or getting started web
> programming with python,
> I am willing to share :)
> I believe a lot in the list are python web programming gurus.
>
> Thank you.
>
> Regards,
> CL Chow
> "Please do not send me Microsoft Office/Apple iWork documents. Send
> OpenDocument instead!http://fsf.org/campaigns/opendocument/"

sweemeng ng

unread,
Apr 20, 2011, 1:38:51 AM4/20/11
to pyth...@googlegroups.com
I do not believe that there is a web framework on python to have ajax build in. but all do have ability to output json, which only half of the solution. django you can easily output result in json in views, or encode queryset result to json.

Mohd Izhar Firdaus Ismail

unread,
Apr 20, 2011, 1:53:50 AM4/20/11
to pyth...@googlegroups.com
On Wed, Apr 20, 2011 at 1:38 PM, sweemeng ng <swee...@gmail.com> wrote:
> I do not believe that there is a web framework on python to have ajax build
> in. but all do have ability to output json, which only half of the solution.
> django you can easily output result in json in views, or encode queryset
> result to json.
>

ajax built in ? .. do you mean generate javascript code? ..

imo, ajax is a problem on the browser side programming rather than on
the server side, and thats the realm of the javascript curly braces,
not the realm for python, or any other language for that sake, as
browser primarily only accept javascript (theres vbscript and all, but
they sucks) ..

@ycloh

what you are looking for are javascript libraries that simplify the
interaction between the client and server, but a python framework that
help doing ajax, because python cant do ajax, as its on the server
side.

if you are looking for a python framework that simplify long polling
http request (which is useful if you want to do real-time chat or
something), theres tornado.

--
Mohd Izhar Firdaus Bin Ismail / KageSenshi
Inigo Consulting (FOSS/Plone Development, Training & Services)
http://www.inigo-tech.com
Fedora Malaysia Contributor & Ambassador
http://blog.kagesenshi.org
92C2 B295 B40B B3DC 6866  5011 5BD2 584A 8A5D 7331

Mohd Izhar Firdaus Ismail

unread,
Apr 20, 2011, 1:54:48 AM4/20/11
to pyth...@googlegroups.com
On Wed, Apr 20, 2011 at 1:53 PM, Mohd Izhar Firdaus Ismail
<kagese...@gmail.com> wrote:
> what you are looking for are javascript libraries that simplify the
> interaction between the client and server, but a python framework that

* but NOT a python framework that help doing ajax

> help doing ajax, because python cant do ajax, as its on the server
> side.

ycloh

unread,
Apr 20, 2011, 3:24:24 AM4/20/11
to python.my
I guess i am thinking more in terms of how jsf works (since we use it
at work). Using primefaces as an example, in the template we can say
something like

<h:outputText id="otherField"
value="userBean.someField" />
...
...
<p:commandButton value="Yes" update="other_field"
actionListener="#{myBean.doSomething}" />

What this will do is that it will call the doSomething method the
myBean instance and then update the other_field. No custom javascript
is required to handle this.

When the user clicks on the button, the JSF framework basically moves
the value from the form the the bean and then calls
myBean.doSomething() which presumably will update the
userBean.someField. The framework then populates the form element with
the new value of the userBean.someField back to the form into
otherField DOM element.

In a way the framework helps with moving values between the form and
the bean (model?) and also calls the appropriate method and also calls
validation (and conversion) as well. Underneath it all is the ajax
calls, and the javascript stuff which the developer does not see. I
know we can write all this stuff ourselves but it does provide a bunch
of useful helpers and does speed up development somewhat.

Is there something similar in the python frameworks/libraries?

I am not concerned if it is the framework or library as long as it
helps to quickly build screens :)







On Apr 20, 1:53 pm, Mohd Izhar Firdaus Ismail
<kagesenshi...@gmail.com> wrote:
> On Wed, Apr 20, 2011 at 1:38 PM, sweemeng ng <swees...@gmail.com> wrote:
> > I do not believe that there is a web framework on python to have ajax build
> > in. but all do have ability to output json, which only half of the solution.
> > django you can easily output result in json in views, or encode queryset
> > result to json.
>
> ajax built in ? .. do you mean generate javascript code? ..
>
> imo, ajax is a problem on the browser side programming rather than on
> the server side, and thats the realm of the javascript curly braces,
> not the realm for python, or any other language for that sake, as
> browser primarily only accept javascript (theres vbscript and all, but
> they sucks) ..
>
> @ycloh
>
> what you are looking for are javascript libraries that simplify the
> interaction between the client and server, but a python framework that
> help doing ajax, because python cant do ajax, as its on the server
> side.
>
> if you are looking for a python framework that simplify long polling
> http request (which is useful if you want to do real-time chat or
> something), theres tornado.
>
> --
> Mohd Izhar Firdaus Bin Ismail / KageSenshi
> Inigo Consulting (FOSS/Plone Development, Training & Services)http://www.inigo-tech.com
> Fedora Malaysia Contributor & Ambassadorhttp://blog.kagesenshi.org

sweemeng ng

unread,
Apr 20, 2011, 4:45:43 AM4/20/11
to pyth...@googlegroups.com
correction it is not handled by most framework that I know of in python.

On Wed, Apr 20, 2011 at 4:44 PM, sweemeng ng <swee...@gmail.com> wrote:
In python now, no such thing exist, I use django, it doesn't exist on it, same for other frameworks(didn't exist when I last check, that I could really be wrong), not sure about zope(because I didn't use it before).

you practically have to implement it differently. How I would do it, using jquery. attach a event on a button field in templates, which read the value in the text field, and do ajax call to the views(or what ever else you call it), to receive json output from the server. from the jquery ajax function, populate the otherfield, by playing around with dome.

and you need a django views to output json(you can just encode result of an operation, and send it to httpresponse.

for other web framework, it is roughly the same. you just need to call the url to call the component that output json via http.

yes, it is not handled automatically by most web framework.

sweemeng ng

unread,
Apr 20, 2011, 4:44:32 AM4/20/11
to pyth...@googlegroups.com
In python now, no such thing exist, I use django, it doesn't exist on it, same for other frameworks(didn't exist when I last check, that I could really be wrong), not sure about zope(because I didn't use it before).

you practically have to implement it differently. How I would do it, using jquery. attach a event on a button field in templates, which read the value in the text field, and do ajax call to the views(or what ever else you call it), to receive json output from the server. from the jquery ajax function, populate the otherfield, by playing around with dome.

and you need a django views to output json(you can just encode result of an operation, and send it to httpresponse.

for other web framework, it is roughly the same. you just need to call the url to call the component that output json via http.

yes, it is not handled automatically by most web framework.

On Wed, Apr 20, 2011 at 3:24 PM, ycloh <yitc...@gmail.com> wrote:

Mohd Izhar Firdaus Ismail

unread,
Apr 20, 2011, 5:29:32 AM4/20/11
to pyth...@googlegroups.com
On Wed, Apr 20, 2011 at 3:24 PM, ycloh <yitc...@gmail.com> wrote:
> I guess i am thinking more in terms of how jsf works (since we use it
> at work). Using primefaces as an example, in the template we can say
> something like
>
>                <h:outputText id="otherField"
> value="userBean.someField" />
>                ...
>                ...
>                <p:commandButton value="Yes" update="other_field"
> actionListener="#{myBean.doSomething}"  />

is that even html ?

>
> What this will do is that it will call the doSomething method the
> myBean instance and then update the other_field. No custom javascript
> is required to handle this.

I dont know about primefaces, but it sound like the framework generate
the javascript to handle it for u, or already using some sort of
javascript library that read the information in the html element and
submit it accordingly to the server.

using jquery, submitting a form through ajax is rather easy imo .. and
nothing fancy on the server side, just yet another view which accept
data and returns json ..

theres also jquery datalink [1] library which bind a javascript
object, to a form field, any changes in the field will be delegated to
the object .. and that object, you can submit it to the server or do
something with it .. again, nothing fancy on the server side.

most python framework only handles the backend side of stuff. The
frontend is usually up to the dev. Some might include widget
libraries, but thats just it ..

In zope, theres one thing that might be close, and that is called KSS
[2] .. but I hate it because lots of flexibility was lost .. the docs
in site might be a bit plone-centric and not clear, the doc in the
grok website [3] describe KSS clearer

[1] http://api.jquery.com/link/
[2] http://kssproject.org/
[3] http://grok.zope.org/documentation/how-to/adding-ajax-with-kss-to-grok

CL Chow

unread,
Apr 20, 2011, 5:40:22 AM4/20/11
to pyth...@googlegroups.com
Perhaps, i should ask the question another way; what
libraries are available to help with doing ajax with the more popular
python web frameworks (e.g. django, web2py, pyramid...)?

$.ajax({
 url: 'ajax/test.html',
 success: function(data) {
   $('.result').html(data);
   alert('Load was performed.');
 }
});

http://api.jquery.com/jQuery.ajax/
jquery? it is server agnostic. and it's easier to do/learn the old js way?

Regards,
CL Chow
"Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/"




On Wed, Apr 20, 2011 at 5:34 PM, ycloh <yitc...@gmail.com> wrote:
>
> There are errors in the code snippet. Was in a hurry when i wrote it.
> It should be

>
>                 <h:outputText id="otherField"
> value="userBean.someField" />
>                  ...
>                  ...
>                  <p:commandButton value="Yes" update="otherField"
> actionListener="#{myBean.doSomething}"  />
>
> Had a bit of a think about what KageSenshi  was saying. I believe that
> JSF is more than just a bunch of js libraries. I would consider it as
> more of a framework that uses some js scripts rather than just a js
> library. In the case of primefaces, the js library that is being used
> is jQuery & YUI i think and also Jquery UI for some of the theming
> support.
>
> The framework spews out the js snippets based on the tag attributes
> (e.g. <p:commandButton action="bean.doSomething" ajax="true" ..../> in
> the template. I guess a bit like in Django if you created a
> AutoCompleteField that when it is rendered, it will also render the js
> snippet based on the options specified when you declare the field.
>
> As far as i can tell, there isn't something similar in the python web
> frameworks. Perhaps, i should ask the question another way; what
> libraries are available to help with doing ajax with the more popular
> python web frameworks (e.g. django, web2py, pyramid...)?

sweemeng ng

unread,
Apr 20, 2011, 5:41:19 AM4/20/11
to pyth...@googlegroups.com
That is not a valid html too.JSF is a bit different, and primeface wrap a lot more stuff than you see.

current web development practice on python(even on rails I believe). Do the templates on js + html + js. let the backend be backend.

I don't think there is libraries for UI on python too. pyjamas comes close, but didn' t heard of a big usage though.

On Wed, Apr 20, 2011 at 5:34 PM, ycloh <yitc...@gmail.com> wrote:
There are errors in the code snippet. Was in a hurry when i wrote it.
It should be
                <h:outputText id="otherField"
value="userBean.someField" />
                 ...
                 ...
                 <p:commandButton value="Yes" update="otherField"
actionListener="#{myBean.doSomething}"  />

Had a bit of a think about what KageSenshi  was saying. I believe that
JSF is more than just a bunch of js libraries. I would consider it as
more of a framework that uses some js scripts rather than just a js
library. In the case of primefaces, the js library that is being used
is jQuery & YUI i think and also Jquery UI for some of the theming
support.

The framework spews out the js snippets based on the tag attributes
(e.g. <p:commandButton action="bean.doSomething" ajax="true" ..../> in
the template. I guess a bit like in Django if you created a
AutoCompleteField that when it is rendered, it will also render the js
snippet based on the options specified when you declare the field.

As far as i can tell, there isn't something similar in the python web
frameworks. Perhaps, i should ask the question another way; what
libraries are available to help with doing ajax with the more popular
python web frameworks (e.g. django, web2py, pyramid...)?


On Apr 20, 3:24 pm, ycloh <yitcho...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "python.my" group.
To post to this group, send email to pyth...@googlegroups.com.
To unsubscribe from this group, send email to pythonmy+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pythonmy?hl=en.




--
Just a random living organic computer code generator

Mohd Izhar Firdaus Ismail

unread,
Apr 20, 2011, 5:44:48 AM4/20/11
to pyth...@googlegroups.com
On Wed, Apr 20, 2011 at 5:34 PM, ycloh <yitc...@gmail.com> wrote:
> There are errors in the code snippet. Was in a hurry when i wrote it.
> It should be
>
>                 <h:outputText id="otherField"
> value="userBean.someField" />
>                  ...
>                  ...
>                  <p:commandButton value="Yes" update="otherField"
> actionListener="#{myBean.doSomething}"  />
>
> Had a bit of a think about what KageSenshi  was saying. I believe that
> JSF is more than just a bunch of js libraries. I would consider it as
> more of a framework that uses some js scripts rather than just a js
> library. In the case of primefaces, the js library that is being used
> is jQuery & YUI i think and also Jquery UI for some of the theming
> support.
>
> The framework spews out the js snippets based on the tag attributes
> (e.g. <p:commandButton action="bean.doSomething" ajax="true" ..../> in
> the template. I guess a bit like in Django if you created a
> AutoCompleteField that when it is rendered, it will also render the js
> snippet based on the options specified when you declare the field.

then the framework is also a javascript generator .. :-) .. unlike the
java world, stuff in python world tend to be less monolithic ..
(except for that darned zope2, huge monolithic giant mess, zope3 is
better) .. python frameworks are usually a set of separate libraries,
which work together .. and i'm sure they also have javascript
libraries included in the pages to help do all the magic ..

>
> As far as i can tell, there isn't something similar in the python web
> frameworks. Perhaps, i should ask the question another way; what
> libraries are available to help with doing ajax with the more popular
> python web frameworks (e.g. django, web2py, pyramid...)?

jQuery .. works with any server side language that can speak http ..

and yep, like sweemeng said, let the backend be just the backend ..
and frontend be just the frontend .. the backend and frontend talks
using some sort of protocol, and in this case, bunch of json object ..

CL Chow

unread,
Apr 20, 2011, 5:51:01 AM4/20/11
to pyth...@googlegroups.com
I don't know if jsf is so, I've been doing abit of lift (scala) before.
Apparently lift's way of doing things starts with view. (View calls the server backend functions, and updates on frontend)
The html are very like the one ycloh shows.
I know that java can do persistent connection quite natively, correct me if i'm wrong.
Hence it is simpler or nicer or easier to implement js compilers along with the templating engine?

Regards,
CL Chow
"Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/"




ycloh

unread,
Apr 20, 2011, 5:34:54 AM4/20/11
to python.my
There are errors in the code snippet. Was in a hurry when i wrote it.
It should be

                <h:outputText id="otherField"
value="userBean.someField" />
                ...
                ...
                <p:commandButton value="Yes" update="otherField"
actionListener="#{myBean.doSomething}"  />

Had a bit of a think about what KageSenshi was saying. I believe that
JSF is more than just a bunch of js libraries. I would consider it as
more of a framework that uses some js scripts rather than just a js
library. In the case of primefaces, the js library that is being used
is jQuery & YUI i think and also Jquery UI for some of the theming
support.

The framework spews out the js snippets based on the tag attributes
(e.g. <p:commandButton action="bean.doSomething" ajax="true" ..../> in
the template. I guess a bit like in Django if you created a
AutoCompleteField that when it is rendered, it will also render the js
snippet based on the options specified when you declare the field.

As far as i can tell, there isn't something similar in the python web
frameworks. Perhaps, i should ask the question another way; what
libraries are available to help with doing ajax with the more popular
python web frameworks (e.g. django, web2py, pyramid...)?


On Apr 20, 3:24 pm, ycloh <yitcho...@gmail.com> wrote:

ycloh

unread,
Apr 20, 2011, 9:36:30 PM4/20/11
to python.my
With JSF the focal point is the view (we can think of this as the
template). What i showed in the template snippet is a tag which is
part of the primefaces project. The idea around JSF is to make state
management simpler (and thus less transparent?), and blur the line
between what is happening on the browser and what is happening on the
server side. For most developers (mortals like me), making it simpler
means i can be more productive. With an understanding of the
internals, we can also extend where required.

I agree with Chow that writing the ajax calls using js is not hard,
but if there are many ajax calls in a page it looks more like
boilerplate code where we replace the url, but we still need to write
the callback handler. So if the framework can handle 80% of the cases
using a declarative style, i consider that to be helpful.

In a way, i am willing to give up the pure approach of let the front
be the front and let the backend be the backend. I started with the
one that said that i originally thought i could get away with not
knowing js + css and went the pyjamas (or vaadin) way where we just
write everything in python (java). In such an approach, the lines
between what is happening on the browser and the backend is completely
blurred. I have moved somewhat in that thinking that perhaps it is too
much of an abstraction and thus feel that knowing js + css is
necessarily. Just perhaps i have not moved to the point that we
clearly separate the front and the back.

More thoughts? Btw, i am enjoying this discussion and thanks for all
the great input.


On Apr 20, 5:51 pm, CL Chow <klrkdek...@gmail.com> wrote:
> I don't know if jsf is so, I've been doing abit of lift (scala) before.
> Apparently lift's way of doing things starts with view. (View calls the
> server backend functions, and updates on frontend)
> The html are very like the one ycloh shows.
> I know that java can do persistent connection quite natively, correct me if
> i'm wrong.
> Hence it is simpler or nicer or easier to implement js compilers along with
> the templating engine?
>
> Regards,
> CL Chow
> "Please do not send me Microsoft Office/Apple iWork documents. Send
> OpenDocument instead!http://fsf.org/campaigns/opendocument/"
>
> On Wed, Apr 20, 2011 at 5:44 PM, Mohd Izhar Firdaus Ismail <
>
>
>
>
>
>
>
> kagesenshi...@gmail.com> wrote:

Boh Yap

unread,
Apr 21, 2011, 7:47:56 AM4/21/11
to pyth...@googlegroups.com
hi,

IMHO, separating the back and front end is referred to as the MVC
Design Pattern, (Model, View, Controller) and dates back to the early
days of OOP, in the days of SmallTalk I believe.

The concept here is we have

'Models' - which models the real world objects we want to emulate, ie:
our eComm back end, Inventory, Order Processing and CRM system etc...
It has the classes like Customer, Order, InvemtoryItem, with its
attributes and methods and any other business logic.

'Views' - present the information obtained form the Models to the
User. So in the case of a Web app, the View 'generates' HTML page for
the presentation. It will also handle User Interaction(UI), hence
maybe the need for JS.

Controllers - mediate between the Model and the Views, it does things
like authentication, session management (in Web), passing data between
the View and the Model.

The concept of the pattern makes the entire app modular. And lends to
reusability of code. For example, I can replace the 'View' with a
text-based curses UI, Just need to change the View and Controller. The
Model remains the same.

Or similarly if I had a Web app for eComm, ...and I develop a web CRM
App, I can make use of the eComm app's Model, and I can talk to it
using HTTP protocols, use its business-logic via RPC etc.

As a counter example, years back I worked on a Web App that intermixed
logic into the presentation, ie: code embedded into the HTML ala
ASP/PHP... The App had about 300+ pages of HTML + code. When there was
a requirement to add a language, add BM to the existing English, all
those 300+ pages had to be reworked!

If the MVC pattern and a good templating system was used, the work
would have been much easier! In the end, the cost was too great and
time to do it too long after the estimates were done, so the changes
was abandoned.

So in my mind, its always better to separate the front end from the
back-end, despite the initial pain. Plus as you mention earlier, you
have a real understanding about what is going on, and can therefore
tweak things if necessary.

--
#-------
regds,

Boh Heong, Yap

Marcus

unread,
Apr 21, 2011, 6:14:44 PM4/21/11
to pyth...@googlegroups.com
Separating backend from front. Separating Engine from UI.
These decisions can't go wrong...

As for using JS, even with all the hidden powers of VS and C# on web
development, sometimes you just
need to know the basic JS to improve on it further.

The mailnow UI is done by the team entirely with nearly "zero" knowledge
on javascript and
all via VS,C# and Telerik libs, you can try out the web UI here, "heavy"
desktop like feel (drag-drop, right click,
ajax response).
Engine is done from ground up using Python, C#, C. (i love to put it in
that order ;-))

http://hq.internetnow.com.my:8383
login : test
pass : user123

(Err kindly don't use it to send spam or any dangerous mails!, just for
this community viewing)

But ultimately we had to fine-tune its performance by shrinking the JS
libraries and some custom codes and
that means learning up basic JS in detail. But it is totally possible to
code front Web UI end entirely separated from
the backend and with no knowledge of JS. You just need VS.

(note : i am going to quote this mail to ask MS for sponsorship for
pycon 2012! yeah baby! LOL)

>>>>> is jQuery& YUI i think and also Jquery UI for some of the theming


>>>>> support.
>>>>> The framework spews out the js snippets based on the tag attributes
>>>>> (e.g.<p:commandButton action="bean.doSomething" ajax="true" ..../> in
>>>>> the template. I guess a bit like in Django if you created a
>>>>> AutoCompleteField that when it is rendered, it will also render the js
>>>>> snippet based on the options specified when you declare the field.
>>>> then the framework is also a javascript generator .. :-) .. unlike the
>>>> java world, stuff in python world tend to be less monolithic ..
>>>> (except for that darned zope2, huge monolithic giant mess, zope3 is
>>>> better) .. python frameworks are usually a set of separate libraries,
>>>> which work together .. and i'm sure they also have javascript
>>>> libraries included in the pages to help do all the magic ..
>>>>> As far as i can tell, there isn't something similar in the python web
>>>>> frameworks. Perhaps, i should ask the question another way; what
>>>>> libraries are available to help with doing ajax with the more popular
>>>>> python web frameworks (e.g. django, web2py, pyramid...)?
>>>> jQuery .. works with any server side language that can speak http ..
>>>> and yep, like sweemeng said, let the backend be just the backend ..
>>>> and frontend be just the frontend .. the backend and frontend talks
>>>> using some sort of protocol, and in this case, bunch of json object ..
>>>> --
>>>> Mohd Izhar Firdaus Bin Ismail / KageSenshi

>>>> Inigo Consulting (FOSS/Plone Development, Training& Services)
>>>> http://www.inigo-tech.com
>>>> Fedora Malaysia Contributor& Ambassador

sweemeng ng

unread,
Apr 21, 2011, 9:20:39 PM4/21/11
to pyth...@googlegroups.com
Actually not just VS, various java framework have the feature of hiding javascript by the framework. it is not just a VS thingy. just saying.

But hey, you pay for it right, you get what you have paid right. That is more often the case of frameworks/tools/languages that is used a lot in the "enterprise" environment such as .net/java or derived from such environment such as scala. Hiding js behind the scene.

Not so much for other environment, such as python and ruby. rails do it a bit better, they have some support. but the culture among the dev there tend to be toward dev need to know js and html.

ycloh

unread,
Apr 21, 2011, 10:49:58 PM4/21/11
to python.my
More thoughts on this. I agree with what Boh is saying about MVC. In
the discussion thus far, i think we have not said much about the Model
layer. This is definitely something in the backend (although Microsoft
has the MVVM pattern). JSF is really about the View and the
Controller. I see the controller and the view as pretty much tied
together, i.e. if you change the view, the controller will probably
need to changed i.e. these 2 layers are pretty tightly coupled. In a
layered architecture, i would consider the view and controller to be
part of the presentation layer. The model as part of the domain layer
and finally there would be the data access layer.

I see the discussion as to the interaction between the view and the
controller. Because the view runs in the browser and the controller
runs in the server, there is a need to exchange data. In JSF the data
exchange (via ajax) with serialization and deserialization is handled
by the framework. With the ajax calls it not not just about the
exchange of data, but also what needs to be done when you get the data
back i.e. the callback. Eg. if i enter my dob the next field should
show my age. If there are many ajax calls, it starts looking like
there is a bit of boilerplate code, and JSF tries to abstract that
somewhat and provides a declarative means to handle most cases (80%).
Of course you can (and will need to) drop back into custom javascript
for the not so common use case.

What i was thinking is that we use JSF for the view and controller
(presentation layer) but to use python for the domain layer and data
access layer (sqlalchemy). That would mean dealing with Jython. Of
course i was hoping that there would be a nice view and controller
layer framework that i could use to replace JSF. That way, it frees
the limitation of using Jython only.

Btw, marcus did you get any piece of the action with the 1 Malaysia
email project?

CL Chow

unread,
Apr 21, 2011, 11:26:04 PM4/21/11
to pyth...@googlegroups.com
Not so much for other environment, such as python and ruby. rails do it a bit better, they have some support. but the culture among the dev there tend to be toward dev need to know js and html. 

Agree.

Off topic, if we want, and there's none, make one?
How about a sprint?

Regards,
CL Chow
"Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/"




sweemeng ng

unread,
Apr 21, 2011, 11:32:23 PM4/21/11
to pyth...@googlegroups.com
I'm in, i say weekend, next week(ok i got over excited here)

CL Chow

unread,
Apr 21, 2011, 11:49:24 PM4/21/11
to pyth...@googlegroups.com
I think regular sprint will be good for our python community too.
You don't need a lot of people, just get one date, one place and one theme.

Swee Meng, tomorrow is the CodeAndroid meetup? You going?
If you, I'll meet you there.

Regards,
CL Chow
"Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/"




sweemeng ng

unread,
Apr 21, 2011, 11:50:36 PM4/21/11
to pyth...@googlegroups.com
Of course, cool, tomorrow will be a crowded day
Reply all
Reply to author
Forward
0 new messages