Posts

Showing posts with the label django

Web application framework comparison by memory consumption

Memory consumption is slightly specific to my area of software development now, but I did some research recently and maybe these results can be useful for others. Of course, I know that precious comparison is very difficult to carry out, but actually I needed only overall picture. And let me admit that results are pretty interesting and even frustrated (at least for me). As a basis I took so-starving project, and measured initial RSS (Resident Set Size) of the each process (local development webservers). Platform: x86_64 Linux (latest Ubuntu with all updates). As a reference, here is the RSS of the interpreters in interactive console mode: Interpreter Version RSS (kB) stackless python 2.6.4 3916 ruby (via irb) 1.8.7 4664 python 2.7.1 5624 php 5.3.5 6924 v8 (via node.js shell) 2.5.9.9 8796 One more reference - the most simplest WSGI app ( example  in the Python documentation). It's RSS: 7336 Kb , so I assume it's almost impossible to consume ...

Introduction to ReviewBoard

Image
Review Board is a powerful web-based code review tool that offers developers an easy way to handle code reviews. It scales well from small projects to large companies and offers a variety of tools to take much of the stress and time out of the code review process. Review Board is written in the Python programming language and makes use of the Django web framework. Installation   Install auxiliary packages if needed and all its dependencies: $ sudo apt-get install python-setuptools $ sudo apt-get install python-svn $ sudo apt-get install python-subversion $ sudo apt-get install apache2 $ sudo apt-get install libapache2-mod-python $ sudo apt-get install git Clone the ReviewBoard package and install it: $ git clone git://github.com/reviewboard/reviewboard.git $ cd reviewboard $ sudo python setup.py develop Also install post-review tool: $ sudo easy_install -U RBTools Set up the required site for the ReviewBoard (for Apache/SQLite backend, otherwise - see Cr...

New articles

I have published several articles on eellc.ru website. I hope you'll find them useful and interesting: Software System Requirements Questionnaire SQL in large-scale systems Architecture of large-scale systems Django speed, stability and security The website doesn't allow to post comments, so you can leave your remarks, suggestions and complaints here. Enjoy!

Mini HOWTO: Programmatically upload a file in Django

Surprisely, there is no any good advice in the Internet how to programmatically upload a file to the FileField field in the Django. I want to cover this issue with the sample that shows how to upload a generic file from the Internet to a Django application. The code is simple: import urllib, mimetypes, os from django.core.files.base import ContentFile #... filename, msg = urllib.urlretrieve(img) ext = mimetypes.guess_extension(msg.type) name, original_ext = os.path.splitext(filename) new_filename = filename if ext != original_ext: new_filename += ext obj.file.save(new_filename, ContentFile(open(filename).read())) First of all, we retrieves a file. urlretrieve returns a tuple <filename, msg>. filename is a name of a temporary file with the downloaded content. msg is a HTTPMessage class instance that contains headers of the file. We use msg to determinate the type of the file. For this guess_extension method is used. It is required for the case when the file is gene...

Daemonize a script

Sometimes it is required to start script as daemon (for example Django site in development mode), and I want to provide guidance how to do it in Fedora 9. First, it is required to write auxiliary bash-script for running necessary script (let's call it 'site.sh'): #!/bin/sh cd /path/to/site/ nohup python manage.py runserver 0.0.0.0:8080 --noreload > site.log & echo "${!}" > /var/run/site.pid In this script I changed directory to site location, and ran it via 'nohup' command. Also I took PID of created process via '${!}' to manage it later. This script should be run under root privileges and should be checked via 'ps aux | grep python' for equality of PID of running process and stored in /var/run/site.pid. If everything is fine, let's move forward and create init-script (let's call it 'site'): #! /bin/sh # Startup script for site # # chkconfig: 2 96 04 # description: site service # Source function library. ....

Django admin changes in SVN trunk

Recently in Django SVN trunk all admin interface changed to newforms. It doesn't have backward compatibility, so I provide some hints to upgrade existing Django applications. There are at least 3 steps for upgrading: Update urls.py to follow new admin URLs. Update admin classes. Change all newforms imports. Update urls.py to follow new admin URLs. Initially urls.py looks like: urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), ) Now it should look like: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), ) Update admin classes. Initially admin classes were a part of model classes. Now they should be moved to independent classes. If a model had empty class: class Model1(models.Model): class Admin: pass Now it is enough just register a model...

Adding security features to Django projects

Security is most valuable feature of any software, and each developer should keep in mind security issues during programming. In this article I show how to restrict user's access to view, but not modify objects in Django project. It could be an equivalent of 'Readers' field in Lotus Notes/Domino application. First of all, let's set up Django . Check out Django’s main development branch (the ‘trunk’) like so: svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk Install it: cd django-trunk sudo python setup.py install Create project, which be called 'secure_site': django-admin.py startproject secure_site Test the installation - start our project: cd secure_site/ chmod +x manage.py ./manage.py runserver 9000 Open browser by URL: http://localhost:9000/ and if 'It worked!' page is shown, then go further. Create two applications - sample (for testing) and secure (for handling security information): ./manage.py startapp sample ....