Dynamic adding apps to Django - django

I'm building a backend with some core-functionality app (which means, of course, a single DB for the app).
I'm looking for elegant way to create app for every new customer by "copying" some template (basic) app to be able modify every's customer app with specific customer's requirements.
For ex., I have some basic StoreApp in Django. It could have some basic features, models etc. Now, when some new customer wants to sign up, I want dynamically (not manually) create additional copy of the existing StoreApp (of course, under different name and its own DB), make initial migration for it, register it in the settings and so on. Lately, I want to customize this new app according to the customer's requirements. I'm just looking for a way to separate code maintenance for every existing app, but, as I mentioned before, not to create every app manually.
Any elegant way to do it? Some existing plugin for Django?
Thanks in advance,
Efi

Related

Is it possible to add an app to django that does not require a database

I have a simple script that creates a unique one time only disposable hash and I was hoping to just add it to my existing django site as this tool is for the people that use the site.
I can find nothing at all on google about this and it seems a shame to have to create a completely separate website just to provide a GUI for a simple 5 line script.

How to structure a project directory in django?

Suppose you are building a Google website. (ok big dream)
Google has web search/youtube/email/news/etc ..
For this site, I'd like to structure my django directory like
Google/
search
youtube
email
news
and so on.
How do I structure such a site?
Create an app for each even though I'm not expecting to publish any of the category as an app?
Where would a common stuff (such as user model, utility modules, decorators..) would go, create a common_app?
Applications are reusable components for a django project that revolve around a central purpose. Applications don't need to map directly to your url structure of the website. While there is a standard structure for a django application to tie in with some of the management commands, such as tests.py, models.py, static files at /static/ you don't need to have any of it to be an application. For example, South is a popular django application used to provide database migrations. It adds a few management commands to manage.py.
When you are adding functionality and it doesn't map directly to the purpose of the application, just create a new one. So instead of thinking of it a a common_app, think about what the purpose of the application would be and how it might be utilized by your other applications.
In my projects, I tend to create a base application to handle the base template and static assets that are used in the base template. I'll create an accounts application to handle the user model and implement things like password reset. To deal with global notifications from any part of my site, I'll create an alerts application. The list can go on for a lot of the common functionality, but it's grouped in a way that revolves around a function and written as if it would be distributed.
So, in your specific case, you'll likely have at least an application for each of the domains such as search, youtube, email, and news, but also an application for each common component you might want to use across your core domains.

Is there any way to administer multiple Django servers at once?

Short Version
Is there any tool that will let me use a single Django admin page to affect multiple Django installations on different servers?
Detailed Version
I've got a bunch of different servers, each with their own Django installation. This works great ... except when I want to do something via the Django admin to all of the servers, in which case I have to log on to each server separately.
For instance, let's say I have a release coming and a co-worker (who's not a programmer) wants to use the admin to make a "message" record about the release for the server's users to see. They have to log in to each server's admin individually, create the message record, then move on to the next server until they've gotten through all of them.
To get around this whenever I have a multi-server change I've been using Git; ie.:
I make a commit with files for the change
I push that commit
I pull that commit on all of the servers at once (using Fabric).
However, this too is sub-optimal, because we can't take advantage of the admin interface, and doing something as simple as adding a "new release coming" message requires an actual (mini-)release itself.
So, it seems to me the best way to handle this would be if there was some sort of meta-admin tool my co-worker could use to Django admin work on multiple servers at once. Does anything like that exist?

How to setup groups (sub-sites) in Django

I'm new to Django and I come from Drupal family. There we have Organic Groups with which we can create groups of content and subsites; how do I do something like that with Django?
Say I'm making this site for my company using Django and every department in my company needs a private section on the site. For example, the design people have their own part of the website into which the back-end developers can not come in. And the back-end developers will have the same thing too.
I want to build the site in such a way that I just login into Django admin and add a new category or subsite or group (whatever the Django term is) with the same settings from other groups or with similar settings.
It depends on what you mean by "private section". You should probably try looking at it from a different angle:
Django splits a site's functionality by means of "apps". Each app does its specific thing, and gets a set of tables in the database. Apps can access each others' tables. For example, it's common for other apps to access the Auth app's user, group, and permissions tables. Is this what you mean by "sub sites"?
As for access control, users can be assigned to groups and they can have various administrative permissions assigned to them. Add, change, and delete permissions are automatically generated for each model (i.e. database table). You can also add your own permissions.
I don't think you'll be able to separate the designers from the back-end developers at the Django level. You'll need to do something else, such as maintain separate source repositories for each and merge them to create the usable site (each group would have read-only access to the other). It really depends on your teams' discipline, because these elements can get intertwined.
Django recommends that static files be served by something else, say directly from your web server, or from another machine with a simple HTTP server (no CGI/WSGI/whatever). This is because Django can only slow down static files compared to direct service. However, for testing, ther is a static page server you can enable.
Given all that, static files usually amount to CSS, images, media, and JavaScript. Of these, the back-end people might want to mess with the JS, but that's it, so this could be in the designers' repo.
The Django tree itself has the code for the site and the apps. It's almost all back end stuff. The exception is the HTML template files, located in the "templates" directory in each app. These are the files that are filled in with the context data supplied by the back-end view code. I have no idea if this is front or back end for you guys; it could be mostly back end if there's a lot of CSS discipline, but I think that's unlikely.
There are a lot of things that you can do in Django that make life easier for one side or the other. For example, template tags allow custom Python code to generate HTML to insert into the page. I use these to generate tab bars and panes, for example.
I really can't help much more without getting a better picture of what your needs are. The question is still vague. You're probably best off taking a day or two going through the tutorial, seeing what the Django perspective is, and then working out how (or if!) it fits into your needs.

Multiple PostgreSQL schemas and users on Django with subdomains

I have seen various questions on multi-site and multi-host Django, including subdomains and specific schemas per subdomain. What I have not seen is a solution (or tips so I can code one) to this problem.
I am using Django + PostgreSQL on a site, let's say myapp.com
The main site myapp.com is used for registration of companies
A registered company gets its own subdomain, company.myapp.com, and logs in and works from there.
My idea of doing this is by making 2 initial schemas in PostgreSQL.
Schema "auth" for companies and users
Schema "empty_company_template" with the basic tables for a company, all empty but hooked up to the right sequences etc.
When a new company registers, I want this to happen:
Create a new schema for the company, derives from empty_company_template
Create a new DB user for the company, named company (the company name)
Set the search path for this new user to company, auth (no access to empty_company_template, no access to other users schema's)
To me this seems better than the existing solutions that all seem to depend on one single database user for the entire application (with access to all schemes). However, I struggle to get this to work. Is this indeed a viable approach? Can anyone point me in the right direction? It's Django, so perhaps it's been done and I just haven't found it?
I have a working solution that does everything except separate users.
It's a small piece of middleware (just process_request) that determines the subdomain, and executes a SET search_path query on the database. It's good enough for me for now.
Anyone interested in the code, just contact me. I'll publish it somewhere when it's final.
EDIT Dec 22, 2010:
I published the code on my blog at
http://blog.dyve.net/django-subdomains-and-postgresql-schemas
If you want to have separate DB users, you'll probably want separate Django instances, otherwise there will be no security gain. This model will require much more complicated process management. I don't think you'll find a ready-made solution for such an application, so you will most probably have to roll your own. Otherwise, if you're unwilling to invest much time, stick with the one user for the entire app approach.