Esempio n. 1
0
def objects():

    ses = rt.login('wilfried')
    dd.plugins.b2c.import_statements_path = HERE
    settings.SITE.site_config.import_b2c(ses)

    # That file contains a few dozen of accounts which are now
    # "orphaned".  We are now going to assign theses accounts to a
    # random partner TODO: find a more realistic rule for selecting
    # the candidates. The filter might be a plugin attribute.

    IA = rt.modules.b2c.Account
    SA = rt.modules.sepa.Account
    PARTNERS = Cycler(rt.modules.contacts.Partner.objects.all())

    count = 0
    for ia in IA.objects.all():
        try:
            SA.objects.get(iban=ia.iban)
        except SA.DoesNotExist:
            yield SA(partner=PARTNERS.pop(), iban=ia.iban)
            count += 1
    if count == 0:
        dd.logger.info("%d statements",
                       rt.modules.b2c.Statement.objects.count())
        raise Exception(
            "There's something wrong: no accounts have been imported")
Esempio n. 2
0
def objects():

    ses = rt.login('wilfried')
    dd.plugins.b2c.import_statements_path = HERE
    settings.SITE.site_config.import_b2c(ses)

    # That file contains a few dozen of accounts which are now
    # "orphaned".  We are now going to assign theses accounts to a
    # random partner TODO: find a more realistic rule for selecting
    # the candidates. The filter might be a plugin attribute.

    IA = rt.modules.b2c.Account
    SA = rt.modules.sepa.Account
    PARTNERS = Cycler(rt.modules.contacts.Partner.objects.all())

    count = 0
    for ia in IA.objects.all():
        try:
            SA.objects.get(iban=ia.iban)
        except SA.DoesNotExist:
            yield SA(partner=PARTNERS.pop(), iban=ia.iban)
            count += 1
    if count == 0:
        dd.logger.info(
            "%d statements", rt.modules.b2c.Statement.objects.count())
        raise Exception(
            "There's something wrong: no accounts have been imported")
Esempio n. 3
0
def objects():
    Person = rt.modules.mti.Person
    Restaurant = rt.modules.mti.Restaurant
    Place = rt.modules.mti.Place

    anne = Person(name="Anne")
    yield anne

    bert = Person(name="Bert")
    yield bert

    claude = Person(name="Claude")
    yield claude

    dirk = Person(name="Dirk")
    yield dirk

    ernie = Person(name="Ernie")
    yield ernie

    fred = Person(name="Fred")
    yield fred

    PERSONS = Cycler(Person.objects.all())

    p = Place(name="Bert's pub")
    yield p
    p.owners.add(anne)
    p.owners.add(bert)

    for name in RESTAURANT_NAMES.strip().splitlines():
        r = Restaurant(name=name)
        yield r
        r.owners.add(PERSONS.pop())
        r.cooks.add(PERSONS.pop())
def objects():
    Category = Instantiator('books.Category', 'name').build
    Author = Instantiator('books.Author', 'name').build
    Publication = Instantiator('books.Publication', 'name').build
    BookInfo = Instantiator('books.BookInfo', 'name author:name publication category copies').build

    # Setup tables
    instantiators = (
        (Category, CATEGORY_DATA),
        (Author, AUTHOR_DATA),
        (Publication, PUBLICATION_DATA),
        (BookInfo, BOOK_INFO_DATA))
    for i, d in instantiators:
        print i
        for row in read_data(d):
            # print row
            yield i(*row)
    # yield BookInfo('Mrutyunjay', '4', '5', '15', '10')

    # added by LS:
    from lino.api import rt
    Floor = rt.modules.books.Floor
    Room = rt.modules.books.Room
    Bookshelf = rt.modules.books.Bookshelf
    Rack = rt.modules.books.Rack
    Slot = rt.modules.books.Slot
    Book = rt.modules.books.Book
    BookInfo = rt.modules.books.BookInfo
    BookLocation = rt.modules.books.BookLocation
    for i in range(10):
        floor = Floor(number=i)
        yield floor
        for j, name in enumerate(["first", "second", "third"]):
            room = Room(floor=floor, number=j, name=name)
            yield room
            for code in ("A", "B", "C"):
                shelf = Bookshelf(room=room, code=code)
                yield shelf
                for rack_code in ("D", "E", "F"):
                    rack = Rack(bookshelf=shelf, code=rack_code)
                    yield rack

                    for slot_number in (1, 2, 3, 4):
                        slot = Slot(rack=rack, number=slot_number)
                        yield slot

    unique_code = 1
    # create 2 copies (Book) of each BookInfo:
    for info in BookInfo.objects.all():
        for i in range(2):
            yield Book(info=info, code=str(unique_code))
            unique_code += 1
    SLOTS = Cycler(Slot.objects.all())
    for book in Book.objects.all():
        yield BookLocation(book=book, slot=SLOTS.pop())
