How to use the lino.utils.Cycler 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 / ledger / fixtures / demo_bookings.py View on Github external
#~ print "20121208 ok", item
                #~ else:
                    #~ if item.product.price:
                        #~ raise Exception("20121208")
                yield item
            invoice.register(ar)
            invoice.save()

    USERS = Cycler(settings.SITE.user_model.objects.all())

    if sales:

        yield Product(name="Foo", sales_price='399.90')
        yield Product(name="Bar", sales_price='599.90')
        yield Product(name="Baz", sales_price='990.00')
        PRODUCTS = Cycler(Product.objects.order_by('id'))
        JOURNAL_S = ledger.Journal.objects.get(ref="SLS")
        #~ assert JOURNAL_S.dc == accounts.DEBIT
        CUSTOMERS = Cycler(Person.objects.order_by('id'))
        ITEMCOUNT = Cycler(1, 2, 3)
        QUANTITIES = Cycler(5, 1, 2, 3)
        SALES_PER_MONTH = Cycler(2, 1, 3, 2, 0)

    PROVIDERS = Cycler(Company.objects.order_by('id'))

    JOURNAL_P = ledger.Journal.objects.get(ref="PRC")
    #~ assert JOURNAL_P.dc == accounts.CREDIT
    ACCOUNTS = Cycler(JOURNAL_P.get_allowed_accounts())
    AMOUNTS = Cycler([Decimal(x) for x in
                      "20 29.90 39.90 99.95 199.95 599.95 1599.99".split()])
    AMOUNT_DELTAS = Cycler([Decimal(x)
                           for x in "0 0.60 1.10 1.30 2.50".split()])
github lino-framework / lino / lino / utils / demonames / bel.py View on Github external
m = re.match(STREET_RE, ln)
            if m:
                s = m.group(1).strip()
                if '|' in s:
                    s = s.split('|')[1]
                yield s
                #~ streets.append(s)


LAST_NAMES_BELGIUM = Cycler(splitter1(LAST_NAMES_BELGIUM))
MALE_FIRST_NAMES_FRANCE = Cycler(splitter2(MALE_FIRST_NAMES_FRANCE))
FEMALE_FIRST_NAMES_FRANCE = Cycler(splitter2(FEMALE_FIRST_NAMES_FRANCE))

LAST_NAMES_AFRICAN = Cycler(splitter1(LAST_NAMES_AFRICAN))
MALE_FIRST_NAMES_AFRICAN = Cycler(splitter1(MALE_FIRST_NAMES_AFRICAN))
FEMALE_FIRST_NAMES_AFRICAN = Cycler(splitter1(FEMALE_FIRST_NAMES_AFRICAN))

LAST_NAMES_MUSLIM = Cycler(splitter1(LAST_NAMES_MUSLIM))
MALE_FIRST_NAMES_MUSLIM = Cycler(splitter1(MALE_FIRST_NAMES_MUSLIM))
FEMALE_FIRST_NAMES_MUSLIM = Cycler(splitter1(FEMALE_FIRST_NAMES_MUSLIM))

if False:
    last_names = []
    for ln in LAST_NAMES_FRANCE.splitlines():
        if ln:
            a = ln.split()
            if len(a) == 3:
                last_names.append(a[0].strip())
            elif len(a) == 4:
                last_names.append(a[0].strip() + ' ' + a[1].strip())
github lino-framework / lino / lino / modlib / ledger / fixtures / demo_bookings.py View on Github external
invoice.save()

    USERS = Cycler(settings.SITE.user_model.objects.all())

    if sales:

        yield Product(name="Foo", sales_price='399.90')
        yield Product(name="Bar", sales_price='599.90')
        yield Product(name="Baz", sales_price='990.00')
        PRODUCTS = Cycler(Product.objects.order_by('id'))
        JOURNAL_S = ledger.Journal.objects.get(ref="SLS")
        #~ assert JOURNAL_S.dc == accounts.DEBIT
        CUSTOMERS = Cycler(Person.objects.order_by('id'))
        ITEMCOUNT = Cycler(1, 2, 3)
        QUANTITIES = Cycler(5, 1, 2, 3)
        SALES_PER_MONTH = Cycler(2, 1, 3, 2, 0)

    PROVIDERS = Cycler(Company.objects.order_by('id'))

    JOURNAL_P = ledger.Journal.objects.get(ref="PRC")
    #~ assert JOURNAL_P.dc == accounts.CREDIT
    ACCOUNTS = Cycler(JOURNAL_P.get_allowed_accounts())
    AMOUNTS = Cycler([Decimal(x) for x in
                      "20 29.90 39.90 99.95 199.95 599.95 1599.99".split()])
    AMOUNT_DELTAS = Cycler([Decimal(x)
                           for x in "0 0.60 1.10 1.30 2.50".split()])
    DATE_DELTAS = Cycler((1, 2, 3, 4, 5, 6, 7))
    INFLATION_RATE = Decimal("0.02")

    """
    5 "purchase stories" : each story represents a provider who sends
    monthly invoices.
github lino-framework / lino / lino / utils / demonames / bel.py View on Github external
"""
    for ln in STREETS_OF_LIEGE.splitlines():
        if ln and ln[0] == '*':
            m = re.match(STREET_RE, ln)
            if m:
                s = m.group(1).strip()
                if '|' in s:
                    s = s.split('|')[1]
                yield s
                #~ streets.append(s)


