Esempio n. 1
0
def add_accessory(image, *args, **kwargs):
    id = kwargs.get('id', None)
    cz_datetime = datetime.strptime(kwargs['datum_vyroby'], '%d.%m.%Y')
    accessory = Doplnek.query.filter_by(id=id).first()
    if not accessory:
        stmt = Doplnek(nazev=kwargs['nazev'],
                       vyrobce=kwargs['vyrobce'],
                       popis_vyuziti=kwargs['popis_vyuziti'],
                       datum_vyroby=cz_datetime.strftime("%Y-%m-%d"),
                       velikost=kwargs['velikost'],
                       opotrebeni=kwargs['opotrebeni'],
                       pocet=kwargs['pocet'],
                       typ=kwargs['typ'],
                       material=kwargs['material'],
                       cena=kwargs['cena'],
                       obrazek=image,
                       barva=kwargs['barva'])
        session.add(stmt)

    else:
        accessory.nazev = kwargs['nazev']
        accessory.vyrobce = kwargs['vyrobce']
        accessory.popis_vyuziti = kwargs['popis_vyuziti']
        accessory.datum_vyroby = cz_datetime.strftime("%Y-%m-%d")
        accessory.velikost = kwargs['velikost']
        accessory.opotrebeni = kwargs['opotrebeni']
        accessory.pocet = kwargs['pocet']
        accessory.typ = kwargs['typ']
        accessory.material = kwargs['material']
        accessory.cena = kwargs['cena']
        accessory.barva = kwargs['barva']
        if image:
            accessory.obrazek = image
    session.commit()
Esempio n. 2
0
def set_product_amount(type, id, amount):
    if (type == "costumes"):
        update_costume = session.query(Kostym)\
            .filter(Kostym.id == id).first()
        update_costume.pocet = amount
        session.commit()
    elif (type == "accessories"):
        update_costume = session.query(Doplnek) \
            .filter(Doplnek.id == id).first()
        update_costume.pocet = amount
        session.commit()
Esempio n. 3
0
def update_users_data(data):
    user = session.query(Osoba).filter(Osoba.rc == data['rc']).first()

    user.jmeno = data['jmeno']
    user.prijmeni = data['prijmeni']
    user.obec = data['obec']
    user.ulice = data['ulice']
    user.cislo_popisne = data['cislo_popisne']
    user.tel_cislo = data['tel_cislo']
    user.email = data['email']

    session.commit()
Esempio n. 4
0
def update_product_amount(id, amount, type):
    if type == "costume":
        costume = session.query(Kostym) \
            .filter(Kostym.id == id).first()
        costume.pocet += amount
        session.add(costume)
    elif type == "accessory":
        accessory = session.query(Doplnek) \
            .filter(Doplnek.id == id).first()
        accessory.pocet += amount
        session.add(accessory)
    session.commit()
Esempio n. 5
0
def create_user(*args, **kwargs):
    stmt = Osoba(rc=kwargs['rc'],
                 email=kwargs['email'],
                 heslo=generate_password_hash(kwargs['password']),
                 jmeno=kwargs['jmeno'],
                 prijmeni=kwargs['prijmeni'],
                 ulice=kwargs.get('ulice'),
                 cislo_popisne=kwargs.get('cislo_popisne'),
                 tel_cislo=kwargs.get('tel_cislo'))
    session.add(stmt)
    session.commit()
    stmt = Klient(clenstvi='bronzove', osoba_rc=kwargs['rc'])
    session.add(stmt)
    session.commit()
Esempio n. 6
0
def update_user(**kwargs):
    session.query(Klient).filter(Klient.osoba_rc==kwargs['rc']).\
        update({'clenstvi': kwargs['membership'][0]})
    if kwargs['role'][0] == 'zakaznik':
        session.query(Zamestnanec).filter(
            Zamestnanec.osoba_rc == kwargs['rc'][0]).delete()
    else:
        if session.query(Zamestnanec).filter(
                Zamestnanec.osoba_rc == kwargs['rc']).first():
            session.query(Zamestnanec).filter(Zamestnanec.osoba_rc == kwargs['rc']). \
                update({'pozice': kwargs['role'][0]})
        else:
            stmt = Zamestnanec(osoba_rc=kwargs['rc'][0],
                               pozice=kwargs['role'][0])
            session.add(stmt)
    session.commit()
