How to check user online with django and GAE? - python

I'm using Django with Google App Engine and I want to build a module for checking online/offline user .
But GAE don't support session so it's hard for me to find way to do it.
how can i resolve this problem? Any ideas would be appreciated, thanks.

A session library won't solve this, because HTTP is stateless. Using sessions, you can determine when someone last made a request, but that doesn't tell you if they're "online" or not - they could have immediately closed their browser tab, or they could leave it open for a week.
If you really, really need to do this, you could use the channel API. Alternately, you could use a session library, or log users in using the Users API, and list as 'online' anyone who's made requests in the last n minutes.

Related

How can I implement simultaneous login feature in Flask?

I made a Flask app using flask-login and flask-sqlalchemy.
When I run my app and login with the same user id in more then 2 devices or different browsers, It fails and renders Internal Server Error.
But I want to make this simultaneous. When somebody log in with the user credentials as the same of somebody current, I don't want anybody to logout or face an error but to share the same user.
How can I make this?
If this is impossible, I want to inform the first-logged-in-user(like "your session was terminated because another user logged in with users" or something). Any hints or examples?
The issue might lie within your custom login code. You can attach your code to the question or try using the code supplied in the documentation:
https://flask-login.readthedocs.io/en/latest/#login-example

Django: How would you constantly check an API even when web app is not loaded?

My website needs to send an email to users even when the web app is not running.
I have an API and each time I receive data I need to send my users an email.
I need to be guided to the right direction. Thanks in advance.
Have you considered writing a python script and letting it run on your server, totally separate from django?
Consider a scheduler, https://github.com/llazzaro/django-scheduler may an option for you.

Django Views and Urls

This is a bit long so please bear with me.....
I am in the middle of building an android application. I have built the client app, now I am working on the server.
I have decided to use Django for the server. Though I have already decided on the data structures, currently I am stuck with how am I supposed to send different kinds of requests from the server and how the server is supposed to handle them differently.
For example:
A request could be registering a new user and storing his
credentials.
Another request could be when a user likes or dislikes a comment.
..... there could be few more
One way that I can think of is to first have separate "django views" for each kind of requests and then attach a "django url" to it. Now from the client app, a particular kind of request could be made at its specific url, and then once received at the server, "django" will automatically direct it to its view, which will then take the desired actions.
Please let me know if there are any better ways to do it.
Yes, that is exactly how to do it.
You probably want to look into Django REST framework for this.

Testing Django Facebook App

I'm making a Django app with Fandjango and I'm trying to unit test it with Django's test framework. The only thing is, in order to test effectively I need a "signed_request" parameter that Facebook sends with every request. Right now I'm logging the requests my server gets from Facebook and copying + pasting the signed_request token I get, but that only works for a few hours at a time.
Is there a simple way to handle this without doing a mock of the whole Facebook API?
Thanks!
You can use Test Users:
http://developers.facebook.com/docs/test_users/
I think the access token never expires, or at less until you delete the Test User.
Well, I understand it's also possible to authenticate fully server side, using just OAuth without Javascript SDK. In that case you should be able to aquire a valid token yourself. There are, I think some libraries that can be used for that like:
http://pypi.python.org/pypi/django-social-auth/
However please note, I've never done this myself so it's more of a suggestion, than a definite answer.
EDIT
It seems like social-auth has some testing functionality that is capable of automatically signing in to a facebook account. You could probably copy the code from there.

Facebook login without opening another window/popup

Is it possible for web application that is created by the same owner as facebook application to have access to facebook application without going through a explicit session opening exercise?
Most of the work is done on server side and I need to access facebook application directly from backend server. Each time the website loads I do not want user to go through the facebook connect experience as data to be displayed does not require his facebook profile/data access.
Let me know if its possible?
Although its not related to language, I would be grateful if help is provided keeping python in mind. Thx
The opening of a window for facebook auth is the way facebook set up their authentication for facebook connect.
I don't think they offer another way of authenticating users, and I doubt you'd be able to work-around/circumvent this method without breaking their terms of use
Sorry I don't have better news for you :/

Categories