I am new to Celery and I can't figure out at all how I can do what I need. I have seen how to create tasks by myself and change Django's file settings.py in order schedule it. But I want to allow users to create "customized" tasks.
I have a Django application that is supposed to give the user the opportunity to create the products they need (files that gather weather information) and to send them emails at a frequency they choose.
I have a database that contains the parameters of every product like geographical time, other parameters and frequency. I also have a script sendproduct.py that sends the product to the user.
Now, how can I simply create for each product, user created a task that execute my script with the given parameters and the given frequency?
As you know how to create & execute tasks, it's very easy to allow customers to create tasks.
You can create a simple form to get required information from the user. You can also have a profile page or some page where you can show user preferences.
The above form helps to get data(like how frequently he needs to receive eamils) from user. Once the form is submitted, you can trigger a task asynchronously which will does processing & send emails to customer.
Related
I'm developing an API with Django Rest Framework for handling some subscriptions
I wanted do make the registration in 2 steps.
First, i would register user in my database, after that i want to register user to other service (email marketing, for example).
I have to do it in two steps because the registering of the user in external services may take some time (or the service can be unavailable at the time of request) and i don't want users to wait everything so they can go to other pages.
My idea is: After registering user into my database, i would return http 200_ok to the front-end so user can go to other pages, and in my backend i would use that data to try to register the user in external services as many times as needed (e.g: waiting if other services are unavailable).
But rest_framework only allows me to return Response() (i'm using class-based views), so i only can return http 200_ok, but if i return the function ends and my other functions (that will take more time to run) will end aswell.
Is there a way to do this?
Have a look at https://django-background-tasks.readthedocs.io/en/latest/
This could help solve your background tasks
I have developed a website having functionality such as writing,posting ,user profiles, events & activities, offers..etc.I need to add one more functionality and i.e. Automatic push notification to the users about activities & events, offers and discounts (facebook like notification).
What I want to do is to inform users in their profiles, whenever admin/staff add their events & activities and offers or if user are updating profile, then inform the user of that update. I have looked around many applications but I am still very confused about how to do it.
I really need some proper tutorial or guidance on how to go about doing it. I know how to register a notification and send it on proper signal but there is no documentation on how to show these notices in a template, if this can be done.
I'm building an API where I need return to users events with a timestamp within in their available time. Since this is an API I don't need a front-side, I will receive a json in backend, but I am not clear about which data should I receive. User should be able to mark a schedule as monthly, weekly, etc. or just for one day. I have found projects like this one django-scheduler but I don't know if it will fits my needs. Any advice?
I'm looking for a way to keep track of users that are online/offline. So if I present all users in a list i could have an icon or some kind of flag to show this. Is this built in in Django's default Auth system?
My first thought was to simply have a field in my profiles called last_logout in the models and update it with the date/time each time user logged out.
With this info and the built in last_login I should be able to make some kind of function to determine if the user is loggedin/online right?
Or should I just have a boolean field called "online" that I can change when user logs in and out?
With only django it will be hard to do. For such task async frameworks are more suitable.
For example, tornado.
Users won't do logout explicitly every time they go offline. They just close their browser and that's it. You can't know it with only django auth app. It is not designed for such tasks.
Even if you will check for not expired session, it not gives you all online users, because session can be non-expired for 30 days.
So to get real online users, possible solutions are:
Every user will send some data via javascript to your server, for example every 10 seconds. You can fetch that data on server and put user into cache and set cache key to be alive for 10 seconds. So when you need to know, who are online now, you'll check your cache. But it is not a good solution, because it will need a lot of server resources.
Use async framework (tornado) at server side (you can setup separate process for exact requests). And use websockets (SockJS is a good library for that at client side). It is a more complicated solution, but it is better.
You have to consider what exactly means for the users to be "online". Since any user can close the browser window any time and without the server knowing about that action, you'd end up having lots of false "online" users.
You have two basic options:
Keep track of the user's last activity time. Every time the user loads a page you'd update the value of the timer. To get a list of all online users you'd need to select the ones with an activity before X minutes. This is what is done by some web forums.
Open a websocket, long polling connection or some heartbeat to the server. This is what Facebook chat does. You'd need more than just django, since to keep a connection open another kind of server-side resources are needed.
I'm trying to set up Satchmo, and I found this cool Subscription Product, but what I want is make a members-only section on the site (a multiple store website) itself. In other words, I want the users to make subscriptions to be able to use certain features. Is this possible in Satchmo?
I guess if my website is called xyz.com then I can create xyz store on the system and let it have a subscription product, but can I integrate it with the Django login system?
Thanks in advance.
You can listen to satchmo_store.shop.signals.order_success and include in your listener all the required steps for self subscription (user to group, object creation etc.,..).