Affiliations

» See a train - click here

Entries with tag "django"

January 23, 2010

Tags: django, history, models, tables, unpickled

I've uploaded a new version of django-history-tables [1] to the mercurial repository. It now should run on Django 1.0 + 1.1 and finally supports (although basically) the Admin interface.

For those that don't know django-history-tables (guessing that's 99.9% of everybody reading this), it is a pluggable Django application to create addition tables inside the database recording the history of changes and deletion of Django models.

This in itself is not unique there are many more project out there doing basically the same but most implement this by serializing data (such as pickling, json, xml, etc). Big drawback of this approach is that when schema changes your serialized history does not change with it. Somewhere down the line when you have forgotten all the schema changes it will be most difficult to use this history data.

django-history-tables works by using one additional 'normal' database table to store history information; major benefit of this approach is that there's no pickling, no serializing, and it should be able to support anything that your database supports as well.

Schema changes in this approach needs to be applied to both tables. When you change your model, you will need to change the schema of the history table as well. <shameless-plug>By using my sqldiff extensions in django-extensions this process can be made pretty easy.</shameless-plug>

In the future I hope to support the major schema migration tools for Django so that we can make schema changes in the history models even less painful.

It has been a while since I've worked on django-history-tables and truth be told I kinda forgot about it :-) It's been lingering in a corner for a while now and I've been busy doing other things like maintaining django-extensions and writing news sites in Django.

But then something really cool happened, something which is really telling for Open Source projects and the Open Source community as a hole. Somebody contacted me, out of the blue, an email from a stranger with the message that they had updated my old proof-of-concept code to run on new versions of Django with the patch attached.

We started talking and found that other people had written patches for it as well and put them up on the issue tracker at Google code. A project which was, for all intents and purposes dead to me, suddenly sparked back to live.

This inspired me to get to work again and to try to get the project back into some kind of shape.

Now it's not perfect yet, it will have bugs and needs more work. I can also do with some help improving it, making it better and reviewing that the implementation works as expected.

So please try it, play with it, have fun with it. And if you like it leave a message :)

[1]Django History Tables: http://code.google.com/p/django-history-tables/
Add to:  

July 11, 2009

Tags: app, bookmarks, code, django, hg, network, reusable, social

The Django Social Bookmarks app does what you might expect this application to do.

It provides an easy and reusable way to get those pesky add to this social network site on a Django site.

It currently supports 34 different sites, ranging from the big ones like; twitter, facebook, slashdot, delicious, digg, technorati, strumble to local networks like nujij (Dutch), ekudos and tagmos or netjes (Belgium).

All texts in the app use Django i18n so people should have no trouble contributing both links and translations to make it truly comprehensive.

After adding social_bookmarks to INSTALLED_APPS and making sure the images are reachable you can use the provided inclusion-tag to add the links in a template.

Template example:

{% load social_bookmarks_tags %}
<div class="content">
    {{ content }}
    {% show_social_bookmarks object.title object.get_absolute_url %}
</div>

The default inclusion-tag template specifies some simple css classes so you can theme the links without having to write you own template.

CSS:

/* div around the entire block of links ^/
.socialbookmarks {
    display: block;
}
.socialbookmarks strong {
    font-weight: bold;
    color: black;
}
/* individual links */
.socialbookmarks .social {
    color: #ccc;
}
/* no borders on images */
.socialbookmarks .social a img {
    border: 0px;
}
Code is maintained in a mercurial repository and can be found here:
http://bitbucket.org/trbs/django-social-bookmarks/
Some points on the todo list for the future are:
  • Some more tags and/or api functions, for people that don't want to use the inclusion tag.
  • Putting the links in database so that they can be added, changed, enabled and disabled in the admin.
  • Add caching to the template tags

Hopefully it is useful for other people and project as well. If you want to use this in your own project, contribute with links, translations or idea please drop me a line at bitbucket or #django irc.

Add to:  

November 14, 2008

Tags: code, django, extjs, source

Finally got around to creating a repository for the source code of ExtPaste a ExtJS [1] / Django [2] powered pastebin [3].

People where asking me about the source code for http://extpaste.com on the ExtJS forums for some time now. So here it is: http://hg.trbs.net/extpaste/

