20150331 (Tuesday, 31 March 2015)

A calendar navigator for my blog

I spent two hours with optimizing atelier.sphinxconf.blog. My blog now features an automatic calendar navigator. I just wanted to move the old years to a less visible place without loosing them from the global toctree. This blogging system contains blog entries since 2009 (though the first years were originally written in other formats and are not yet fully converted)

Repairing data using a script

Yesterday we decided to write and run a rather simple but critical batch operation in a production database.

Here is the script shortly before I actually ran it:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
from lino.api.shell import *
from clint.textui import puts, prompt, progress
from lino.core.utils import PseudoRequest
from lino.core.diff import ChangeWatcher

# rt.show(pcsw.ClientStates)
# rt.show(changes.Changes)

former = pcsw.ClientStates.former
# refused = pcsw.ClientStates.refused

qs = pcsw.Coaching.objects.filter(
    client__client_state=former, end_date__isnull=True)
# qs = pcsw.Coaching.objects.filter(client__client_state=former)

puts("{0} unbeendete Begleitungen ehemaliger Klienten".format(qs.count()))

clients = dict()
for o in progress.dots(qs):
    lst = clients.setdefault(o.client.id, [])
    lst.append(o)

puts("{0} Klienten".format(len(clients)))
puts("Davon Klienten mit mehr als einer Begleitung:")
for lst in clients.values():
    if len(lst) != 1:
        print("- {0} : {1}".format(lst[0].client, [o.user for o in lst]))

ok = prompt.query("Ready to go?", default="n")

if ok.upper() == "Y":

    REQUEST = PseudoRequest("robin")

    for obj in progress.dots(qs):
        cw = ChangeWatcher(obj)
        obj.end_date = obj.client.modified.date()
        obj.full_clean()
        obj.save()
        cw.send_update(REQUEST)

# rt.show(changes.Changes)

I discovered that the puts of clint does not like unicode strings. What a pity! I also saw that they know it.

I wrote documentation for PseudoRequest and moved it from lino.api.dd to lino.core.utils.

Miscellaneous

I updated some parts of the Lino documentation.

About plugin inheritance

The new module lino_welfare.modlib.countries is because I converted the usage of set_detail_layout and of the magic site_setup function which were in lino_welfare.models.

My plan is to declare this usage pattern as deprecated, but the topic needs more investigation and documentation.

I also tried to solve the problem that a plugin, when it inherits from an existing plugin, must create a wrapper for everything in its parent’s fixtures and config directories. That problem is described in /dev/plugin_inheritance. My idea was to add fixtures directories of parent plugins to Django’s FIXTURE_DIR setting. I even got this wo work, but then discovered that it is useless because it changes the order in which the fixtures are being loaded: Django’s loaddata command first loads all fixtures of INSTALLED_APPS, and only then those from FIXTURE_DIR. No, I think we must continue to live with these fixture wrappers.