October 2007 archive

23
Oct

Letras Gordas

De tempos em tempos lá sai mais uma alta tecnologia do super laboratório da garagem lá de casa.

É uma página que permite passar os olhos pelos títulos de um conjunto de blogs e jornais. Olhar para as letras gordas na web.

Usa o conceito do popurls e acrescenta a possibilidade de escolher os blogs e sites (neste momento apenas de uma lista pré-definida), e a capacidade de usar o máximo do espaço do ecrã para mostrar informação.

Eu uso esta ferramenta como complemento ao meu leitor de RSS, para de vez em quando passar os olhos pelos blogs e media mais populares (e que, por terem tantos artigos, não quero acompanhar no meu leitor).

É biodegradável e energeticamente eficiente :-)

13
Oct

Touareg Scuba Ad

Best car ad. Ever.

VW Tuareg Scuba Ad
07
Oct

As Espanhas

A Espanha está cada vez mais dividida. No mês passado vi a notícia do país basco a tentar fazer um referendo para ser tornar independente. Hoje reparei que a Catalunha já tem um domínio de topo na internet, o .cat. E pelos vistos a Galiza está na lista de espera para ter o seu domínio de topo, o .gal (e depois alguém vai registar o portu.gal :-).

E eu acho bem. A verdadeira liberdade de uma população é poder rejeitar a própria organização que lhe dá a liberdade. Mas ainda estou para ver se Madrid vai deixar.

05
Oct

Including variables as templates

To manage the website content in a flexible way it's practical to have some portions of some pages generated from variables created as FlatPages. For example, in a frontpage I have a "featured item" section which renders a flatpage variable.

def frontpage(request):
    fp = FlatPage.objects.get(url='featured')
    return render_to_response('frontpage.html', {'fp':fp })
then in the template
...<div id="featured">{{ fp.content }}</div> ...

But sometimes it would also be nice to put some template tags inside those flatpages. Django does not seem to provide a tag for such task (most probably because it can be a bad idea from the security point of view), but the ssi tag does exactly the same thing for files in the filesystem. Based on ssi, the code bellow defines a new tag that includes the content of a variable as a template.

def do_templatevar(parser, token):
    bits = token.contents.split()
    if len(bits) != 2:
        raise TemplateSyntaxError, "%s tag takes one argument" % bits[0]
    return TemplateVarNode(parser.compile_filter(bits[1]))

register.tag('templatevar', do_templatevar)

class TemplateVarNode(Node):
    def __init__(self, content):
        self.content = content

    def render(self, context):
        content = self.content.resolve(context)
        try:
            t = Template(content)
            return t.render(context)
        except TemplateSyntaxError, e:
            if settings.DEBUG:
                return "[Included template had syntax error: %s]" % e
            else:
                return '' # Fail silently

Now I can put the following code in my flat page

<p>This is my media_url: {{ MEDIA_URL }}</p>

And it will work if I define my template as

...<div id="featured">{% templatevar fp.content %}</div> ...

A last remark to mention databasetemplateloader that allows to load template data from the database. I never tried it, but seems to be a more generic solution (and also a way to have a Zope 1 experience in Django).

01
Oct

OpenID blog claim in technorati

This is probably old news but the openid blog claim in technorati is definitely a very good idea. If your blog is also your openid, when doing the blog claim in technorati you are given the chance to do the claim using openid.

With this option you just have to authenticate in your openid provider and ... it's done!

Just by having these two lines in my blog header allowed technorati to give me an easy authentication process.

<link rel="openid.server" href="http://www.myopenid.com/server">
<link rel="openid.delegate" href="http://pedrolima.myopenid.com/">

I was happily surprised with this process. Simple and easy.