Esempio n. 5
0
def objects():
    
    yield rt.login('alicia').get_user()

    if False:  # done in lino_welfare/modlib/integ/fixtures/

        TT = Cycler(rt.modules.immersion.ContractType.objects.all())
        TG = Cycler(rt.modules.immersion.Goal.objects.all())
        Training = rt.modules.immersion.Contract

        alicia = rt.login('alicia').get_user()
        selected_clients = (131, 149, 161)
        for i, pk in enumerate(selected_clients):
            kw = dict(client_id=pk)
            kw.update(type=TT.pop())
            kw.update(user=alicia)
            kw.update(goal=TG.pop())
            kw.update(applies_from=dd.demo_date(i*30))
            kw.update(applies_until=dd.demo_date(i*30+60*(i+1)))
            yield Training(**kw)
Esempio n. 6
0
def objects():

    Vote = rt.models.votes.Vote
    VoteStates = rt.models.votes.VoteStates
    User = rt.models.users.User

    STATES  = Cycler(VoteStates.objects())
    USERS = Cycler(User.objects.all())
    TICKETS = Cycler(dd.plugins.votes.votable_model.objects.all())
    if len(TICKETS):
        for i in range(20):
            USERS.pop()  # not every user votes
            obj = Vote(
                state=STATES.pop(), user=USERS.pop(), votable=TICKETS.pop())
            if obj.user != obj.votable.user:
                yield obj
Esempio n. 7
0
def objects():

    yield lib_objects()

    SECTIONS = Cycler(rt.models.courses.Sections.objects())

    for obj in rt.models.courses.Pupil.objects.order_by('id'):
        if obj.id % 5 == 0:
            obj.is_lfv = True
        if obj.id % 6 == 0:
            obj.is_ckk = True
        if obj.id % 4 == 0:
            obj.section = SECTIONS.pop()
        elif obj.id % 10 != 0:
            obj.member_until = dd.demo_date().replace(month=12, day=31)
        yield obj

    fee_account = rt.models.accounts.Account(
        ref=dd.plugins.courses.membership_fee_account,
        type=rt.models.accounts.AccountTypes.incomes,
        default_amount=15,
        **dd.str2kw('name', _("Membership fee")))
    yield fee_account

    Journal = rt.models.ledger.Journal
    USERS = Cycler(rt.models.users.User.objects.all())
    MEMBERS = Cycler(rt.models.courses.Pupil.objects.all())

    jnl = Journal.objects.get(ref='CSH')
    membership_payments = [
        (1, 3),
        (2, 1),
        (10, 2),
        (11, 4),
        (12, 5),
    ]
    REQUEST = rt.login()

    for month, number in membership_payments:
        date = dd.demo_date().replace(month=month)
        voucher = jnl.create_voucher(
            user=USERS.pop(),
            voucher_date=date)
        yield voucher
        for i in range(number):
            M = jnl.voucher_type.get_items_model()
            kw = dict(voucher=voucher)
            kw.update(partner=MEMBERS.pop(), date=date, account=fee_account)
            kw.update(
                amount=fee_account.default_amount, dc=fee_account.type.dc)
            yield M(**kw)
        voucher.register(REQUEST)
        voucher.save()
