How to use the lino.api.dd.resolve_app function in lino

To help you get started, we’ve selected a few lino examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lino-framework / lino / lino / modlib / countries / fixtures / be.py View on Github external
def objects():
    countries = dd.resolve_app('countries')
    city = Instantiator(countries.Place, "zip_code name",
                        country='BE',
                        type=countries.PlaceTypes.city).build
    for ln in belgian_cities.splitlines():
        ln = ln.strip()
        if ln and ln[0] != '#':
            args = ln.split(None, 1)
            o = city(*args)
            # print "%r %r" % (o.zip_code, o.name)
            yield o
            #~ print __name__, "20121114"
            #~ return
    for ln in belgian_cities_nl_fr.splitlines():
        ln = ln.strip()
        if ln and ln[0] != '#':
            args = ln.split('|')
github lino-framework / lino / lino / modlib / outbox / models.py View on Github external
#~ else:
            #~ body = elem.owner.get_mailable_body(rr)
        text_content = html2text(elem.body)
        msg = EmailMultiAlternatives(subject=elem.subject,
                                     from_email=sender,
                                     body=text_content,
                                     to=to, bcc=bcc, cc=cc)
        msg.attach_alternative(elem.body, "text/html")
        for att in elem.attachment_set.all():
            #~ if as_attachment or att.owner != elem.owner:
            fn = att.owner.get_target_name()
            if fn is None:
                raise Warning(_("Couldn't find target file of %s") % att.owner)
            msg.attach_file(fn)

        uploads = dd.resolve_app("uploads")
        for up in uploads.UploadsByController.request(elem):
        #~ for up in uploads.Upload.objects.filter(owner=elem):
            fn = os.path.join(settings.MEDIA_ROOT, up.file.name)
            msg.attach_file(fn)

        num_sent = msg.send()

        elem.sent = timezone.now()
        kw.update(refresh=True)
        #~ msg = "Email %s from %s has been sent to %s." % (
            #~ elem.id,elem.sender,', '.join([
                #~ r.address for r in elem.recipient_set.all()]))
        msg = _("Email %(id)s from %(sender)s has been sent to %(num)d recipients.") % dict(
            id=elem.id, sender=sender, num=num_sent)
        kw.update(message=msg, alert=True)
        #~ for n in """EMAIL_HOST SERVER_EMAIL EMAIL_USE_TLS EMAIL_BACKEND""".split():
github lino-framework / lino / lino / modlib / orders / models.py View on Github external
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _

from lino.api import dd, rt

#~ from lino import reports
from lino.core import actions
from lino import mixins
from lino.utils import mti
#~ from lino.utils.quantities import Duration


contacts = dd.resolve_app('contacts')
accounts = dd.resolve_app('accounts')
ledger = dd.resolve_app('ledger')
vat = dd.resolve_app('vat')
products = dd.resolve_app('products')
sales = dd.resolve_app('sales')


class OrderStates(dd.Workflow):
    pass
add = OrderStates.add_item
add('10', _("Draft"), 'draft', editable=True)
add('20', _("Registered"), 'registered', editable=False)
add('30', _("Inactive"), 'inactive', editable=False)


@dd.receiver(dd.pre_analyze)
def setup_workflow(sender=None, **kw):
    OrderStates.registered.add_transition(_("Register"), states='draft')
    OrderStates.draft.add_transition(_("Deregister"), states="registered")
github lino-framework / lino / docs / blog / 2012 / 0914b.py View on Github external
from lino.api import dd, rt
pcsw = dd.resolve_app('pcsw')
users = dd.resolve_app('users')
alicia = users.User.objects.get(username='alicia')
root = users.User.objects.get(username='root')
pg = pcsw.PersonGroup.objects.get(pk=1)

ar = pcsw.CoachingsByUser.request(master_instance=alicia)
print ar.to_rst()
print "%d rows" % ar.get_total_count()

ar = pcsw.MyClientsByGroup.request(
    user=root,subst_user=alicia,
    master_instance=pg)
print ar.to_rst('name_column national_id address_column')
print "%d rows" % ar.get_total_count()
github lino-framework / lino / lino / projects / belref / models.py View on Github external
# -*- coding: UTF-8 -*-
# Copyright 2013-2016 Luc Saffre
# License: BSD (see file COPYING for details)

"""
The :xfile:`models` module for :mod:`lino.projects.belref`.

"""

from lino.api import dd

concepts = dd.resolve_app('concepts')


class Main(concepts.TopLevelConcepts):
    pass


@dd.receiver(dd.post_analyze)
def my_details(sender, **kw):
    site = sender

    lst = (site.modules.countries.Places,
           site.modules.countries.Countries,
           site.modules.concepts.Concepts)
    for t in lst:
        t.required_roles.discard(dd.SiteUser)
        t.required_roles.discard(dd.SiteStaff)
