Wednesday, April 27, 2011

Re: Javascript frameworks with Django

This is exactly like I've done it in the past and it's problematic. Specially
with lazy loading features. (Though I haven't upgraded my apps to use 1.3
style media serving that could ease whole thing)

One problem is that I need some dynamic parts for otherwise static JS code.
Let's take an example, a simple "login" form.

<script>
var form = new Ext.widget('form', {
items: [{
xtype: 'textfield',
fieldLabel: '{% trans "Username" %}',
name: 'username'
},{
xtype: 'textfield',
fieldLabel: '{% trans "Password" %}',
name: 'password'
}],
buttons: [{
text: '{% trans "Login" %}',
handler: function() {
this.up('form').getForm().submit({
url: '{% url login_view %}'
});
}
}]
});
</script>

As seen on above example, there is small parts (translations) and the most
important - url.

And I've tens of forms like above (of course way more complex forms). In
"biggest" application there is a bit over 50 different forms. And that's where
dynamic loading comes quite handy. System loads only what is needed on demand.

So I can't put everything in static files nor it wouldn't make point to put
everything in templates either.

So how to make it work without too much pain?

Oh, let me clear up one thing.

When I declare these files one of the key features is to use "require"
functionality. In pseudo-code it works like this:

Require('My.fancy.class');

That is translated roughly to:

<location of "My">/fancy/class.js

For example if I've declared location of "My" as /static/ system would
construct url: /static/fancy/class.js

Hope that this cleared up my "problem".

On Wednesday 27 April 2011 18:01:57 christian.posta wrote:
> I'm not sure I completely understand your question, but let me provide
> an answer and maybe that'll get us started on the right track.
>
> For the dynamic parts of the application, you could absolutely use
> django and view methods/classes to return json/xml or whatever data
> format you use. The data can then be rendered by your front-end JS
> code. You probably won't need the django templates unless you're
> formatting data a certain way.
>
> Your static code (you mean static media like javascript, css, and
> images, right?) should ultimately be served by a different server,
> specifically set up for static content (see the django docs... they
> mention this). To implement the static URL, use either the
> 'staticfiles' app for django 1.2.x or use the built in static files
> for django 1.3.
>
> HTH
>
> On Apr 27, 12:50 am, Jani Tiainen <rede...@gmail.com> wrote:
> > Hi,
> >
> > I've been for a while been using ExtJS and Dojotoolkit. Specially very
> > recently released ExtJS 4 brought lot of interesting features including
> > loading on demand (Dojotoolkit had it for a good while).
> >
> > Now I'm facing good practice problem:
> >
> > I want to construct apps that relies pretty much solely on "web 2.0"
> > technologies, namely to rewrite desktop apps in a web.
> >
> > There comes the "problem". To make things work smooth browser side
> > javascript code needs to talk to Django views and to make that happen I
> > need to get URLs working (and later on translations).
> >
> > How to make all that work together well? I mean where to put dynamic
> > parts, where to put static parts and at some day - translations.
> >
> > Should I mix and match templates and plain static javascripts? One
> > problem that I've been facing (though 1.3 probably fixed it) was
> > resources from different apps, specially static js parts.
> >
> > --
> >
> > Jani Tiainen

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

No comments:

Post a Comment