LAST_NAMES_BELGIUM = Cycler(splitter1(LAST_NAMES_BELGIUM))
MALE_FIRST_NAMES_FRANCE = Cycler(splitter2(MALE_FIRST_NAMES_FRANCE))
FEMALE_FIRST_NAMES_FRANCE = Cycler(splitter2(FEMALE_FIRST_NAMES_FRANCE))

LAST_NAMES_AFRICAN = Cycler(splitter1(LAST_NAMES_AFRICAN))
MALE_FIRST_NAMES_AFRICAN = Cycler(splitter1(MALE_FIRST_NAMES_AFRICAN))
FEMALE_FIRST_NAMES_AFRICAN = Cycler(splitter1(FEMALE_FIRST_NAMES_AFRICAN))

LAST_NAMES_MUSLIM = Cycler(splitter1(LAST_NAMES_MUSLIM))
MALE_FIRST_NAMES_MUSLIM = Cycler(splitter1(MALE_FIRST_NAMES_MUSLIM))
FEMALE_FIRST_NAMES_MUSLIM = Cycler(splitter1(FEMALE_FIRST_NAMES_MUSLIM))

if False:
    last_names = []
    for ln in LAST_NAMES_FRANCE.splitlines():
        if ln:
            a = ln.split()
            if len(a) == 3:
                last_names.append(a[0].strip())
github lino-framework / lino / lino / modlib / cal / fixtures / demo2.py View on Github external
ETYPES = Cycler(EventType.objects.filter(is_appointment=True))

    def s2duration(s):
        h, m = map(int, s.split(':'))
        #~ return relativedelta(hours=h,minutes=m)
        return datetime.timedelta(hours=h, minutes=m)

    def s2time(s):
        h, m = map(int, s.split(':'))
        return datetime.time(h, m)
    TIMES = Cycler([s2time(s)
                   for s in ('08:30', '09:40', '10:20', '11:10', '13:30')])
    #~ DURATIONS = Cycler([s2duration(s) for s in ('00:30','00:40','1:00','1:30','2:00','3:00')])
    DURATIONS = Cycler([s2duration(s)
                       for s in ('01:00', '01:15', '1:30', '1:45', '2:00', '2:30', '3:00')])
    ACL = Cycler(cal.AccessClasses.items())
    STATES = Cycler(cal.EventStates.items())
    SUMMARIES = Cycler((
        dict(en='Lunch', de=u"Mittagessen", fr=u"Diner"),
        dict(en='Dinner', de=u"Abendessen", fr=u"Souper"),
        dict(en='Breakfast', de=u"Frühstück", fr=u"Petit-déjeuner"),
        dict(en='Meeting', de=u"Treffen", fr=u"Rencontre"),
        dict(en='Consultation', de=u"Beratung", fr=u"Consultation"),
        dict(en='Seminar', de=u"Seminar", fr=u"Séminaire"),
        dict(en='Evaluation', de=u"Auswertung", fr=u"Evaluation"),
        dict(en='First meeting', de=u"Erstgespräch", fr=u"Première rencontre"),
        dict(en='Interview', de=u"Interview", fr=u"Interview")
    ))
    #~ for i in range(20):

    for u in settings.SITE.user_model.objects.exclude(email=''):
        #~ u = USERS.pop()