github lino-framework / lino / lino / modlib / declarations / models.py View on Github external
import logging
logger = logging.getLogger(__name__)

from decimal import Decimal

from django.db import models
from django.conf import settings

from lino.api import dd
from django.utils.translation import ugettext_lazy as _

partner_model = settings.SITE.partners_app_label + '.Partner'

vat = dd.resolve_app('vat')
ledger = dd.resolve_app('ledger')


ZERO = Decimal()


# class DeclarationStates(dd.Workflow):
#     pass
# add = DeclarationStates.add_item
# add("00", _("Draft"), "draft", editable=True)
# add("10", _("Registered"), "registered", editable=False)
# add("20", _("Submitted"), "submitted", editable=False)

# DeclarationStates.registered.add_transition(
#     _("Register"), states='draft submitted')
# DeclarationStates.draft.add_transition(_("Deregister"), states="registered")
# DeclarationStates.submitted.add_transition(_("Submit"), states="registered")
github lino-framework / lino / lino / modlib / countries / fixtures / eesti.py View on Github external
"""This fixture imports all Estonian places from :mod:`commondata.ee`
(which needs to be installed before loading this fixture).

"""

import logging
logger = logging.getLogger(__name__)

from commondata.ee.places import root

from commondata.ee.places import (Village, SmallBorough, Borough,
                                  Township, Town, Municipality, County)

from lino.api import dd

countries = dd.resolve_app('countries')


def cd2type(p):
    if isinstance(p, County):
        return countries.PlaceTypes.county
    if isinstance(p, Township):
        return countries.PlaceTypes.township
    if isinstance(p, Town):
        return countries.PlaceTypes.town
    if isinstance(p, Municipality):
        return countries.PlaceTypes.municipality
    if isinstance(p, Borough):
        return countries.PlaceTypes.borough
    if isinstance(p, SmallBorough):
        return countries.PlaceTypes.smallborough
    if isinstance(p, Village):
github lino-framework / lino / lino / modlib / tickets / blogger.py View on Github external
# License: BSD (see file COPYING for details)

"""
code changes must be documented in *one central place 
per developer*, not per module.
"""

import os
import datetime
from django.conf import settings
from lino.utils import i2d, i2t
from lino.utils.restify import restify, doc2rst

from lino.api import dd, rt
blogs = dd.resolve_app('blogs')
tickets = dd.resolve_app('tickets')


class Blogger(object):

    def __init__(self, user=None):
        self.objects_list = []
        self.date = None
        self.user = user
        self.current_project = None

    def set_date(self, d):
        self.date = i2d(d)

    def set_project(self, project):
        self.current_project = project
github lino-framework / lino / lino / modlib / orders / models.py View on Github external
from lino.api import dd, rt

#~ from lino import reports
from lino.core import actions
from lino import mixins
from lino.utils import mti
#~ from lino.utils.quantities import Duration


contacts = dd.resolve_app('contacts')
accounts = dd.resolve_app('accounts')
ledger = dd.resolve_app('ledger')
vat = dd.resolve_app('vat')
products = dd.resolve_app('products')
sales = dd.resolve_app('sales')


class OrderStates(dd.Workflow):
    pass
add = OrderStates.add_item
add('10', _("Draft"), 'draft', editable=True)
add('20', _("Registered"), 'registered', editable=False)
add('30', _("Inactive"), 'inactive', editable=False)


@dd.receiver(dd.pre_analyze)
def setup_workflow(sender=None, **kw):
    OrderStates.registered.add_transition(_("Register"), states='draft')
    OrderStates.draft.add_transition(_("Deregister"), states="registered")
github lino-framework / lino / lino / modlib / orders / models.py View on Github external
from django.conf import settings
#~ from django.contrib.auth import models as auth
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _

from lino.api import dd, rt

#~ from lino import reports
from lino.core import actions
from lino import mixins
from lino.utils import mti
#~ from lino.utils.quantities import Duration


contacts = dd.resolve_app('contacts')
accounts = dd.resolve_app('accounts')
ledger = dd.resolve_app('ledger')
vat = dd.resolve_app('vat')
products = dd.resolve_app('products')
sales = dd.resolve_app('sales')


class OrderStates(dd.Workflow):
    pass
add = OrderStates.add_item
add('10', _("Draft"), 'draft', editable=True)
add('20', _("Registered"), 'registered', editable=False)
add('30', _("Inactive"), 'inactive', editable=False)


@dd.receiver(dd.pre_analyze)
def setup_workflow(sender=None, **kw):