Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

October 25 2010

October 22 2010

django-multilingual-model

A very simple abstract base class, enabling translation of (specific) model fields with only about 33 lines of code.

Example:

models.py

    from django.db import models
    from multiling import MultilingualModel
   
    class Language(models.Model):
        code = models.CharField(max_length=5)
        name = models.CharField(max_length=16)
       
    class BookTranslation(models.Model):
        language = models.ForeignKey("Language")
        title = models.CharField(max_length=32)
        description = models.TextField()
        model = models.ForeignKey("Book")
       
    class Book(MultilingualModel):
        ISBN = models.IntegerField()
       
        class Meta:
            translation = BookTranslation
            multilingual = ['title', 'description']
>>> lang_en = Language(code="en", name="English")
>>> lang_en.save()
>>> lang_pl = Language(code="pl", name="Polish")
>>> book = Book(ISBN="1234567890")
>>> book.save()
>>> book_en = BookTranslation()
>>> book_en.title = "Django for Dummies"
>>> book_en.description = "Django described in simple words."
>>> book_en.model = book
>>> book_en.save()
>>> book_pl = BookTranslation()
>>> book_pl.title = "Django dla Idiotow"
>>> book_pl.description = "Django opisane w prostych slowach"
>>> book_pl.model = book
>>> book_pl.save()
>>>
>>> # now here comes the magic
>>> book.title_en
u'Django for Dummies'
>>> book.description_pl
u'Django opisane w prostych slowach'

To have it interated with Django Admin nicely, try this:

admin.py

from django.contrib import admin
import models

class BookTranslationInline(admin.StackedInline):
   model = models.BookTranslation
   extra = 1
   min_num = 1


class BookAdmin(admin.ModelAdmin):
   list_display = ["ISBN"]
   inlines = [BookTranslationInline]

admin.site.register(models.Book, BookAdmin)

October 18 2010

django-mobile

django-mobile provides a simple way to detect mobile browsers and gives you tools at your hand to render some different templates to deliver a mobile version of your site to the user.


Hg-Git Mercurial Plugin

This is the Hg-Git plugin for Mercurial, adding the ability to push to and pull from a Git server repository from Mercurial. This means you can collaborate on Git based projects from Mercurial, or use a Git server as a collaboration point for a team with developers using both Git and Mercurial.

October 07 2010

X-Sendfile static file serve view

This view has the same functionality as Django's builtin static view function but when the configuration option USE_XSENDFILE = True is specified in the settings it returns the absolute path of the file instead of its contents.

This allows the mod_xsendfile module in Apache or Lighttpd to take care of ...

X-Sendfile static file serve view

This view has the same functionality as Django's builtin static view function but when the configuration option USE_XSENDFILE = True is specified in the settings it returns the absolute path of the file instead of its contents.

This allows the mod_xsendfile module in Apache or Lighttpd to take care of ...

X-Sendfile static file serve view

This view has the same functionality as Django's builtin static view function but when the configuration option USE_XSENDFILE = True is specified in the settings it returns the absolute path of the file instead of its contents.

This allows the mod_xsendfile module in Apache or Lighttpd to take care of ...

September 30 2010

django-fileprocessor: efficient, scalable processing of files (ie. scaling images)

This is a prototype project for something we have been wanting to make: efficient file processing - from within templates!

Right now, if you are like me, you probably use something like easy_thumbnail for scaling of images for your website. You might even have written some code to extract thumbnails from PDF files or from video files. All really great work!

BUT. As our applications relying on this stuff might actually scale up a bit, the amount of work our application servers are doing WHILE RENDERING THE TEMPLATE can quickly become excessive. At the same time, if these servers were just doing what they should be, namely data <-> view interactions, this would not be happening.

Moreover: if your server is, in principle, able to handle a mentioning on some lame but immensely popular blog - why should it not be in practice? Because, right now - if you use easy_thumbnails - your server will block while rendering templates until your thumbnails are gone.

So here is my concept solution: When we need to do something with a file, while rendering a template, we first put out a request. This request can be put out to some other server, but for small instances it can easily be the same server - just some other CPU doing the work. This 'remote tag' basically passes any contents between the {% fileprocessor %} and {% endfileprocessor %} along to this other server as a parameter (so far called instructions), telling it what to do and where to get stuff from.

