示例#1
0
def toxml():
    from xml.etree.ElementTree import ElementTree,Element, SubElement, tostring
    from aplikace.models import  Product,Promena
    prom=Promena.query.filter_by(promena='cena').first()
    prom = float(prom.hodnota)
    root = Element('SHOP')

    for polozka in Product.all():
#    for polozka in Product.filter_by_Popis('3/8x4'):
        child = SubElement(root, "SHOPITEM")
        child_id_product = SubElement(child, "ID_PRODUCT")
        child_id_product.text = str(polozka.id)
        child_product_name = SubElement(child, "PRODUCT_NAME")
        child_product_name.text = polozka.Popis.encode('utf-8').decode('utf-8')
        child_category_text = SubElement(child, "CATEGORY_TEXT")
        child_category_text.text = str(polozka.Skupina[:2])
        child_description_short = SubElement(child, "DESCRIPTION_SHORT")
        description=polozka.Popis.encode('utf-8').decode('utf-8')
        if polozka.KL:
            description=description + '<br>Produktovy list viz.: <a href=' + polozka.KL+ '>Odkaz</a>'
        if polozka.TL:
            description=description + '<br>Technicky list viz.: <a href=' + polozka.TL+ '>Odkaz</a>'
        if polozka.Foto:
            description=description + '<br>Obrazek viz.: <a href=' + polozka.Foto+ '>Odkaz</a>'
        child_description_short.text = description
        child_manufacturer = SubElement(child, "MANUFACTURER")
        child_manufacturer.text = "Online"
        if polozka.Foto:
            child_img = SubElement(child, "IMG_URL")
            child_img.text = str(polozka.Foto)
        if polozka.CenaProdej == 0:
            child_price = SubElement(child, "PRICE")
            child_price.text = "Na dotaz"
        else:
            child_price = SubElement(child, "PRICE")
            child_price.text = str(polozka.CenaProdej*(100+prom)/100)

        child_vat = SubElement(child, "VAT")
        child_vat.text = "21"
        child_quantity = SubElement(child, "QUANTITY")
        child_quantity.text = str(polozka.sklad)
        child_ean = SubElement(child, "EAN")
        child_ean.text = str(polozka.UID)
        child_reference = SubElement(child, "REFERENCE")
        child_reference.text = str(polozka.Obj)
#        print root
#        tree = ElementTree(root)
#        tree.write('out.xml',xml_declaration=True,encoding='utf-8',method="xml")
    APP_DIR=dev_config.PROJECT_ROOT
    f = open(APP_DIR + '/app/static/vystup.xml','w')
    f.write(tostring(root)) # python will convert \n to os.linesep
    f.close()
#    return Response(tostring(root), mimetype='text/xml')
    return "Ok"
示例#2
0
def toxml():
    from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
    from aplikace.models import Product, Promena
    prom = Promena.query.filter_by(promena='cena').first()
    prom = float(prom.hodnota)
    root = Element('SHOP')

    for polozka in Product.all():
        #    for polozka in Product.filter_by_Popis('3/8x4'):
        child = SubElement(root, "SHOPITEM")
        child_id_product = SubElement(child, "ID_PRODUCT")
        child_id_product.text = str(polozka.id)
        child_product_name = SubElement(child, "PRODUCT_NAME")
        child_product_name.text = polozka.Popis.encode('utf-8').decode('utf-8')
        child_category_text = SubElement(child, "CATEGORY_TEXT")
        child_category_text.text = str(polozka.Skupina[:2])
        child_description_short = SubElement(child, "DESCRIPTION_SHORT")
        description = polozka.Popis.encode('utf-8').decode('utf-8')
        if polozka.KL:
            description = description + '<br>Produktovy list viz.: <a href=' + polozka.KL + '>Odkaz</a>'
        if polozka.TL:
            description = description + '<br>Technicky list viz.: <a href=' + polozka.TL + '>Odkaz</a>'
        if polozka.Foto:
            description = description + '<br>Obrazek viz.: <a href=' + polozka.Foto + '>Odkaz</a>'
        child_description_short.text = description
        child_manufacturer = SubElement(child, "MANUFACTURER")
        child_manufacturer.text = "Online"
        if polozka.Foto:
            child_img = SubElement(child, "IMG_URL")
            child_img.text = str(polozka.Foto)
        if polozka.CenaProdej == 0:
            child_price = SubElement(child, "PRICE")
            child_price.text = "Na dotaz"
        else:
            child_price = SubElement(child, "PRICE")
            child_price.text = str(polozka.CenaProdej * (100 + prom) / 100)

        child_vat = SubElement(child, "VAT")
        child_vat.text = "21"
        child_quantity = SubElement(child, "QUANTITY")
        child_quantity.text = str(polozka.sklad)
        child_ean = SubElement(child, "EAN")
        child_ean.text = str(polozka.UID)
        child_reference = SubElement(child, "REFERENCE")
        child_reference.text = str(polozka.Obj)
#        print root
#        tree = ElementTree(root)
#        tree.write('out.xml',xml_declaration=True,encoding='utf-8',method="xml")
    APP_DIR = dev_config.PROJECT_ROOT
    f = open(APP_DIR + '/app/static/vystup.xml', 'w')
    f.write(tostring(root))  # python will convert \n to os.linesep
    f.close()
    #    return Response(tostring(root), mimetype='text/xml')
    return "Ok"
示例#3
0
def data_ean13_update():

    from aplikace.models import Product
    #    from locale import atof
    from utils import ean13
    id = 0
    for polozka in Product.all():
        data = Product.find_by_id(polozka.id)
        data.UID = ean13()
        data.update(commit=False)
    db.session.commit()
    return True
示例#4
0
def data_ean13_update():


    from aplikace.models import Product
#    from locale import atof
    from utils import ean13
    id=0
    for polozka in Product.all():
            data=Product.find_by_id(polozka.id)
            data.UID=ean13()
            data.update(commit=False)
    db.session.commit()
    return True