You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.6 KiB
71 lines
2.6 KiB
from flask import Blueprint, json, request, url_for, Response, make_response, render_template
|
|
from database import db_session, init_db
|
|
from models import Warenkorb, Produkt, WarenkorbProdukt, Adresse
|
|
from sqlalchemy import func, desc, asc, or_
|
|
|
|
from datetime import datetime, timedelta, date
|
|
|
|
import requests
|
|
|
|
checkout_page = Blueprint('checkout_pages', __name__, url_prefix="/checkout", template_folder='templates')
|
|
|
|
def _convert_to_JSON(result):
|
|
"""Convert result object to a JSON web request."""
|
|
response = make_response(json.dumps(result))
|
|
response.headers['Access-Control-Allow-Origin'] = "*"
|
|
response.mimetype = "application/json"
|
|
return response
|
|
|
|
@checkout_page.route("/checkout", methods=['POST'])
|
|
def checkout():
|
|
netto = request.form.get('netto')
|
|
mwst = request.form.get('mwst')
|
|
brutto = request.form.get('brutto')
|
|
return render_template("checkout.html")
|
|
#if netto and mwst and brutto:
|
|
|
|
@checkout_page.route("/addaddress", methods=['POST'])
|
|
def addaddress():
|
|
name = request.form.get('name')
|
|
firma = request.form.get('firma')
|
|
uid = request.form.get('uid')
|
|
straße = request.form.get('straße')
|
|
plz = request.form.get('plz')
|
|
land = request.form.get('land')
|
|
user_id = request.form.get('user_id')
|
|
if plz and land and user_id and straße:
|
|
exist = Adresse.query.filter_by(user_id=user_id).filter_by(plz=plz).filter_by(strase=straße).first()
|
|
if exist:
|
|
return _convert_to_JSON("exist")
|
|
else:
|
|
newadresse = Adresse(user_id,name,firma,uid,straße,plz,land,datetime.now(),"1","1")
|
|
db_session.add(newadresse)
|
|
db_session.commit()
|
|
return _convert_to_JSON("success")
|
|
return _convert_to_JSON("fail")
|
|
|
|
@checkout_page.route("/getadress", methods=['POST'])
|
|
def getadress():
|
|
userid = request.form.get('userid')
|
|
if userid:
|
|
addressen = Adresse.query.filter_by(user_id=userid).all()
|
|
if addressen:
|
|
korb=dict()
|
|
i=0
|
|
for adresse in addressen:
|
|
if adresse.firma:
|
|
korb[i]=[adresse.name,adresse.firma, adresse.strase, adresse.plz + " " + adresse.land, adresse.uid]
|
|
else:
|
|
korb[i]=[adresse.name, adresse.strase, adresse.plz + " " + adresse.land, "", ""]
|
|
i=i+1
|
|
return _convert_to_JSON(korb)
|
|
return _convert_to_JSON("leer")
|
|
return _convert_to_JSON("fail")
|
|
|
|
@checkout_page.route("/order", methods=['POST'])
|
|
def order():
|
|
user_id = request.form.get('user_id')
|
|
warenkorb_id = request.form.get('warenkorb_id')
|
|
return user_id
|
|
return render_template("checkout.html")
|
|
#if netto and mwst and brutto:
|