How to use the lino.api.rt 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_noi / fixtures / tractickets.py View on Github external
def objects():

    Project = rt.modules.tickets.Project
    Milestone = rt.modules.tickets.Milestone
    Ticket = rt.modules.tickets.Ticket
    User = rt.modules.users.User
    TicketStates = rt.modules.tickets.TicketStates

    states = set()

    for n, row in enumerate(codecs.open(fn, encoding="utf-8").readlines()):
        if n == 0:
            continue  # headers
        if not row:
            continue
        cells = row.split('\t')
        if len(cells) != len(COLUMNS):
            msg = "Oops, line {0} has {1} cells".format(n, len(cells))
            raise Exception(msg)
github lino-framework / lino / lino / modlib / contacts / mixins.py View on Github external
def get_contact(self):
        if self.contact_person is not None:
            if self.company is not None:
                roles = rt.modules.contacts.Role.objects.filter(
                    company=self.company, person=self.contact_person)
                #~ print '20120929 get_contact', roles
                if roles.count() == 1:
                    return roles[0]
github lino-framework / lino / lino / modlib / summaries / management / commands / checksummaries.py View on Github external
def handle(self, *args, **options):
        ses = rt.login()
        ses.run(settings.SITE.site_config.check_all_summaries)
        # checksummaries(args=args)
github lino-framework / lino / lino_noi / projects / team / lib / clocking / fixtures / std.py View on Github external
def objects():
    yield parent_objects()

    ServiceReport = rt.modules.clocking.ServiceReport
    ExcerptType = rt.modules.excerpts.ExcerptType
    kw = dict(
        build_method='weasy2html',
        # template='service_report.weasy.html',
        # body_template='default.body.html',
        # print_recipient=False,
        primary=True, certifying=True)
    kw.update(dd.str2kw('name', ServiceReport._meta.verbose_name))
    yield ExcerptType.update_for_model(ServiceReport, **kw)
github lino-framework / lino / lino / modlib / vat / fixtures / euvatrates.py View on Github external
def objects():
    Country = rt.modules.countries.Country
    # VatRule = rt.modules.vat.VatRule
    vat = rt.modules.vat

    def rule(vat_class, country_id, vat_regime, rate):
        if country_id is None:
            country = None
        else:
            try:
                country = Country.objects.get(pk=country_id)
            except Country.DoesNotExist:
                raise Exception("No country {0}".format(country_id))
        return vat.VatRule(
            country=country,
            vat_class=vat.VatClasses.get_by_name(vat_class),
            # trade_type=vat.TradeTypes.get_by_name(trade_type),
            vat_regime=vat.VatRegimes.get_by_name(vat_regime),
github lino-framework / lino / lino / modlib / auth / models.py View on Github external
def get_welcome_email_body(self, ar):
        template = rt.get_template('users/welcome_email.eml')
        context = self.get_printable_context(ar)
        # dict(obj=self, E=E, rt=rt)
        return template.render(**context)
github lino-framework / lino / lino / modlib / sales / models.py View on Github external
def discount_changed(self, ar):
        if not self.product:
            return

        tt = self.voucher.get_trade_type()
        catalog_price = tt.get_catalog_price(self.product)

        if catalog_price is None:
            return
        #~ assert self.vat_class == self.product.vat_class
        rule = self.get_vat_rule()
        if rule is None:
            return
        cat_rule = rt.modules.vat.VatRule.get_vat_rule(
            get_default_vat_regime, self.get_vat_class(tt),
            dd.plugins.countries.get_my_country(),
            dd.today())
        if cat_rule is None:
            return
        if rule.rate != cat_rule.rate:
            catalog_price = remove_vat(catalog_price, cat_rule.rate)
            catalog_price = add_vat(catalog_price, cat_rule.rate)

        if self.discount is None:
            self.unit_price = catalog_price
        else:
            self.unit_price = catalog_price * \
                (HUNDRED - self.discount) / HUNDRED
        self.unit_price_changed(ar)
github lino-framework / lino / lino / modlib / printing / actions.py View on Github external
def before_build(self, bm, elem):
        """Return the target filename if a document needs to be built,
        otherwise return ``None``.
        """
        elem.before_printable_build(bm)
        # raise Exception("20170519 before_build didn't warn")
        filename = bm.get_target_name(self, elem)
        if not filename:
            return
        if os.path.exists(filename):
            logger.debug("%s %s -> overwrite existing %s.", bm, elem, filename)
            os.remove(filename)
        else:
            # logger.info("20121221 makedirs_if_missing %s",os.path.dirname(filename))
            rt.makedirs_if_missing(os.path.dirname(filename))
        logger.debug("%s : %s -> %s", bm, elem, filename)
        return filename
github lino-framework / lino / lino / modlib / excerpts / models.py View on Github external
def get_body_template_filename(self):
        tplname = self.get_body_template()
        if not tplname:
            return None
        mc = self.excerpt_type.content_type.model_class()
        tplgroup = mc.get_template_group()
        return rt.find_config_file(tplname, tplgroup)
github lino-framework / lino / lino_noi / lib / clocking / ui.py View on Github external
def get_slave_summary(self, obj, ar):
        if ar is None:
            return ''
        elems = []

        # Active sessions:
        active_sessions = []
        qs = rt.modules.clocking.Session.objects.filter(ticket=obj)
        tot = Duration()
        for ses in qs:
            d = ses.get_duration()
            if d is not None:
                tot += d
            if ses.end_time is None:
                txt = "{0} since {1}".format(ses.user, ses.start_time)
                lnk = ar.obj2html(ses, txt)
                sar = ses.end_session.request_from(ar)
                if sar.get_permission():
                    lnk = E.span(lnk, " ", sar.ar2button(ses))
                active_sessions.append(lnk)

        # elems.append(E.p(_("Total {0} hours.").format(tot)))
        elems.append(E.p(_("Total %s hours.") % tot))