Re: Javascript frameworks with Django

2011-04-27 Thread Jani Tiainen
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.


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 %}'   
   });
   }
   }]
  });


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:

/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  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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Javascript frameworks with Django

2011-04-27 Thread Shawn Milochik
In my experience you almost definitely do want to take advantage of 
templates. It makes things a lot easier.


Simple example:

A main template (including things like the  and  tags 
and doctype).


A detail template that just includes, say, a table of results.

In action:

The user takes action on the page.

JavaScript does an AJAX call, which hits your Django view.

The Django view returns a rendered template.

The JavaScript callback function replaces a portion of the DOM with 
that response.


Simple jQuery example of this:
$.ajax({
url: url_to_your_view,
type: "POST",
data: $("#search_form").serialize()
success: function(data){ $("#results_pane").html(data);},
});


Of course, you will probably have other bits and pieces of AJAX that 
deal with JSON and change other aspects of the page, but for the 
requirement of simulating a desktop application you will definitely have 
a much easier time with it if you use templates as much as possible 
instead of using JavaScript to dynamically write all your HTML.


Shawn


--
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Javascript frameworks with Django

2011-04-27 Thread christian.posta
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  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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Javascript frameworks with Django

2011-04-27 Thread Jani Tiainen
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.