The remote server writes this to the database, generates a checksum thereof and parses the instructions just well enough to generate some kind of representation (ie. and image tag) of the stuff that will be rendered later.

After the HTML has been sent out to the client, the client will start making individual requests for the URL's referred to in the representation code generate while rendering the template. Calling these URL's directly triggers processing the file in any possible way, according to the instructions in the database. When this is done, the file is written to some kind of storage, somewhere and a redirect to this file is generated.

On subsequent requests, all the 'file processing server' does is blurt out redirects to that some old file. But as these are permanent redirects, they should also be cached by the client which ought to be quite efficient. Furthermore, the template rendering results can and should also be cached: we do not have to reach out to the server all of the time to retreive the same kind of data.

So that's it. A work in progress. Feel free to join in. :)

September 26 2010

django-newsletter released in the Cheese Shop

After a long time of though work we have finally released this app for managing multiple mass-mailing lists with both plaintext as well as HTML templates (and TinyMCE editor for HTML messages), images and a smart queueing system all right from the admin interface. And what's more: it's all fully integrated into the Django admin.

Stay tuned for some screenshots - or perhaps even a screencast of our (Dutch) presentation of the project this wednesday at the Django Meeting in Amsterdam.

Reposted bydokterbob dokterbob

September 16 2010

Improved many-page pagination

This one was adapted from Page numbers with ... like in Digg. See that one for more reference.

Digg-like page numbering using inclusion tag.

Usage in template:

{% load pagination %} {% pagination yourpage %}

Inclusion template pagination.html:

{% if page.has_previous %}
    <a href="?page={{ page.previous_page_number }}"><img src="{{ MEDIA_URL }}images/page/cyclenav_l.png" alt ...

Improved many-page pagination

This one was adapted from Page numbers with ... like in Digg. See that one for more reference.

Digg-like page numbering using inclusion tag.

Usage in template:

{% load pagination %} {% pagination yourpage %}

Inclusion template pagination.html:

{% if page.has_previous %}
    <a href="?page={{ page.previous_page_number }}"><img src="{{ MEDIA_URL }}images/page/cyclenav_l.png" alt ...

Improved many-page pagination

This one was adapted from Page numbers with ... like in Digg. See that one for more reference.

Digg-like page numbering using inclusion tag.

Usage in template:

{% load pagination %} {% pagination yourpage %}

Inclusion template pagination.html:

{% if page.has_previous %}
    <a href="?page={{ page.previous_page_number }}"><img src="{{ MEDIA_URL }}images/page/cyclenav_l.png" alt ...

July 11 2010

8930 e44e 500

July 06 2010

LESS

Less extends CSS with: variables, mixins, operations and nested rules.

May 29 2010

April 13 2010

Introduction to Surlex

Surlex (Simple URL Expression) is a language for matching and extracting text, similar to regex (regular expression). It works by generating a regular expression from a more concise syntax that is designed to produce easy-to-read url patterns.

February 02 2010

django-google-analytics - Project Hosting on Google Code

A simple django application that eases Google Analytics integration with your Django projects by sapegin
Reposted fromdjangofeeds djangofeeds

November 17 2009

ExtendibleModelAdminMixin

A generic base class for extending ModelAdmin views. This can be used likewise:

def myview(self, request, object_id):
    obj = self._getobj(request, object_id)
    < do something >

def get_urls(self):
    urls = super(MyAdmin, self).get_urls()

    my_urls = patterns('',
        url(r'^(.+)/myview/$', 
            self._wrap(self.myview), 
            name=self._view_name('myview')),
        )

    return my_urls + urls

ExtendibleModelAdminMixin

A generic base class for extending ModelAdmin views. This can be used likewise:

def myview(self, request, object_id):
    obj = self._getobj(request, object_id)
    < do something >

def get_urls(self):
    urls = super(MyAdmin, self).get_urls()

    my_urls = patterns('',
        url(r'^(.+)/myview/$', 
            self._wrap(self.myview), 
            name=self._view_name('myview')),
        )

    return my_urls + urls
Older posts are this way If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.

Don't be the product, buy the product!

Schweinderl