github lino-framework / lino / lino / apps / pcsw.old / fixtures / demo.py View on Github external
yield bisajob
    rcyclejob = job(rcycle,art607,2,"rcycle")
    yield rcyclejob 
    proaktivjob = job(proaktiv,art607,2,"proaktiv",sector=horeca,function=1)
    yield proaktivjob
    
    for i in range(5):
        f = FUNCTIONS.pop()
        yield Job(provider=PROVIDERS.pop(),
          type=JTYPES.pop(),
          contract_type=CTYPES.pop(),
          name=unicode(f),
          sector=SECTORS.pop(),function=f)
    
    #~ JOBS = Cycler(*[x for x in Job.objects.all()])
    JOBS = Cycler(Job.objects.all())
    if False:
        contract = Instantiator('jobs.Contract',
          'type applies_from applies_until job contact',
          user=root).build
        yield contract(1,settings.LINO.demo_date(-30),
            settings.LINO.demo_date(+60),rcyclejob,rcycle_dir,person=hans)
        yield contract(1,settings.LINO.demo_date(-29),
            settings.LINO.demo_date(+61),bisajob,bisa_dir,person=ulrike)
        yield contract(1,settings.LINO.demo_date(-29),None,bisajob,bisa_dir,person=andreas)
        yield contract(1,settings.LINO.demo_date(-28),None,
            rcyclejob,rcycle_dir,person=annette)
        yield contract(1,
            settings.LINO.demo_date(-10),settings.LINO.demo_date(+20),
            bisajob,bisa_dir,person=tatjana)
        yield contract(2,
            settings.LINO.demo_date(20),settings.LINO.demo_date(+120),
github lino-framework / lino / lino / modlib / ledger / fixtures / welfare_demo.py View on Github external
InvoiceItem = rt.modules.vatless.InvoiceItem
    Account = rt.modules.accounts.Account
    AccountCharts = rt.modules.accounts.AccountCharts
    AccountTypes = rt.modules.accounts.AccountTypes

    CLIENTS = Cycler(Client.objects.filter(client_state=ClientStates.coached))

    l = []
    qs = ClientContactType.objects.filter(can_refund=True)
    for cct in qs:
        qs2 = Partner.objects.filter(client_contact_type=cct)
        if qs2.count():
            # i = (cct, Cycler(qs2))
            l.append(Cycler(qs2))
    RECIPIENTS = Cycler(l)
    ACCOUNTS = Cycler(Account.objects.filter(
        chart=AccountCharts.default, type=AccountTypes.expenses))
    AMOUNTS = Cycler(10, '12.50', 25, '29.95', 120, '5.33')

    ses = rt.login('robin')
    PRC = Journal.get_by_ref('PRC')
    for i in range(20):
        kw = dict()
        kw.update(partner=RECIPIENTS.pop())
        if i % 9 != 0:
            kw.update(project=CLIENTS.pop())
        kw.update(date=dd.today(-5*i))
        kw.update(journal=PRC)
        kw.update(user=ses.get_user())
        obj = Invoice(**kw)
        yield obj
        yield InvoiceItem(
github lino-framework / lino / lino / modlib / households / fixtures / demo.py View on Github external
def objects():

    Member = rt.modules.households.Member
    MemberRoles = rt.modules.households.MemberRoles
    # Household = resolve_model('households.Household')
    Person = resolve_model(dd.plugins.households.person_model)
    Type = resolve_model('households.Type')

    MEN = Cycler(Person.objects.filter(gender=dd.Genders.male)
                 .order_by('-id'))
    WOMEN = Cycler(Person.objects.filter(gender=dd.Genders.female)
                   .order_by('-id'))
    TYPES = Cycler(Type.objects.all())

    ses = rt.login()
    for i in range(5):
        pv = dict(
            head=MEN.pop(), partner=WOMEN.pop(),
            type=TYPES.pop())
        ses.run(
            Person.create_household,
            action_param_values=pv)
        # yield ses.response['data_record']
        # he = MEN.pop()
        # she = WOMEN.pop()
github lino-framework / lino / lino_noi / projects / team / settings / fixtures / demo.py View on Github external
WORKERS = Cycler(workers)
    TYPES = Cycler(SessionType.objects.all())
    TICKETS = Cycler(Ticket.objects.all())
    DURATIONS = Cycler([12, 138, 90, 10, 122, 209, 37, 62, 179, 233, 5])

    # every fourth ticket is unassigned and thus listed in
    # PublicTickets
    # for i, t in enumerate(Ticket.objects.exclude(private=True)):
    for i, t in enumerate(Ticket.objects.all()):
        if i % 4:
            t.assigned_to = WORKERS.pop()
            yield t

    for u in workers:

        TICKETS = Cycler(Ticket.objects.filter(assigned_to=u))
        if len(TICKETS) == 0:
            continue

        for offset in (0, -1, -3, -4):

            date = dd.demo_date(offset)
            worked = Duration()
            ts = datetime.datetime.combine(date, datetime.time(9, 0, 0))
            for i in range(7):
                obj = Session(
                    ticket=TICKETS.pop(), session_type=TYPES.pop(), user=u)
                obj.set_datetime('start', ts)
                d = DURATIONS.pop()
                worked += d
                if offset < 0:
                    ts = DurationUnits.minutes.add_duration(ts, d)
github lino-framework / lino / lino / modlib / contacts / management / commands / garble_persons.py View on Github external
def __init__(self):
        self.LAST_NAMES = Cycler(self.get_last_names())
        self.MALES = Cycler(self.get_male_first_names())
        self.FEMALES = Cycler(self.get_female_first_names())