Loadable/Unloadable django apps - django

I wanted to make an application which could handle other applications as plugins, that the user could download and load/unload at any time. I read all the django documentation, and there doesn't seem to be a proper way to do it apart from installing the app by hand a doing a syncdb, with no possibility of unloading.
A good example of what I want to do could be the wordpress plugins. I wanted something like that for my django project, downloadable "plugins" that the user can load and unload at any time.
Is there any way to accomplish this?

I don't think it's possible. Django loads all its .py files only once, when its *cgi process is started. So to updating your urls.py or models.py requires restarting cgi, and I don't think you want to allow your users doing this. :-)

Related

Django application onload?

Is there a way to hook on the loading of the django application?
I want to be able to execute code when the application is loaded, so that I can for example
create static variables to be used later on by the application or establish connections to other servers.
The best I came across was to add code in the __init__.py file (How do I create application scope variable django?) but the problem with this solution is that I want my code to be executed after django has finished its startup process, and not in the middle/start of it.
Another solution I came up with is to have a view that handles this process and then when the application is deployed I issue a request to the url of the view. I don't like this solution very much, I prefer it to be a part of the loading of the application.
Any ideas of how to pull this out?
Thanks;
edit: Apllication refers to the entire django project and not one of the INSTALLED_APPS
Right now, there's really no good way to do this as Django doesn't have a startup signal. Interestingly, there is a ticket for this, but it's strangely tied to a branch that is being held up by another ticket. I'm not sure if Django 1.4 is feature-locked, yet, but as it's in release candidate stage, my bet is that it is. So, maybe you might get this in Django 1.5 whenever that happens.

How to integrate multiple image uploading with UPLOADIFY in django administration?

I met the django-uploadify (multiple file uploading) application, but the only template-use is described in wiki of the project. I need to integrate it with django admin. Any ideas?
#rebus and #Mordi have good suggestions; one of those is probably your best bet. Still...
The current implementation of file uploads in web browsers is single file only. That's a limitation of the HTML standards and the browsers themselves. When you see multiple file upload capability (all at once / select multiple) in some web app, something like Flash or Java is in play. You could potentially use a Flash or Java applet (check out Uploadify - about the easiest to work with you'll find), if you wanted, but you'd have to do some work tying it into Django: namely mapping the output of the applet to the input the Django Admin expects on POST.
Personally I found this package to be painful when I attempted to do this locally. It is 7 years old and not maintained. django-filer is a more modern implementation that has this exact functionality built into the admin panel, it was quick to set up and it seems to be maintained a lot better. And the UI is excellent!
If your really set on using uploadify my attempt was quite painful. When I went to the website to download the uploadify jQuery plugin it was a paid download. After looking a bit I found a fork, and was able to get it going locally, but because the python package is old it required a lot of changes from python 2.7..
To integrate this with your project in the admin will definitely require you to write your own custom admin template. In your admin.py you would have to override the default template and methods, this faq has some insights. In your new template you would include the uploadify jquery script and put the upload file field inside the form where your model fields would be. When you upload files the signal sender in the package will fire, and you would just have to intercept the signal and handle it with your intended logic
Very easy to implement multiple image upload with this project:
https://github.com/tstone/django-uploadify

Django settings app?

Has anyone run into an idea of a "settings app" for a django project?
It's a set of application variables set by an administrator (not developer, so settings.py fails) using admin panel.
Are there any apps ready to use?
edit
I probably didn't state my question clear. I don't mean editing the things like connection settings, rather things like "file size limit".
There is a very nice app that does this, called django-dbsettings. The official repo hasn't been updated in years, but I have an up-to-date fork on my github page.
The question is how would you store the settings.
Cause... if you store the settings in the database it will be troublesome since most of the code will already be initialized (using the settings before that) before you have a database connection.
If it's the filesystem that means you're going to have to include a Python file that's being modified by your webserver which sounds like a huge security risk to me.
So... in my opinion, it could be done but I would vote against it since it's dangerous. If things should be configurable from the web, implement that in the app :)
It sounds a bit like you're asking "how does an administrator change the settings (like database connection parameters) without changing settings.py?"
If your admin isn't familiar enough with python to change the settings.py file directly, you might consider giving the admin a simpler file to edit, perhaps a config file that you loaded from settings.py. Then all your admin has to do is edit the config file and restart the server.
This has an added benefit that you can limit the config file to only those parameters which your admin would need to mess with (like database connection parameters).
(Another option would be to get a better admin ...)