Esempio n. 8
0
def objects():
    # not used. from the time when we still had tickets and courses
    Line = rt.models.courses.Line
    Topic = rt.models.courses.Topic
    Course = rt.models.courses.Course
    EventType = rt.models.cal.EventType
    Room = rt.models.cal.Room
    Company = rt.models.contacts.Company
    Person = rt.models.contacts.Person
    Role = rt.models.contacts.Role
    RoleType = rt.models.contacts.RoleType

    school = named(Room, _("School"))
    yield school
    center = named(Room, _("Youth center"))
    yield center
    library = named(Room, _("Library"))
    yield library

    training = named(EventType, _("Training"))
    yield training
    workshop = named(EventType, _("Workshop"))
    yield workshop
    camp = named(EventType, _("Camp"))
    yield camp

    nature = named(Topic, _("Nature"))
    yield nature
    folk = named(Topic, _("Folk"))
    yield folk
    together = named(Topic, _("Acting together"))
    yield together
    health = named(Topic, _("Health"))
    yield health
    comp = named(Topic, _("Computer"))
    yield comp

    yield named(Line,
                _("Photography workshop"),
                event_type=workshop,
                every_unit=Recurrencies.once,
                topic=together)
    yield named(Line,
                _("Teamwork training"),
                event_type=training,
                every_unit=Recurrencies.once,
                topic=together)
    yield named(Line,
                _("Folk camp 2017"),
                event_type=camp,
                every_unit=Recurrencies.once,
                topic=together)
    yield named(Line,
                _("Lino Vilma training"),
                event_type=training,
                every_unit=Recurrencies.weekly,
                topic=together)

    LINES = Cycler(Line.objects.all())
    for offset in (-60, -10, -5, 1, 10, 30):
        yield Course(line=LINES.pop(), start_date=dd.demo_date(offset))

    choir = Company(name="Village choir")
    yield choir

    yield Company(name="Sopranos", parent=choir)
    yield Company(name="Altos", parent=choir)
    yield Company(name="Tenors", parent=choir)
    yield Company(name="Basses", parent=choir)

    RTYPES = Cycler(RoleType.objects.all())
    COMPANIES = Cycler(Company.objects.all())

    for i, p in enumerate(Person.objects.all()):
        for j in range(i % 3):
            yield Role(company=COMPANIES.pop(), type=RTYPES.pop(), person=p)
Esempio n. 9
0
def objects():
    # not used. from the time when we still had tickets and courses
    Line = rt.models.courses.Line
    Topic = rt.models.courses.Topic
    Course = rt.models.courses.Course
    EventType = rt.models.cal.EventType
    Room = rt.models.cal.Room
    Company = rt.models.contacts.Company
    Person = rt.models.contacts.Person
    Role = rt.models.contacts.Role
    RoleType = rt.models.contacts.RoleType

    school = named(Room, _("School"))
    yield school
    center = named(Room, _("Youth center"))
    yield center
    library = named(Room, _("Library"))
    yield library
    
    training = named(EventType, _("Training"))
    yield training
    workshop = named(EventType, _("Workshop"))
    yield workshop
    camp = named(EventType, _("Camp"))
    yield camp
    
    nature = named(Topic, _("Nature"))
    yield nature
    folk = named(Topic, _("Folk"))
    yield folk
    together = named(Topic, _("Acting together"))
    yield together
    health = named(Topic, _("Health"))
    yield health
    comp = named(Topic, _("Computer"))
    yield comp
    
    yield named(
        Line, _("Photography workshop"),
        event_type=workshop,
        every_unit=Recurrencies.once, topic=together)
    yield named(
        Line, _("Teamwork training"),
        event_type=training,
        every_unit=Recurrencies.once, topic=together)
    yield named(
        Line, _("Folk camp 2017"),
        event_type=camp,
        every_unit=Recurrencies.once, topic=together)
    yield named(
        Line, _("Lino Vilma training"),
        event_type=training,
        every_unit=Recurrencies.weekly, topic=together)

    LINES = Cycler(Line.objects.all())
    for offset in (-60, -10, -5, 1, 10, 30):
        yield Course(line=LINES.pop(), start_date=dd.demo_date(offset))

    choir = Company(name="Village choir")
    yield choir
    
    yield Company(name="Sopranos", parent=choir)
    yield Company(name="Altos", parent=choir)
    yield Company(name="Tenors", parent=choir)
    yield Company(name="Basses", parent=choir)
    
    RTYPES = Cycler(RoleType.objects.all())
    COMPANIES = Cycler(Company.objects.all())

    for i, p in enumerate(Person.objects.all()):
        for j in range(i % 3):
            yield Role(company=COMPANIES.pop(), type=RTYPES.pop(),
                       person=p)
Esempio n. 10
0
def unused_objects():

    Vote = rt.models.votes.Vote
    VoteStates = rt.models.votes.VoteStates
    User = rt.models.users.User

    STATES = Cycler(VoteStates.objects())
    USERS = Cycler(User.objects.all())
    TICKETS = Cycler(dd.plugins.votes.votable_model.objects.all())
    if len(TICKETS):
        for i in range(20):
            USERS.pop()  # not every user votes
            obj = Vote(state=STATES.pop(),
                       user=USERS.pop(),
                       votable=TICKETS.pop())
            if obj.user != obj.votable.user:
                yield obj