Esempio n. 7
0
def add_or_update_costume(image, *args, **kwargs):
    id = kwargs.get('id', None)
    cz_datetime = datetime.strptime(kwargs['datum_vyroby'], '%d.%m.%Y')
    costume = Kostym.query.filter_by(id=id).first()
    if not costume:
        costume = Kostym(nazev=kwargs['nazev'],
                         vyrobce=kwargs['vyrobce'],
                         material=kwargs['material'],
                         popis=kwargs['popis'],
                         velikost=kwargs['velikost'],
                         datum_vyroby=cz_datetime.strftime("%Y-%m-%d"),
                         opotrebeni=kwargs['opotrebeni'],
                         pocet=kwargs['pocet'],
                         cena=kwargs['cena'],
                         obrazek=image,
                         barva=kwargs['barva'])
        session.add(costume)
        costume = session.query(Kostym).order_by(Kostym.id.desc()).first()

    else:
        costume.nazev = kwargs['nazev']
        costume.vyrobce = kwargs['vyrobce']
        costume.material = kwargs['material']
        costume.popis = kwargs['popis']
        costume.velikost = kwargs['velikost']
        costume.datum_vyroby = cz_datetime.strftime("%Y-%m-%d")
        costume.opotrebeni = kwargs['opotrebeni']
        costume.pocet = kwargs['pocet']
        costume.cena = kwargs['cena']
        costume.barva = kwargs['barva']
        if image:
            costume.obrazek = image
        session.add(costume)

        session.query(KostymVyuziti).filter_by(kostym_id=costume.id).delete()

    for usage in kwargs['vyuziti']:
        session.add(KostymVyuziti(vyuziti_id=usage, kostym_id=costume.id))
    session.commit()
Esempio n. 8
0
def create_order(*args, **kwargs):
    cz_datetime = datetime.strptime(kwargs['datum_vraceni'], '%d.%m.%Y')
    stmt = Vypujcka(
        nazev_akce=kwargs['nazev_akce'],
        vracen=0,
        datum_vypujceni=time.strftime("%Y-%m-%d"),
        datum_vraceni=cz_datetime.strftime("%Y-%m-%d"),
        klient=current_user.get_id(),
        zamestnanec=current_user.get_id(),
    )
    session.add(stmt)

    new_order_id = session.query(Vypujcka).order_by(Vypujcka.id.desc()).first()

    costumes_occurences = Counter(args[0]['costumes'])

    for item, occurence in costumes_occurences.items():

        stmt = VypujckaKostym(kostym_id=item,
                              vypujcka_id=new_order_id.id,
                              pocet=occurence)
        costume = session.query(Kostym).filter_by(id=item).first()
        costume.pocet -= occurence
        session.add(costume)
        session.add(stmt)

    accessories_occurences = Counter(args[0]['accessories'])

    for item, occurence in accessories_occurences.items():
        stmt = DoplnekVypujcka(doplnek_id=item,
                               vypujcka_id=new_order_id.id,
                               pocet=occurence)
        session.add(stmt)
        accessoory = session.query(Doplnek).filter_by(id=item).first()
        accessoory.pocet -= occurence
        session.add(accessoory)

    session.commit()
Esempio n. 9
0
def insert_base_users():
    stmt = Osoba(
        rc='9609255832',
        email='*****@*****.**',
        # Heslo123
        heslo=
        'pbkdf2:sha256:50000$qeDxpiht$e3f267714dc599d57ce7f6a10e55febb032e717d9561c1c501404c0d4c8ba9f6',
        jmeno='Tomas',
        prijmeni='Willaschek',
        ulice='',
        obec='',
        cislo_popisne='',
        tel_cislo='')
    session.add(stmt)
    session.commit()
    stmt = Klient(clenstvi='bronzove', osoba_rc='9609255832')
    session.add(stmt)
    stmt = Zamestnanec(osoba_rc='9609255832', pozice='vedouci')
    session.add(stmt)

    stmt = Osoba(
        rc='9610086548',
        email='*****@*****.**',
        # Heslo123
        heslo=
        'pbkdf2:sha256:50000$R1EGLREp$17c8154b3817009d26f14456dc54ae89f041e500c43ca011ecd5133c0763febf',
        jmeno='Dominik',
        prijmeni='Ruta',
        ulice='',
        obec='',
        cislo_popisne='',
        tel_cislo='')
    session.add(stmt)
    session.commit()
    stmt = Klient(clenstvi='bronzove', osoba_rc='9610086548')
    session.add(stmt)
    stmt = Zamestnanec(osoba_rc='9610086548', pozice='vedouci')
    session.add(stmt)

    session.commit()
Esempio n. 10
0
def delete_order(id):
    session.query(Vypujcka).filter(Vypujcka.id == id).delete()
    session.commit()
Esempio n. 11
0
def update_order(**kwargs):
    order = session.query(Vypujcka).filter_by(id=kwargs['id'][0]).first()
    order.vracen = kwargs['returned'][0]
    session.commit()
Esempio n. 12
0
def insert_use(*args, **kwargs):
    stmt = Vyuziti(druh_akce=kwargs['vyuziti'])
    session.add(stmt)
    session.commit()
Esempio n. 13
0
def delete_accessory(id):
    if id:
        session.query(Doplnek).filter_by(id=id).delete()
    session.commit()
Esempio n. 14
0
def delete_costume(id):
    if id:
        session.query(Kostym).filter_by(id=id).delete()
    session.commit()
Esempio n. 15
0
def delete_user(rc):
    session.query(Osoba).filter(Osoba.rc == rc).delete()
    session.commit()