HTML5 Offline storage web framework - django

I am looking for a web app framework which can automatically generate an HTML5 offline storage based app, so while the users become disconnected they still can view the data which normally is stored on a server
Also currently I am using Django and it would be great if there was a framework which could pull data from Django and present that as an offline app.
From the related questions suggested by stackoverflow, while writing this question, I found one interesting link mentioning that GWT has such functionality, I would like to know more about that if possible and if it can generate an HTML5 offline app
Thanks in Advance

Rather than server-side frameworks, you should be taking a look at JavaScript frameworks.
Dojo Storage will transparently select between providers such as Google Gears, Adobe AIR or plain old HTML 5 local storage. Dojo 1.5 - dojox.storage: http://dojotoolkit.org/api/1.5/dojox/storage
There's also jQuery local storage: http://plugins.jquery.com/project/saveit
... or jStorage, which can act as a storage plugin for jQuery, Prototype or MooTools: http://www.jstorage.info/
With any of these, you should be able to use a quick little AJAX call to pull (JSON perhaps) data from your server and use one of these tools to help minimise your storage code.

You're talking about a standalone app, not a django app.
This can be done with javascript (jQuery, Sproutcore, JavascriptMVC, Pyjamas ...) or Adobe AIR, or...
Pulling data from Django is just a matter of setting up a syncing method, most probably using JSON, to fill up the browser local storage. So this is not django-specific at all.
If you want a standalone django app, this can be done if you bundle in a python desktop app django with a built-in server, that's another question

You could suggest the users to create web apps or use google gears instead... I don't know if this will fill the question, but, i'm in the same way. However, I'm developing an governamental solution who will run only for some kind of people, so, I can have a few control about the user's environment... All you need to do is to use jquery to detect if user has a live connection, or offer to the users a 'preferences' page where you define the behavior of the page itself...
Some info about offline cache: http://diveintohtml5.ep.io/offline.html
PS.: In another post in stackoverflow, I 've found another question: html5 offline caching with php driven sites... The last Post said:
HTML5 offline caching does not work to make your pages interact; it works only to make a
particular page available offline. Basically, it works on a URL-by-URL basis. If you
absolutely need offline functionality, you will be forced to make it work in JS.
Also, make sure your manifest includes all resources used by all pages.
Hope this helps!
Hope it helps!!

Related

Cloning PyQt app in django framework

I've designed a desktop app using PyQt GUI toolkit and now I need to embed this app on my Django website. Do I need to clone it using django's own logic or is there a way to get it up on website using some interface. Coz I need this to work on my website same way it works as desktop. Do I need to find out packages in django to remake it over the web or is there way to simplify the task?
Please help.
I'm not aware of any libraries to port a PyQT desktop app to a django webapp. Django certainly does nothing to enable this one way or another. I think, you'll find that you have to rewrite it for the web. Django is a great framework and depending on the complexity of your app, it might not be too difficult. If you haven't done much with web development, there is a lot to learn!
If it seemed like common sense to you that you should be able to run a desktop app as a webapp, consider this:
Almost all web communication that you likely encounter is done via HTTP. HTTP is a protocol for passing data between servers and clients (often, browsers). What this means is that any communication that takes place must be resolved into discrete chunks. Consider an example flow:
You go to google in your browser.
Your browser then hits a DNS server (or cache) that resolves the name google.com to some IP address.
Cool, now your browser makes a request to that IP address and says "get me some stuff".
Google decides to send you back a minimal amount of HTML and lots of minified JavaScript in the page.
Your browser realizes that there are some image links in the HTML and so it makes additional requests to google to get each of the images so that it can display them.
Now all the content is loaded on your browser so it starts to execute the JavaScript code, and that code needs some more data from google so it starts sending requests to google too.
This is just a small example of how fundamentally different a web application operates than how a desktop application does. On a desktop app you have the added convenience that any operation doesn't need to be "packaged up" and sent, then have an action taken, etc (unless you're using a messaging architecture, but that's relatively uncommon outside of enterprise apps).

django: Usage logging tracker application

I am very new to web development. I have build a django application. Now what I want to do is log user behavior such as mouse clicking, time spend on certain section of the webpage. I am very new django so my django application is very simple and I want to start exploring how to build an user behavior tracker to my django application. Ideally I like to save all this session information in database/table. Where should I start and any example would be a great help.
What you want is just web analyics. There are lots of ready made systems that can do this for you, so you won't need to make it yourself in Django.
I would recommend Piwik as it's an open source solution. The drawback is that you have to install it yourself, so something like Google Analytics might be easier to set up, just remember that using this option enables google to track your visitors too.
There are a lots more web analytics software. For a good overview check this Wiki page:
https://en.wikipedia.org/wiki/List_of_web_analytics_software

Recording Audio on the browser

I have basic website I developed in Django and SQL lite.
I want to add this feature to it.
A user should be able to click a button and record a message that is no longer than 10 seconds and save it.
It can be saved on server as an audio file or can be saved on the database if that is more efficient and possible.
Can you please let me know if Django already has any component or plugin or something that I can use?
If it doesn't exist, what are my best options. If I need to write from the scratch, can you point me to any tutorials/blogs, etc?
Thanks for your time
RM
As far as I know there's no such plugin for django. But it's not mainly django's work to do this. You can record audio via javascript using Web Audio API, or by using one of several projects (see this answer). Also if you have to support older browsers I think that your best bet is to use flash for this purpose (but some mobile browsers don't support it). So the best thing is to use some sort of fallback mode with html5&javascript implementation for browsers that support Audio API and use flash for others.

using backbone/ember makes django being a simple REST API?

I have read a couple of articles about using new JS frameworks like Backbone.js or Ember.js
I have come up to this statement:
If I use a JS framework like Backbone.js/Ember.js, I then move the logic from the back-end (Django) to the front-end.
Therefore, will Django actually be used only for its Models?
Does that mean that Django Views and Django Template are not needed anymore and the Django back-end is kinda turn into a "basic" REST API that will be consumed by the front end.
Do you agree? Is it then the purpose of Django in this case?
Is turning the django backend into a REST API one of the most suitable use case when using a framework like Backbone.js/Ember.js for the front-end?
Thanks.
Django is perfectly fine to be used this way, you still get the admin, the models, the orm and all the third-party plugins. However, it isn't blazingly fast, so if you're doing simple document level, non-relational REST mapping, you might wan't to look into node.js and mongoDB for instance.
If you're sticking with django (like we are, we like the structure it gives us), you can use one of the REST plugins:
Django Rest Framework A perfect match since DRF 2.0, under very active development!
Django Tastypie (checkout backbone-tastypie.js for integration)
Django Piston (might be a bit stale or has development picked up lately?)
If you only want to work with frontend development, checkout the Backend-as-a-Service places like cloudmine.me or firebase.com that handle all backend stuff for you, for a price of course.
Django may seem unnecessary once you start thinking about single page solutions and Javascript applications, but if you want your site to be 'fail proof' it wouldn't be impossible to develop both a client side Javascript version of the site as well as a backend django side incase the user, or your site's javascript, fails at some level. Of course this requires creating your site twice, and probably isn't needed in the age of modern browsers, but such would be one of the few instances where you would mix the two for a complete solution.
Yes, that's about it. You can use it to manage authentication to resources and such and maybe use a main view for your application but you won't need to use the server side templating since these frameworks are made to work with json/xml response.
That's why a lot of people are moving to lighter backend/backbone or ember combo instead of a complete solution like django. You can also use your django for caching json response which makes your application appears faster.
We are doing that and use django-piston to make it easier on you.
Normally you make your entire website under Django and only one page will be a "single app page" using backbone.js, usually that page is a very interactive page, with lots of small updates that occur frequently and need to be shown very fast to the user. This page, because of the large number of changes and user interactions is constructed on the client-side so that you are using his PC resources and not the server's, the rest of the pages can use django because it offers you a very stable and secure framework for the server-side

Should my web based app be a consumer of my api?

I will be developing a mobile app (iPhone) and a web based app (Django) soon. For the mobile app I will be creating a REST api (most likely using Django) to send data back and forth from phone to server.
When I comes time to create the web based version does it make sense to just create it as any other client of the api. In other words both the mobile app and the web app will get there data from an external API over HTTP. Or should the web based app have direct access to the database that the api is using and just get its data that way?
Break it into three "sections". The first uses a Python API to manipulate the database. The second interfaces your REST API with your Python API. The third talks web and uses the Python API.
I would create the web application to serve the API to the mobile client. That is, give the web based application direct access to the database. This will simplify your XML / JSON RESTful resource access.
I would say no, don't use the API for the HTML version. If you design your Django well, you can end up with less code than using the API for the HTML version. You also get to retain the ability to have a web designer work with the Django templates whenever the boss wants the spelling changed on something.
I'd suggest trying to define a base app for your iPhone app to interface with, and then extend that within a second app for the HTML version. App1 would have all of your models (including business logic), and a views.py for processing the data to/from the iPhone. Then create App2 which uses App1.models, but creates its own views.py. With any luck, you'll find yourself with the ability to change nothing but the template used to render the output, so you can reuse your views by passing the template as an argument.
For example:
App1.views:
def list(request, template="list.json"):
list = Model.objects.filter(deleted=False).filter(user=request.user)
list.reverse()
## Lots of other logic to work on the list.
return render_to_response(template, {list: list,})
App2.views:
def list(request, template="list.html"):
return App1.views.list(request, template=template)
I think the answer to this question has changed over time. A year ago when asked it was probably still too much hassle to do this, but now I'd definitely say yes - using your API as the basis is the smart thing to do. As Web sites use more HTML5 and Mobile apps get smarter it really makes sense to have all your "UIs" read/writing from the same API layer. This will give you much more flexibility in the future.