def before_analyze(self): super(Plugin, self).before_analyze() from lino_xl.lib.countries.mixins import AddressLocation from lino.core.utils import models_by_base if self.hide_region: for m in models_by_base(AddressLocation): m.hide_elements('region')
def on_analyze(cls, site): super(Polymorphic, cls).on_analyze(site) if cls._mtinav_models is None: models = list(models_by_base(cls)) # TODO: it would be nice to have them sorted in some # understandable way, but that's not trivial. First # attempts are not satisfying: # # def f(a, b): # level = 0 # if b in a.__bases__: # level -= a.__bases__.index(b) # if a in b.__bases__: # level += b.__bases__.index(a) # return level # models.sort(f) cls._mtinav_models = tuple(models) def add(m, cl): a = cl(m) cls.define_action(**{a.get_action_name(): a}) for m in cls._mtinav_models: add(m, DeleteChild) add(m, InsertChild)
def on_analyze(cls, site): """ Add workflow actions to the models which use this workflow so that we can access them as InstanceActions. """ super(Workflow, cls).on_analyze(site) if cls.abstract: return # logger.info("20150602 Workflow.on_analyze %s", cls) used_on_models = [] for fld in cls._fields: model = getattr(fld, 'model', None) if model: used_on_models.append(model) # logger.info("20150602 %s, %s", model, cls.workflow_actions) for a in cls.workflow_actions: # if not a.action_name.startswith('wf'): if not hasattr(model, a.action_name): setattr(model, a.action_name, a) if cls.verbose_name_plural is None: if len(used_on_models) == 1: concrete_models = list(models_by_base(used_on_models[0])) if len(concrete_models) == 1: m = concrete_models[0] else: m = used_on_models[0] name = m._meta.verbose_name cls.verbose_name_plural = format_lazy(_("{} states"), name) # elif len(used_on_models) > 1: # raise Exception( # "20190103 {} is used in more than one model : {}".format( # cls, used_on_models)) else: cls.verbose_name_plural = _("States") cls.sort()
def get_dashboard_items(self, user): from lino.core.utils import models_by_base from .mixins import Publishable for m in models_by_base(Publishable): if m.publisher_location is not None: for obj in m.get_dashboard_objects(user): yield PublisherDashboardItem(obj)
def get_dashboard_items(self, user): # print("20210112 get_dashboard_items") from lino.core.utils import models_by_base from .mixins import Publishable for m in models_by_base(Publishable): # print("20210112 ", m, m.publisher_location) yield PublisherDashboardItem(m)
def on_site_startup(self, kernel): from lino_xl.lib.beid.mixins import BeIdCardHolder from lino.core.utils import models_by_base super(Plugin, self).on_site_startup(kernel) if self.data_cache_dir is None: self.data_cache_dir = self.site.cache_dir.child('media').child('cache').child('beid') # self.data_cache_dir = join( # self.site.cache_dir, 'media', 'beidtmp') self.site.makedirs_if_missing(self.data_cache_dir) cmc = list(models_by_base(BeIdCardHolder, toplevel_only=True)) if len(cmc) > 1: msg = "There must be exactly one BeIdCardHolder model " \ "in your Site! You have {}. ".format(cmc) raise Exception(msg) if len(cmc) == 0: self.site.logger.warning( "You have lino_xl.lib.beid installed, " "but there is no implementation of BeIdCardHolder.") return self.holder_model = cmc[0] if self.urlhandler_prefix is not None: if not self.urlhandler_prefix.endswith("://"): msg = "Invalid urlhandler_prefix {} (must end with '://')" raise Exception(msg.format(self.urlhandler_prefix)) return
def on_site_startup(self, kernel): from lino_xl.lib.beid.mixins import BeIdCardHolder from lino.core.utils import models_by_base super(Plugin, self).on_site_startup(kernel) cmc = list(models_by_base(BeIdCardHolder, toplevel_only=True)) if len(cmc) == 1: self.holder_model = cmc[0] return if len(cmc) == 0: self.site.logger.warning( "You have lino_xl.lib.beid installed, " "but there is no implementation of BeIdCardHolder.") return msg = "There must be exactly one BeIdCardHolder model " \ "in your Site! You have {}. ".format(cmc) # from django.apps import apps # msg += "\nYour models are:\n {}".format( # '\n'.join([str(m) for m in apps.get_models()])) # from django.conf import settings # msg += "\nYour plugins are:\n {}".format(settings.INSTALLED_APPS) # [p.app_label # for p in self.site.installed_plugins])) raise Exception(msg)
def on_site_startup(self, kernel): from lino_xl.lib.beid.mixins import BeIdCardHolder from lino.core.utils import models_by_base super(Plugin, self).on_site_startup(kernel) if self.data_cache_dir is None: self.data_cache_dir = self.site.cache_dir.child('media').child( 'cache').child('beid') # self.data_cache_dir = join( # self.site.cache_dir, 'media', 'beidtmp') self.site.makedirs_if_missing(self.data_cache_dir) cmc = list(models_by_base(BeIdCardHolder, toplevel_only=True)) if len(cmc) > 1: msg = "There must be exactly one BeIdCardHolder model " \ "in your Site! You have {}. ".format(cmc) raise Exception(msg) if len(cmc) == 0: self.site.logger.warning( "You have lino_xl.lib.beid installed, " "but there is no implementation of BeIdCardHolder.") return self.holder_model = cmc[0] if self.urlhandler_prefix is not None: if not self.urlhandler_prefix.endswith("://"): msg = "Invalid urlhandler_prefix {} (must end with '://')" raise Exception(msg.format(self.urlhandler_prefix)) if self.simulate_eidreader_path is not None: self.SIMULATION_FILES = Cycler( self.simulate_eidreader_path.listdir()) return
def on_site_startup(self, kernel): from lino_xl.lib.beid.mixins import BeIdCardHolder from lino.core.utils import models_by_base super(Plugin, self).on_site_startup(kernel) if self.data_cache_dir is None: self.data_cache_dir = self.site.cache_dir.child('media').child('cache').child('beid') # self.data_cache_dir = join( # self.site.cache_dir, 'media', 'beidtmp') self.site.makedirs_if_missing(self.data_cache_dir) cmc = list(models_by_base(BeIdCardHolder, toplevel_only=True)) if len(cmc) == 1: self.holder_model = cmc[0] return if len(cmc) == 0: self.site.logger.warning( "You have lino_xl.lib.beid installed, " "but there is no implementation of BeIdCardHolder.") return msg = "There must be exactly one BeIdCardHolder model " \ "in your Site! You have {}. ".format(cmc) # from django.apps import apps # msg += "\nYour models are:\n {}".format( # '\n'.join([str(m) for m in apps.get_models()])) # from django.conf import settings # msg += "\nYour plugins are:\n {}".format(settings.INSTALLED_APPS) # [p.app_label # for p in self.site.installed_plugins])) raise Exception(msg)
def get_patterns(self): from django.conf.urls import url from lino.core.utils import models_by_base from . import views from .mixins import Publishable for m in models_by_base(Publishable): if m.publisher_location is not None: yield url('^{}/(?P<pk>.+)$'.format(m.publisher_location), views.Element.as_view(publisher_model=m)) yield url('^{}/$'.format(m.publisher_location), views.Element.as_view(publisher_model=m))
def on_site_startup(self, site): super(Plugin, self).on_site_startup(site) from lino.core.utils import models_by_base if len(list(models_by_base(site.models.system.Lockable))): def welcome_messages(ar): def fmt(model, pk): try: obj = model.objects.get(pk=pk) except model.DoesNotExist: return "{}{}".format(model.__name__, pk) return ar.obj2html(obj) up = ar.get_user().get_preferences() if len(up.locked_rows): chunks = [ ugettext("You have a dangling edit lock on"), " "] chunks += join_elems( [fmt(m, pk) for m, pk in up.locked_rows], ", ") chunks.append('.') yield E.span(*chunks) site.add_welcome_handler(welcome_messages)
def on_site_startup(self, site): super(Plugin, self).on_site_startup(site) from lino.core.utils import models_by_base if len(list(models_by_base(site.models.system.Lockable))): def welcome_messages(ar): def fmt(model, pk): try: obj = model.objects.get(pk=pk) except model.DoesNotExist: return "{}{}".format(model.__name__, pk) return ar.obj2html(obj) up = ar.get_user().get_preferences() if len(up.locked_rows): chunks = [ ugettext("You have a dangling edit lock on"), " " ] chunks += join_elems( [fmt(m, pk) for m, pk in up.locked_rows], ", ") chunks.append('.') yield E.span(*chunks) site.add_welcome_handler(welcome_messages)
def get_lockables(): return models_by_base(Lockable)