Re: Basic AJAX (was: Re: multi applications)
Hi, thank you for the explanation. I'll look into it. I found also an ajax lib for Django, it is DAJAX. Steve On Tue, Jul 14, 2009 at 10:09 PM, Shawn Milochik wrote: > > > On Jul 14, 2009, at 3:43 PM, sjtirtha wrote: > > > Thank you for the explanation. > > This helps me very much. > > > > You mentions about handling the smaller apps on the page with AJAX. > > Is there any basic functionality to do this from Django Framework? > > Or do you have any ajax lib/framework as preference? > > > > Steve > > > Use jQuery -- it'll automate most of it. > > Here are two simple samples. Both are in the $(document).ready() > function. Once you use jQuery for about three minutes, you'll know > what that is. > >This does a GET request to get a user's current balance. >It then writes the balance (returned as JSON by the view) >into the HTML div with the id current_balance. > >$.get("/balance_json/{{ch.slug}}", {}, function (data){ >$('#current_balance').html("$" + data.balance); >}, 'json'); > > >This does a POST to submit a form to send an SMS message. The view > also returns >JSON in this case, (created from a Python dictionary), which will > have a key of 'success' >with a value of the success message, or a key of 'failure' with an > error message in it. > > $("#sms_form").submit(function(event){ > event.preventDefault(); // stop the form from submitting and > refreshing the page > var data = $("#sms_form").serialize() > > // now send the data to the server via AJAX > $.post("/patient/{{ch.slug}}/sms/", data, function(resp){ > if(resp.success) { > $("#messages").html(" class='success'>" + resp.success + ""); > $("#success-message").animate({ backgroundColor: > "#E6EFC2" }, 2000); > update_activity(); > } else if (resp.fail) { > $("#messages").html(" class='fail'>" + resp.fail + ""); > $("#fail-message").animate({ backgroundColor: > "#fbe3e4" }, 2000); > } > }, "json"); > }); > > I don't know if there are are super-special Django tools to do AJAX, > but as it's JavaScript and Django's Python, I doubt it. > > The most useful things in Django are simplejson and safestring (both > in django.utils). You'll need simplejson to easily dump a dictionary > into a JSON string to pass back to JavaScript, and you'll need > safestring to "mark_safe" JSON strings you're going to pass via the > context to be rendered within the templates. Otherwise they'll be > escaped automatically for your protection. > > 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 -~--~~~~--~~--~--~---
Basic AJAX (was: Re: multi applications)
On Jul 14, 2009, at 3:43 PM, sjtirtha wrote: > Thank you for the explanation. > This helps me very much. > > You mentions about handling the smaller apps on the page with AJAX. > Is there any basic functionality to do this from Django Framework? > Or do you have any ajax lib/framework as preference? > > Steve Use jQuery -- it'll automate most of it. Here are two simple samples. Both are in the $(document).ready() function. Once you use jQuery for about three minutes, you'll know what that is. This does a GET request to get a user's current balance. It then writes the balance (returned as JSON by the view) into the HTML div with the id current_balance. $.get("/balance_json/{{ch.slug}}", {}, function (data){ $('#current_balance').html("$" + data.balance); }, 'json'); This does a POST to submit a form to send an SMS message. The view also returns JSON in this case, (created from a Python dictionary), which will have a key of 'success' with a value of the success message, or a key of 'failure' with an error message in it. $("#sms_form").submit(function(event){ event.preventDefault(); // stop the form from submitting and refreshing the page var data = $("#sms_form").serialize() // now send the data to the server via AJAX $.post("/patient/{{ch.slug}}/sms/", data, function(resp){ if(resp.success) { $("#messages").html("" + resp.success + ""); $("#success-message").animate({ backgroundColor: "#E6EFC2" }, 2000); update_activity(); } else if (resp.fail) { $("#messages").html("" + resp.fail + ""); $("#fail-message").animate({ backgroundColor: "#fbe3e4" }, 2000); } }, "json"); }); I don't know if there are are super-special Django tools to do AJAX, but as it's JavaScript and Django's Python, I doubt it. The most useful things in Django are simplejson and safestring (both in django.utils). You'll need simplejson to easily dump a dictionary into a JSON string to pass back to JavaScript, and you'll need safestring to "mark_safe" JSON strings you're going to pass via the context to be rendered within the templates. Otherwise they'll be escaped automatically for your protection. 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: multi applications
Thank you for the explanation. This helps me very much. You mentions about handling the smaller apps on the page with AJAX. Is there any basic functionality to do this from Django Framework? Or do you have any ajax lib/framework as preference? Steve On Tue, Jul 14, 2009 at 9:10 PM, Shawn Milochik wrote: > > > On Jul 14, 2009, at 2:57 PM, sjtirtha wrote: > > > Hi, > > > > I'm looking for documentation, which describes how to build a web > > application which includes many other applications. > > For example like Facebook, it has following applications on the > > first screen: > > 1. On the left side is dynamic menu > > 2. In the middle is the microblogging > > 3. On the right side on the top is Request block > > 4. On the right side in the middle is Highlights > > > > How can I build a web application like this? I was thinking to have > > a main application which has a template that includes all other > > applications. > > But how can I set the context specific for every templates of the > > included applications? > > > > regards, > > > > Steve > > > There are several different aspects to what you are asking for and > describing. The first part is showing all the apps within one page, > and that's just a matter of a well-formatted CSS/HTML template. This > template may (should?) include smaller templates (for each section). > > Ultimately your page will be called by a single URL, so you'll receive > the entire request in one place. From there, you will have to decide > how to handle the contexts. Look into the RequestContext class. The > things you need to display on all pages, regardless of what the "main" > view is at the moment, can be moved over there to avoid clutter. > > The "main" content could be handled in the view called directly by > urls.py, and the rest can be inherited from the context dictionary > keys coming from your request contexts. > > Also, you'll probably want/need to handle all the smaller apps on the > page with AJAX, because you won't want to refresh the entire page for > updating the microblog, etc. And since you're referring to FaceBook, > they even do most of the processing of actions in the "main" section > with AJAX, just to have a smoother user experience. > > These are certainly vague answers. If this isn't what you're asking > for, please provide more detail. > > 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: multi applications
On Jul 14, 2009, at 2:57 PM, sjtirtha wrote: > Hi, > > I'm looking for documentation, which describes how to build a web > application which includes many other applications. > For example like Facebook, it has following applications on the > first screen: > 1. On the left side is dynamic menu > 2. In the middle is the microblogging > 3. On the right side on the top is Request block > 4. On the right side in the middle is Highlights > > How can I build a web application like this? I was thinking to have > a main application which has a template that includes all other > applications. > But how can I set the context specific for every templates of the > included applications? > > regards, > > Steve There are several different aspects to what you are asking for and describing. The first part is showing all the apps within one page, and that's just a matter of a well-formatted CSS/HTML template. This template may (should?) include smaller templates (for each section). Ultimately your page will be called by a single URL, so you'll receive the entire request in one place. From there, you will have to decide how to handle the contexts. Look into the RequestContext class. The things you need to display on all pages, regardless of what the "main" view is at the moment, can be moved over there to avoid clutter. The "main" content could be handled in the view called directly by urls.py, and the rest can be inherited from the context dictionary keys coming from your request contexts. Also, you'll probably want/need to handle all the smaller apps on the page with AJAX, because you won't want to refresh the entire page for updating the microblog, etc. And since you're referring to FaceBook, they even do most of the processing of actions in the "main" section with AJAX, just to have a smoother user experience. These are certainly vague answers. If this isn't what you're asking for, please provide more detail. 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 -~--~~~~--~~--~--~---
multi applications
Hi, I'm looking for documentation, which describes how to build a web application which includes many other applications. For example like Facebook, it has following applications on the first screen: 1. On the left side is dynamic menu 2. In the middle is the microblogging 3. On the right side on the top is Request block 4. On the right side in the middle is Highlights How can I build a web application like this? I was thinking to have a main application which has a template that includes all other applications. But how can I set the context specific for every templates of the included applications? regards, Steve --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---