libjpeg PIL photologue django

So I have been looking up and down for a good solution to display images, audio, media in general with django:
From what I found there is the following solutions:
1. Photologue:
Cant seem to make it work.
It needs PIL and libjepg.
I tried to install both, but ran into different build problems.
Someone on stackoverflow recommended me this link:
http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/
Which is a great tutorial and also deals with removing PIL and reinstalling (which I have to do, I guess).
But somewhere along this tutorial I have to do this:
sudo rm -Rf build
And I dont feel confident enough to run a sudo rm command.
Also I thought there must be an easier way to achieve this, since EVERY Blog needs to display media.
2. Django itself says:
Let Apache do the display and use this:
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/pathtomedia/', 'show_indexes': True}),
for development BUT not for production.
So what does everybody use for production?
3. Other:
I managed to display images via os.listdir , urllist and a template:
allimg= os.listdir("/pathtomyimages/")
urllist = ['/site_media/Imagedir/%s' % url for url in allimg]
return render_to_response('picture_display.html',
{'allimg': allimg})
But this also seems not very promising, since I want to display images, audio, media from one directory on multiple sites.
I hear paginator could be the solution.
So now my question:
What is the best, easiest and robust solution to display media in django in development and in production?
What are you using?
Please help me out!
Thanks for the time.
django-photologue is an app for managing images and image collections for your project but isn't directly related to serving static media.
Since "best", "easiest", and "robust" are all fairly subjective terms depending on your specific needs, I recommend you first seek to understand why it is not common practice to serve your media files from Django. The short, generic answer is that Django must be loaded into each web server process that handles a request and this will use a non-trivial amount of memory. When serving a media file you (usually) just return a file from disk. Since no application logic is required you are incurring unnecessary overhead both from the memory required to run Django in a process and the extra code processing that will occur for Django to map the request path back to a view, load the file, and dump it into the response. Web servers (Apache, Nginx, etc.) are already very good at returning files from disk. This is why it is recommended that you have your web server handle static media files. The request does not ever need to get handed off to the WSGI middleware or Django.
There are many options available but there are a few that are likely to be common solutions. For example, if you've decided on Apache as your web server, you would need to configure it so that requests to your media path are handled directly by Apache and all other requests are handed off to Django. Apache + mod_wsgi is a fairly common choice AFAICT. Read through this carefully:
http://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/#howto-deployment-modwsgi
It is not strictly necessary to configure a separate web server as the documents recommend. You can use the same Apache instance for Django and media as you're getting started.
That tutorial is actually mine :)
the sudo RM -rf build, all this does is actually force remove any previous builds, which basically means it clears anything to do with the builds.
hope this helps

Confusion on using django socialauth

http://github.com/uswaretech/Django-Socialauth/tree/master/socialauth/
I'm a bit confused on how I should use this. Of course, I read the notes at the bottom but I'm a Django novice so I'll need a little hand holding.
The structure of this looks like a project structure since it contains a urls.py but I'm also aware that applications can also have that. It also has a manage.py which leads me to believe it's a project ( plus the subdirectories ).
So should I just be integrating portions of this into my existing project? This isn't an application, right?
The README also mentions grabbing API Keys. So if I want a standard interface where you click on a google/yahoo logo and it forwards itself via Javascript to the authentication page where you login if you already aren't logged in, kicks you back to your own page, would I need API keys?
Any other special tips are appreciated.
[We wrote this]
There are quite a few forks, which are ahead of us so you might want to use that.
If you just want openid, you dont need API Keys
If you want twitter/FB you definately need keys.
urls.py and manage.py are too show a demo app.
socialauth is the django app, which you can pull out.
I would use the fork from agiliq (same guys).
If you look at the commits in agiliq and uswaretech, you will see that the agiliq fork has more recent commits.
https://github.com/agiliq/Django-Socialauth/commits/master
https://github.com/uswaretech/Django-Socialauth/commits/master
And you could also use django-social-auth, which might seem to be another fork, but it's a completely different implementation.