2010-08-23

compiling .po messages from Django

djangoninja:

to enable that, set LOCALE_PATH in your settings pointing to directory containing locales, e.g.

import os SITE_ROOT = os.path.dirname(os.path.abspath(__file__)) LOCALE_PATHS = ( os.path.join(SITE_ROOT, 'locale') )

2010-08-04

Créer une table des matières avec django

À nettoyer, modifier, améliorer… Emprunté au snippet MediaWikiMarkup

Usage :

{{ object.html_text|createToc }}

Code :

```

-- coding: utf-8 --

from django.template import Library import re from django.template.defaultfilters import slugify, striptags

register = Library()

_headerPat = re.compile(ur"<Hh(.?)>(.?)", re.UNICODE) _tagPat = re.compile(ur"<.*?>", re.UNICODE)

def createToc(text, extractToc=None, noToc=None):

# Get all headlines for numbering them and adding funky stuff like [edit]
# links - this is for later, but we need the number of headlines right now
matches = _headerPat.findall(text)
numMatches = len(matches)


# if there are fewer than 4 headlines in the article, do not show TOC
# unless it's been explicitly enabled.
enoughToc = (numMatches >= 3)

# headline counter
headlineCount = 0

# Ugh .. the TOC should have neat indentation levels which can be
# passed to the skin functions. These are determined here
toc = []
head = {}
sublevelCount = {}
levelCount = {}
toclevel = 0
level = 0
prevlevel = 0
toclevel = 0
prevtoclevel = 0
refers = {}
refcount = {}
wgMaxTocLevel = 5

for match in matches:
    headline = match[2]

    if toclevel:
        prevlevel = level
        prevtoclevel = toclevel

    level = matches[headlineCount][0]

    if enoughToc:
        if level > prevlevel:
            toclevel += 1
            sublevelCount[toclevel] = 0
            if toclevel < wgMaxTocLevel:
                toc.append(u'\n<ul class="toc">')
        elif level < prevlevel and toclevel > 1:
            # Decrease TOC level, find level to jump to

            if toclevel == 2 and level < levelCount[1]:
                toclevel = 1
            else:
                for i in range(toclevel, 0, -1):
                    if levelCount[i] == level:
                        # Found last matching level
                        toclevel = i
                        break
                    elif levelCount[i] < level:
                        toclevel = i + 1
                        break
            if toclevel < wgMaxTocLevel:
                toc.append(u"</li>\n")
                toc.append(u"</ul>\n</li>\n" * max(prevtoclevel - toclevel, 0))
        else:
            if toclevel < wgMaxTocLevel:
                toc.append(u"</li>\n")

        levelCount[toclevel] = level

        # count number of headlines for each level
        sublevelCount[toclevel] += 1

    # The canonized header is a version of the header text safe to use for links
    canonized_headline = slugify(headline)


    # strip out HTML
    tocline =  striptags(headline)

    # Save headline for section edit hint before it's escaped
    headline_hint = tocline
    canonized_headline = slugify(tocline)
    refers[headlineCount] = canonized_headline

    # count how many in assoc. array so we can track dupes in anchors
    if canonized_headline not in refers:
        refers[canonized_headline] = 1
    else:
        refers[canonized_headline] += 1
    refcount[headlineCount] = refers[canonized_headline]

    # Create the anchor for linking from the TOC to the section
    anchor = canonized_headline;
    if refcount[headlineCount] > 1:
        anchor += u'_' + unicode(refcount[headlineCount])

    if enoughToc:
        toc.append(u'\n<li class="toclevel-')
        toc.append(unicode(toclevel))
        toc.append(u'"><a href="#')
        toc.append(anchor)
        toc.append(u'">')
        toc.append(u'<span class="toctext">')
        toc.append(tocline)
        toc.append(u'</span></a>')

    # give headline the correct <h#> tag
    if headlineCount not in head:
        head[headlineCount] = []
    h = head[headlineCount]
    h.append(u'<h')
    h.append(unicode(level))
    h.append(u' id="')
    h.append(anchor)
    h.append('">')
    h.append(matches[headlineCount][1].strip())
    h.append(headline.strip())
    h.append(u'</h')
    h.append(unicode(level))
    h.append(u'>')

    headlineCount += 1

if enoughToc:
    if toclevel < wgMaxTocLevel:
        toc.append(u"</li>\n")
        toc.append(u"</ul>\n</li>\n" * max(0, toclevel - 1))
    #toc.insert(0, u'<table id="toc" class="toc" summary="Contents"><tr><td><div id="toctitle"><h2>Contents</h2></div>')
    toc.append(u'</ul>\n')

# split up and insert constructed headlines

if extractToc is not None:
    full = []
    if enoughToc :
        full += toc
    full = u''.join(full)
    return full
else:
    blocks = _headerPat.split(text)

    i = 0
    len_blocks = len(blocks)

    full = []
    while i < len_blocks:
        j = i/4
        full.append(blocks[i])
        if enoughToc and not i :
            if noToc is not None :
                full += toc
            toc = None
        if j in head and head[j]:
            full += head[j]
            head[j] = None
        i += 4
    full = u''.join(full)
    return full

"""
return text
"""

register.filter(createToc)

```

2010-07-21

Shell screen

screen -S starts a new screen instance
screen -ls list running screen instances
screen -r attach to a specific screen instance
^a " list available windows
^a c create a new window and switch to it
^a n switch to the next window
^a p switch to the previous window
^a A rename the current window
^a d detach screen from the current terminal (programs will continue to run)
^a D Power detach and logout
^a ? help; show key bindings
^a k Kill the current window

2010-07-15

2010-07-15

The most interesting trend in the development of the Internet is not how it is changing people’s ways of thinking but how it is adapting to the way that people think

Steven Pinker, but does it float

2010-07-12

Internet est la rencontre, la convergence, sinon la collision brutale, entre une longue et lente évolution technologique, des protocoles informatiques extrêmement arides et des usages humains

exomakina.fr

2010-07-08

The goal of design is to efficiently solve problems. Design is based on the understanding of how user see the world, how they think and behave. And the toolset of the designer is broader than just colors and font-styles, as it also includes user-research, prototyping, usability testing, and more.

UX Myths

2010-07-07

Django and Python embedded in a tumblblog

Floating is quite hard

2010-07-05

Python-tumblr issue

python-tumblr has an issue with posting to a secondary tumblblog. abiomkhar suggested a simple patch : http://code.google.com/p/python-tumblr/issues/detail?id=4. If you read this, it just means that it works perfectly. As I’m posting this from my django admin.

2010-06-06

This is everything we asked for but not what we wanted.

— (via clientsfromhell) (via nautilebleu)

2010-05-28

Django forums

SCT (Sphene Community Tools) is a collection of Django applications that are designed to be easily pluggable into any Django project. It currently consists of a Wiki and an extensible Forum application. Features for the forum include rendering of BBCode or markdown (with a pluggable rendering architecture), hierarchical forum categories, granular permissions, new posts-notifications and many more. It is extensible through ‘Category Types’ and includes a LinkList and Blog application to demonstrate it’s use.

vs

DjangoBB is a quick and simple forum which uses the Django Framework (written in Python language). Abbreviation DjangoBB stands for Django Bulletin Board. DjangoBB is distributed under the BSD license.

Any other ?