The project was development and currently runs on a Django version before 1.0 :( But i'm working at this moment to get the repository up to date with Django 1.0. I've already ported it to NewForms-Admin so the biggest thing left is to port to newforms.

If everything goes fine the code in the repository should be on Django 1.0 before the end of the day.

Updated 15-Nov-2008: Extpaste now runs on Django 1.0 and higher

[1]ExtJS JavaScript Framework: http://www.extjs.com
[2]Django Web Framework: http://www.djangoproject.com
[3]Modeled closely to the excellent dpaste Django pastebin: http://dpaste.com
Add to:  

November 13, 2008

Tags: django, kcachegrind, lsprof, runprofileserver

Today i've added a new option to Django-Extension's runprofileserver to make like a bit easier for people who want to use KCacheGrind to profile Django.

This was sparked by profiling one of the scientific Python scripts i wrote for my research project. I wanted to see where (or at least if) i could squeeze a bit more performance out of it without resorting to ctypes/c-modules or weave. For more information about the latter see: http://www.scipy.org/PerformancePython

So i disabled Psyco [1] which confuses the profiler and started my program with the cProfiler enabled and started analyzing it's output.

you can do this easily by executing:

  $ python -m cProfiler ./my_application.py

From earlier encounters with profiling i found that KCacheGrind is a really awesome application for viewing and analyzing profile data. However Python's profiler module cannot directly save it's data in a format which is compatible with KCacheGrind. There are a few ways around this and one of them is a script called: lsprofcalltree.py [2].

It converts the profile information from cProfiler to something which is readable by KCacheGrind. Best of all you can use it as an in-place replacement for the Python interpreter so it's just as easy to use as the "$ python -m cProfiler" line.

Coming back to the runprofileserver I implemented lsprofcalltree directly into the extension command so you do not have to convert the output data by hand later. All you need to do now is enable the --kcachegrind option and all the profiler data is automatically saved in the KCacheGrind compatible format.

Example:

$ mkdir /tmp/my-profile-data
$ ./manage.py runprofileserver --kcachegrind --prof-path=/tmp/my-profile-data
Validating models...
0 errors found

Django version 1.0-post-release-SVN-SVN-unknown, using settings 'complete_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[13/Nov/2008 06:29:38] "GET / HTTP/1.1" 200 41107
[13/Nov/2008 06:29:39] "GET /site_media/base.css?743 HTTP/1.1" 200 17227
[13/Nov/2008 06:29:39] "GET /site_media/logo.png HTTP/1.1" 200 3474
[13/Nov/2008 06:29:39] "GET /site_media/jquery.js HTTP/1.1" 200 31033
[13/Nov/2008 06:29:39] "GET /site_media/heading.png HTTP/1.1" 200 247
[13/Nov/2008 06:29:39] "GET /site_media/base.js HTTP/1.1" 200 751
<ctrl-c>
$ kcachegrind /tmp/my-profile-data/root.12574391.592.prof

Here is a screenshot of how the above commands might look in KCacheGrind:

Screenshot

More information can be found at http://code.google.com/p/django-command-extensions/wiki/RunProfileServer

Have fun profiling :)

P.S. Having fancy tools is never a replacement for learning and knowing about what code actually does and what profile data represents !

[1]The Python Dynamic/JIT compiler - http://psyco.sf.net/
[2]http://codespeak.net/pypy/dist/pypy/tool/lsprofcalltree.py
Add to:  

September 19, 2008

Tags: admin, django, tabbed, tabs

A while ago i was playing with the excellent pinax (django-hotclub) project and i felt like the admin index page was kind-of overwhelming due to all the different apps listed in it.

So i put a simple app together that has one template tag and a slight modification of the "admin/index.html" template to create simple tabs in the django admin interface.

To minimize my effort ;-) i used jquery and ui.tabs.js to create the tabs at runtime. With one mandatory tab called "main" (changeable in settings.py), which contains all apps not mapped to a specific tab, and an attribute in settings called "ADMIN_TABS" that maps different apps to different tabs.

It's still more-or-less a proof-of-concept applicatio, but it shows how easy these kinds of modifications can be in the django admin interface.

Screenshots

Mercurial repository

Afterthoughts:

I would like to extend this to something like shown in the Gondola screencast by Peter Baumgartner at a later time where a specific tab can also short-cut to common usage patterns.

Add to:  

September 13, 2008

Tags: books, django, japanese, python

Japanese Django book

When looking for English books in a bookstore i came across the programming section of the 8 story book store and i could not resist to take a look and see if i could find any Python or Django books there.

Look at my picture from what i've found here: http://trbs.net/photos/python-django-books-in-japanese/

Regretfully these where only about two bookshelves worth of Python books. Compare that too one full cabinet of Ruby and Rails books, one cabinet for Perl, a hole alley of Java books, an alley for c and c++ and lastly an alley for php/asp/vb/c# and other some other languages. *I'd even found some scheme, lisp and cobolt books in there :) *

Worthy to note was that the Microsoft languages section was far less in total then i'd expected. While on the other hand a relatively minor language like Ruby had far more. Ofcourse japan is the homeland of Ruby so that might explain it's high number of books ;) (On a site note; probably the only people that could have invented such a syntax horrible language are the Japanese. Of-course I'm purposely forgetting about Perl here)

Anyways i did not want to withhold u guys of these pictures, specially the one from the Django book that has a lovely cover, good layout and lots of examples, i even found a lot of debugging instructions and examples in there.

P.S. The pictures where taking with the build-in camera of the N810 so quality is very poor.

Add to:  

September 8, 2008

Tags: django, extensions

I recently added two new commands to the django-extensions project.

  • clean_pyc, removes all compiled python bytecode files from your project directory
  • compile_pyc, compiles all python files to bytecode files in your project directory

These are handy shortcuts to what you would normally do with something like "$ find -name "*.py[co]" -delete" or python's compileall import. The main added advantage is a little piece of code that checks the correct working directory. So it will only compile or delete files in your project root, even if you call manage.py from somewhere else.

One other thing to note is that you will always see files being deleted when you call "$ ./manage.py clean_pyc -v" this is because when manage.py gets loaded python will compile files in your project root which are then in turn deleted by the command ;-)

Check it out at: http://code.google.com/p/django-command-extensions/

Add to:  

September 5, 2008

Tags: django

Congratulations everybody Django 1.0 has landed

Thanks for all the hard work of the Django core team !!!

Add to: