On my iOS app, when a user logs in I start a series of firebase listeners for my users data... Profile, Accounts, Campaigns, etc..
How and where would I do something like this is django/python? I have a firebase db. I configure it in the top of my views.py, I log the user in on my login view. At this point in the iOS app, I add it to an AppState File and can call it from any view. In django, I ended up calling the data and creating my "joins" in the actual view like so:
campaign_list = []
results = db.child('campaigns').get(refresh_token)
for campaign in results.each():
campaign = models.Campaign().db_snapshot(campaign)
result = db.child('accounts').child(campaign.userUUID).get(refresh_token)
campaign.account = models.Account().db_snapshot(result)
Now I have my campaign object and attached the account object. db is set from the config at the top of my views.py. I believe this the correct way? I know its weird to use firebase and django, and I'm slowly switching to postgresql, but in the mean time, I have to continue to use firebase.
So how do I create a so called snapshot of my user, then access the data when they visit specific views. Aka, create a list of accounts, then on the accounts view, show the list. Instead of creating the list when the user visits the view.
Is this caching? haha
I've read two tutorials on elastic search and that seems like one of the tools I will need. But I also create lists of the data. I.e. I add analytics to the account data. Like a join. Is this possible in elastic search?
The other talked about create_command core. This was interesting and potentially what I need, however, if I placed my listeners in there, it would start on the WebApp startup, but wouldn't know the logged-in users info, so I would have to create every list upfront...? The tutorials that I read on django didn't really go into this a whole lot. And I know Im supposed to keep sessions light.
Any help and links are appreciated!
Denis Angell
Related
I have a django project and want to divide it into multiple databases with the same structure.
Use url to distinguish different databases. When the admin management page logs in, log in to different databases according to different urls.
For example: 127.0.0.1/admin uses the admin database, 127.0.0.1/admin2 uses the admin2 database.
Does django implement this function? What do I need to do, Can you give me some suggestions or ideas? thank you very much
TL;DR
As far as a single django project is considered, there is no default way to achieve multiple database.
Scenario 1
From your very limited explaination I will assume that you want to seperate data of one admin dashboard from the data of second admin dashboard, to achieve data isolation with respect to permissions & other models, this is called multitenancy.
Very briefly: In a Multitenant architecture you can have multiple tenants whose structure is defined by your models.py and you can control all this tenant via a main superadmin, these tenants can have their own admin dashboard where the data stored in them are only specific to their tenant users. In more simpler terms you can have a SaaS app with this method, where you can have multiple organizations and these organizations have their own users with their specific permissions/groups.
Multitenancy can be achieved in django via a Schema seperated database using POSTGRESql and this awesome package that has already done most of the heavy lifting for you. You can achieve seperate logins via url or subdomain. If your tenants have users who part of more than one organisation and you want a single login for all of them then you can use this package that goes along with django-tenants. It provides a public user table with permission modules separate for each tenant.
Scenario 2
From your very limited explaination I will assume that you still want seperate databases for your app, in such case you need to rethink your approach to the problem because it is not something you will fancy after deployment as there is not direct way provided by django. Instead you should look into micro-service architecture.
I made a web application using Django, that stores information in python arrays that are accessed by the user via the front-end. My problem now is that since I have deployed it via heroku, you can't use the website on more than one device, or else options selected from one device affects the website data for all devices.
How would I be able to make it so that user experiences are different / unrelated? How can I alter the views.py (or other components) so that the web application has a "session" for each user?
This is for a django web application running on heroku. The application is for my school, and it's akin to a battle-royal type site. Users can select people displayed on the site, which in turn removes them from a python dictionary that's stored in memory and puts them in another dictionary for later. The problem is, if more than one person is using the site at one time, they access the same dictionary. I haven't a clue what to try to solve this.
"processor.py"
names, accepted = list(), list()
# names contains many names of people, accepted is empty
def accept_person(person):
if person in names:
accepted.append(person)
names.remove(person)
else:
a = difflib.get_close_matches(person, names)
if len(a) > 1:
accepted.append(a[0])
names.remove(a[0])
else:
pass
"views.py"
def view_home(request):
if request.method == 'POST':
if(request.POST.get("yes")):
processor.accept_person(request.POST.get("yes", False))
Accepting a person on one device accepts that person for everyone accessing the site. I want to be able to have one "session" per user, so that one person changing this python dictionary doesn't affect everyone's experience.
What you are looking for here is a way to authenticate users, Django is brilliant for this and handles basically all of it for you.
But if you really want a full solution with minimal effort I would take a look at a package called django-allauth.
The official docs (https://django-allauth.readthedocs.io/en/latest/installation.html) can be a bit daunting so here is a good tutorial I followed the first time I integrated authentication into Django.
https://wsvincent.com/django-allauth-tutorial/
I'm currently working with some people to develop an application that will display a "sound library" when the user selects an option on their voip phone. The idea is that the phone system will pass a url with a device id in it, and that will open the django app to the users' library. I was told to remove login/user authentication in order to make the process easier for the user. My question is, is there a way to create a user field and save the model for future retrieval via the url request alone? Do I need to pass the device id to some hidden form first and redirect to the main page, and query the users' objects via the device id? I know there are security concerns but was wondering if it's even possible, any help is appreciated!
You should try using Djago REST Framework, it will make it easy to retrieve data with urls using unique identifier.
I've installed the django-registration app succesfully and it works great.
But now I want that when people are logged in, they have to fill in more data about theirself.
Do I need to create an new django-app, so with a new database, or is it possible to save the data in the djano-registration app database (the database with username, password and e-mail)?
And how should I link these two databases, so everybody have his own, unique "index"-page with correct 'place'/link in/to the database?
Thanks a lot!
Look at the User-Profiles section of the auth application. It explains how to create a Profile object (basically a new table, not database), that is connected to the User object, and has whatever data you add to it. It can be retrieved with get_profile().
Just to highlight something in the docs - get_profile() does not automatically create a Profile for you, you need to manually create one each time a User is created. This Answer gives sample code for using Signals to create a profile - after a User is created, it sends a signal to any registered process. You would need to code, and register a profile-creation function with the signal.
The author of django-registration has also done a nice profile app. Wrapping around the User-Profiles.
Check it out at:
https://bitbucket.org/ubernostrum/django-profiles/
I want to benchmark the performance of a template website on a modified kernel. I want to use a website template that has 2-3 tiers (frontend, database etc), logic to create users and some logic to store/modify data for each user.
A quick search did not reveal any useful results as of yet.
I've little experience in web development and was hoping that stackoverflow can point me to something useful.
I would suggest taking a look at the Django framework:
http://docs.djangoproject.com/en/1.3/intro/
http://www.djangobook.com/en/2.0/
Django operates using a three tiered (Model, Template, View) design. The Model is the database access layer and will enable you to validate and store information about your users. The Template is the 'presentation layer' that will both determine the layout of your page through html, but has access to your view and its variables. The View is the portion that will contain all of the logic for the page - in a way it works as a median between your model and your template. The url your user visits will determine which view function you load.
If you are interested in the admin capabilities of the framework, take a look at:
http://www.djangobook.com/en/2.0/chapter06/
You could simply download and run one of the sample django applications like:
http://code.google.com/p/django-voting/
or
https://github.com/scrum8/django-job-board/
Or you could just create a clean django project and turn on the admin console.