Coverage for lino/modlib/plausibility/choicelists.py : 50%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright 2015 Luc Saffre # License: BSD (see file COPYING for details)
Choicelists for `lino.modlib.plausibility`.
.. autosummary::
"""
class Feedbacks(dd.ChoiceList): verbose_name = _("Plausibility feedback") verbose_name_plural = _("Plausibility feedback")
add = Feedbacks.add_item() add("10", _("Ignorable"), 'ignorable') add("20", _("Serious"), 'serious')
class Severities(dd.ChoiceList): verbose_name = _("Severity") verbose_name_plural = _("Plausibility problem severities")
add = Severities.add_item() add("10", _("Note"), 'note') add("20", _("Warning"), 'warning') add("30", _("Error"), 'error')
"""Base class for the choices of :class:`Checkers`.
"""
# if isinstance(self.model, basestring): # value = self.model + '.' + self.__class__.__name__ # else: # value = self.model.__name__ + '.' + self.__class__.__name__ text = value else:
def activate(cls): """Application developers must call this on their subclass in order to "register" or "activate" it.
This actually just creates an instance and adds it as a choice to the :class:`Checkers` choicelist.
"""
"""Update the problems of this checker and the specified object.
When `delete` is False, the caller is responsible for deleting any existing objects.
""" Problem = rt.modules.plausibility.Problem if delete: gfk = Problem.owner qs = Problem.objects.filter(**gfk2lookup(gfk, obj, checker=self)) qs.delete()
done = [] todo = [] for fixable, msg in self.get_plausibility_problems(obj, fix): if fixable: msg = u"(\u2605) " + str(msg) if fixable and fix: done.append(msg) else: todo.append(msg) if len(todo): user = self.get_responsible_user(obj) if user is None: lang = dd.get_default_language() else: lang = user.language with translation.override(lang): msg = '\n'.join([str(s) for s in todo]) prb = Problem(owner=obj, message=msg, checker=self, user=user) prb.full_clean() prb.save() return (todo, done)
"""Return or yield a series of `(fixable, message)` tuples, each describing a plausibility problem. `fixable` is a boolean saying whther this problem can be automatically fixed. And if `fix` is `True`, this method is also responsible for fixing it.
""" return []
"""The :attr:`user <lino.modlib.plausibility.models.Problem.user>` to be considered as reponsible for problems detected by this checker on the given database object `obj`.
The given `obj` will always be an instance of :attr:`model`.
The default implementation returns the *main plausibility responsible* defined for this site (see :attr:`responsible_user <lino.modlib.plausibility.Plugin.responsible_user>`).
""" return dd.plugins.plausibility.get_responsible_user(self, obj)
"""The list of plausibility problem types known by this application.
This was the first use case of a :class:`ChoiceList <lino.core.choicelists.ChoiceList>` with a :attr:`detail_layout <lino.core.actors.Actor.detail_layout>`.
""" # e.g. "lino_welfare.modlib.pcsw.models.ClientCoachingsChecker"
value name text plausibility.ProblemsByChecker """
def resolve_checkers(sender, **kw): |