Thursday, December 17, 2015¶
About configuring plugin attributes¶
I was wondering why the following code does not have the expected
result (of setting
import datetime from lino_cosi.projects.apc.settings import * class Site(Site): ... SITE = Site(globals()) SITE.plugins.ledger.configure(start_year=2014)
while this code worked:
import datetime from lino_cosi.projects.apc.settings import * class Site(Site): ... def setup_plugins(self): super(Site, self).setup_plugins() self.plugins.ledger.configure(start_year=2014) SITE = Site(globals())
The explanation was not that the settings module would be getting imported twice (Ned Batchelder complained about this in 2011, django-extensions had an issue with it in August 2015, blueyed on pytest reported an issue in Januay 2015).
The explanation was that
Site a second time. It did:
from .demo import * class Site(Site): verbose_name = Site.verbose_name + " (:memory:)" SITE = Site(globals()) DATABASES['default']['NAME'] = ':memory:'
There are a few things to learn here:
we can indeed never guarantee that our
SITEinstance is actually being used. A solcal system admin can always decide to import our
settings.pymodule and the reinstantiate our Site class. That’s part of our game with
lino.core.site.Siteand should not be forbidden.
lino_cosi.projects.apc.settings.memory(and a first series of similar files) so that it no longer reinstantiates the
SITE. Because that’s not necessary. A typical memory.py module in a settings package should have this content:
from .demo import * SITE.verbose_name = SITE.verbose_name + " (:memory:)" DATABASES['default']['NAME'] = ':memory:'
A simple sales workflow with payment¶
There was still a bug in a tricky part: the
part is tricky and hackerish because we need to re-create the volatile
for each selected row.
TODO: unregistering a BankStatement which had cleared an invoice does not yet restore the correct satisfied for the (now again unsatisfied) invoice.