commit ef51ee36ceb24685d41eba376b50e21788cdf9d7
parent 3320568abef7a031a86f7cc5666c6fa89de6266f
Author: Bebin Rockman <rob@radiorymd.com>
Date: Mon, 31 Oct 2022 23:48:23 +0200
yes
Diffstat:
12 files changed, 533 insertions(+), 258 deletions(-)
diff --git a/public_html/static/style.css b/public_html/static/style.css
@@ -121,19 +121,18 @@ table, tbody, tr, td
input, select
{
padding: 4px;
- color: #ff0000;
+ color: #666;
background-color: #111;
- font-size: 18px;
+ font-size: 16px;
border: 0px;
- width: 100%;
}
textarea
{
padding: 4px;
- color: #ff0000;
+ color: #666;
background-color: #111;
- font-size: 18px;
+ font-size: 16px;
border: 0px;
width: 100%;
height: 20px;
@@ -169,7 +168,7 @@ button
.orders
{
margin:0 auto;
- background-color:#345E5A;
+ background-color:#333;
font-weight: normal;
font-style: normal;
font-size: 15px;
@@ -183,6 +182,10 @@ button
border-radius:5px;
}
+.imgprod
+{
+ border-radius:5px;
+}
#payid
{
margin: 0px auto;
@@ -190,9 +193,8 @@ button
text-decoration: normal;
background-color: #111;
border: 0px;
- width: 20vw;
- height: 2vw;
- font-size: 1.5vw;
+ width: 100%;
+ font-size: 10px;
text-align: center;
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */
@@ -207,9 +209,9 @@ button
color: #888;
background-color: #111;
border: 0px;
- width: 45vw;
- height: 4vw;
- font-size: 1.5vw;
+ width: 100%;
+ height: 55px;
+ font-size: 10px;
text-align: center;
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */
diff --git a/public_html/templates/base.html b/public_html/templates/base.html
@@ -3,7 +3,7 @@ $def with (content)
<HEAD>
<meta charset="utf-8">
<title>Tarina web shop Welcome!</title>
- <link rel="stylesheet" href="/static/style.css?v=7.9" type="text/css" rel="stylesheet"/>
+ <link rel="stylesheet" href="/static/style.css?v=999.999" type="text/css" rel="stylesheet"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cache-control" content="no-cache">
</HEAD>
diff --git a/public_html/templates/checkout.html b/public_html/templates/checkout.html
@@ -1,27 +1,32 @@
-$def with (checkoutform, bag, b, productname, float, round, errormsg)
-$ tot = 0
+$def with (checkoutform,bag,productname,errormsg,db,getprice)
+$ totsats = 0
+$ toteuro = 0
<div id="container">
<div id="default">
<a href="/">go back</a>
<br>
<h2>Checkout</h2>
-$if bag != []:
- in your order:<br>
- $for i in bag:
- $code:
- price = i.quantity * float(i.price/100)
- $i.quantity x $productname(i.product)
- <a href="/dropitem/$i.product">X</a> $round(price,2)€<br>
- <img src="/static/img/$i.product/thumb/000.jpeg" style="width:120px"><br>
- $code:
- tot += price
-$if tot > 0:
+in your order:<br>
+$for i in bag:
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='" +i.product+"';")
+ $code:
+ price = getprice(i.product)
+ quantity = i.quantity
+ p_totsats=i.quantity*price[0]
+ p_toteuro=i.quantity*price[1]
+ $i.quantity x $productname(i.product)
+ <a href="/dropitem/$i.product">X</a> $p_totsats $p_toteuro€<br>
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$g.soundname" style="width:120px"><br>
+ $code:
+ totsats += p_totsats
+ toteuro += p_toteuro
+$if totsats > 0:
<br>
- total: $round(tot,2)€ or in real money $int(b.convert_to_btc(tot, 'EUR') * 100000000) Satoshi
+ total: $totsats Satoshi or $toteuro €
<br>
Order is only reserved once paid.
-If you choose NO-SHIPPING you will have to pick up the order yourself.
-<br>
<br>
<h2>$errormsg</h2>
<div id="addevent">
diff --git a/public_html/templates/goodies.html b/public_html/templates/goodies.html
@@ -0,0 +1,52 @@
+$def with (key,keys,productname,db,getprice)
+<div id="container">
+<div id="default">
+<a href="/">go back</a>
+<br>
+<h2>All Your Goodies!</h2>
+<br>
+
+$ totsats = 0
+$ toteuro = 0
+$if keys != []:
+ $for k in keys:
+ $ bags = db.query("SELECT * FROM paidbags WHERE sessionkey='"+k.invoice_key+"' ORDER BY timeadded DESC;")
+ $for i in bags:
+ $ invoice = db.select('invoices', where="invoice_key='"+i.sessionkey+"'")[0]
+ <div class="orders" id="$id">
+ $code:
+ price = getprice(i.product)
+ quantity = i.quantity
+ p_totsats=i.quantity*price[0]
+ p_toteuro=i.quantity*price[1]
+ $i.timeadded
+ <br>
+ $productname(i.product)<br>
+ status: $invoice.status<br>
+ $if invoice.status=='shipped':
+ $invoice.dateshipped
+ <br>
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='"+i.product+"';")
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$g.soundname" style="width:120px"><br>
+ $else:
+ <a href="/static/upload/$g.soundlink/$g.soundname">$g.soundname</a> <- Download file
+ <br>
+ $code:
+ totsats += p_totsats
+ toteuro += p_toteuro
+ </div>
+ <br>
+<br>
+total: $totsats Satoshi or $toteuro €<br>
+<br>
+Order is only reserved once paid.
+If you choose NO-SHIPPING you will have to pick up the order yourself.
+<br>
+<br>
+</div>
+<a href="/"><<<<<< back shoppin for more!!</a>
+</div>
+</div>
+</div>
diff --git a/public_html/templates/index.html b/public_html/templates/index.html
@@ -1,20 +1,24 @@
-$def with (products, b, bag, str, int, float, round, sessionkey, productname, inbag)
-$ tot = 0
+$def with (products,bag,sessionkey,productname,inbag,db,getprice,getrate)
+$ totsats = 0
+$ toteuro = 0
$ x = 0
$if sessionkey != 'empty':
<div id="bag">
<div id="insidebag">
- in your order (click to remove):
+ in your order:<br>
$for i in bag:
$code:
- price = i.quantity * float(i.price/100)
- $#<img src="/static/img/$i.product/thumb/000.jpeg" style="width:50px">
- <div id="prod">$i.quantity x $productname(i.product)
- <a href="/dropitem/$i.product">X</a> $round(price,2)€</div>
+ price = getprice(i.product)
+ quantity = i.quantity
+ p_totsats=i.quantity*price[0]
+ p_toteuro=i.quantity*price[1]
+ $i.quantity x $productname(i.product)
+ <a href="/dropitem/$i.product">X</a> $p_totsats $p_toteuro€<br>
$code:
- tot += price
- $if tot > 0:
- total: $round(tot,2)€ or in real money $int(b.convert_to_btc(tot, 'EUR') * 100000000) Satoshi
+ totsats += p_totsats
+ toteuro += p_toteuro
+ $if totsats > 0:
+ total: $totsats Satoshi or $toteuro €
<a href="/checkout">Checkout</a>
</div>
</div>
@@ -35,18 +39,20 @@ $if sessionkey != 'empty':
<div id="productlist">
$for i in products:
<div class="product" id="$i.id">
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='" +i.id+"';")
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <a href="/bigpic/$g.id"><img class="imgprod" src="/static/img/thumb/$g.soundname"></a>
$code:
- sat = str(int(b.convert_to_btc(i.price/100, 'EUR') * 100000000))
+ sat, euro = getprice(i.id)
<h2>
$i.name
</h2>
<p>$i.description</p>
- $for p in i.images:
- <a href="/bigpic/$i.id?pic=$p"><img src="/static/img/$i.id/thumb/$p"></a>
<br>
$if i.available > 0:
- Price $sat Satoshi ~ $("%1.2f" % float(i.price/100))€ <a href="?putinbag=$i.id#$i.id">order</a><br>
- Available $str(i.available) pcs
+ Price $sat Satoshi ~ $euro € <a href="?putinbag=$i.id#$i.id">order</a><br>
+ Available $i.available pcs
$else:
SOLD OUT! check back later.
</div>
@@ -55,7 +61,7 @@ $for i in products:
<br>
</div>
<p></p>
-<h3>rate is $int(b.get_latest_price('EUR'))€/btc</h4>
+<h4>$getrate()€/₿</h4>
<small>powered by <a href="https://github.com/ElementsProject/lightning">c-lightning</a>, <a href="https://github.com/Ride-The-Lightning/c-lightning-REST">c-lightning-REST</a> and <a href="https://webpy.org">web.py </a></small>
<br>
<br>
diff --git a/public_html/templates/op.html b/public_html/templates/op.html
@@ -3,7 +3,7 @@ $def with (content)
<HEAD>
<meta charset="utf-8">
<title>Tarina web shop Welcome!</title>
- <link rel="stylesheet" href="/static/style.css?v=8.9" type="text/css" rel="stylesheet"/>
+ <link rel="stylesheet" href="/static/style.css?v=9.99" type="text/css" rel="stylesheet"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cache-control" content="no-cache">
</HEAD>
diff --git a/public_html/templates/orders.html b/public_html/templates/orders.html
@@ -1,5 +1,4 @@
-$def with (payments,db,getinvoice,totsats,status,paid,unpaid,shipped,nonshipped,pickup,removed,productname,round)
-$var payments = payments
+$def with (payments,db,getinvoice,totsats,status,paid,unpaid,shipped,nonshipped,pickup,removed,productname,getprice)
$ link = ''
<h2>Orders</h2>
<h4>total $totsats</h4>
@@ -16,14 +15,16 @@ $ link = ''
<a href="?status=removed">removed</a>
<a href="?status=thankyou">thankyou</a>
$ id=0
+$ totsats=0
+$ toteuro=0
$for i in payments:
$ id=id+1
$if i.status == status:
<div class="orders" id="$id">
<pre>
$ bag = db.query("SELECT * FROM paidbags WHERE sessionkey='" + i.invoice_key +"';")
- $ pending = db.select('pending', where="invoice_key='" + i.invoice_key + "'", what='country, firstname, lastname, address, town, postalcode, email')[0]
- $ invoice = db.select('invoices', where="invoice_key='"+i.invoice_key+"'", what='invoice_key, btc, ln, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped')[0]
+ $ pending = db.select('pending', where="invoice_key='"+i.invoice_key+"'")[0]
+ $ invoice = db.select('invoices', where="invoice_key='"+i.invoice_key+"'")[0]
$ ln = getinvoice(i.ln)
$if i.payment == 'Bitcoin':
$ link = "/paybtc/" + i.invoice_key
@@ -40,10 +41,24 @@ $for i in payments:
in your order:<br>
$ total = 0
$for b in bag:
- $ price = b.quantity * float(b.price/100)
- $ total = total + price
- $b.quantity x $productname(b.product) $round(price,2)€ <br>
- <img src="/static/img/$b.product/thumb/000.jpeg" style="width:120px"><br>
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='"+b.product+"';")
+ $code:
+ price = getprice(b.product)
+ quantity = b.quantity
+ p_totsats=b.quantity*price[0]
+ p_toteuro=b.quantity*price[1]
+ $b.quantity x $productname(b.product)
+ <a href="/dropitem/$b.product">X</a> $p_totsats $p_toteuro€<br>
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$g.soundname" style="width:120px"><br>
+ $code:
+ totsats += p_totsats
+ toteuro += p_toteuro
+ $if totsats > 0:
+ <br>
+ total: $totsats Satoshi or $toteuro €
+
Satoshis: $i.totsats
order $i.timestamp
$pending.email
diff --git a/public_html/templates/orders2.html b/public_html/templates/orders2.html
@@ -0,0 +1,75 @@
+$def with (payments,db,getinvoice,totsats,status,paid,unpaid,shipped,nonshipped,pickup,removed,productname,getprice)
+$ link = ''
+<h2>Orders</h2>
+<h4>total $totsats</h4>
+<p>paid $paid</p>
+<p>shipped $shipped</p>
+<p>pickup $pickup</p>
+<p>unpaid $unpaid</p>
+<p>removed $removed</p>
+<h3>waiting to be shipped $nonshipped</h3>
+<a href="?status=unpaid">unpaid</a>
+<a href="?status=paid">paid</a>
+<a href="?status=shipped">shipped</a>
+<a href="?status=pickup">pickup</a>
+<a href="?status=removed">removed</a>
+<a href="?status=thankyou">thankyou</a>
+$ id=0
+$ totsats=0
+$ toteuro=0
+$for i in payments:
+ $ id=id+1
+ $if i.status == status:
+ <div class="orders" id="$id">
+ <pre>
+ $ bag = db.query("SELECT * FROM paidbags WHERE sessionkey='" + i.invoice_key +"';")
+ $ pending = db.select('pending', where="invoice_key='"+i.invoice_key+"'")[0]
+ $ invoice = db.select('invoices', where="invoice_key='"+i.invoice_key+"'")[0]
+ $ ln = getinvoice(i.ln)
+ $if i.payment == 'Bitcoin':
+ $ link = "/paybtc/" + i.invoice_key
+ $if i.payment == 'Bitcoin Lightning':
+ $ link = "/payln/" + i.invoice_key
+ <b>order status: $i.status</b>
+ <b>ln status: $ln['status']</b>
+ <a href=$link>$i.invoice_key</a>
+ $ln['msatoshi'] mSatoshis
+ $if ln['status'] == 'paid':
+ $ totsats=totsats+ln['msatoshi']
+ $i.payment
+ $i.ln
+ in your order:<br>
+ $ total = 0
+ $for b in bag:
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='"+b.product+"';")
+ $code:
+ price = getprice(b.product)
+ quantity = b.quantity
+ p_totsats=b.quantity*price[0]
+ p_toteuro=b.quantity*price[1]
+ $b.quantity x $productname(b.product)
+ <a href="/dropitem/$b.product">X</a> $p_totsats $p_toteuro€<br>
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$g.soundname" style="width:120px"><br>
+ $code:
+ totsats += p_totsats
+ toteuro += p_toteuro
+ $if totsats > 0:
+ <br>
+ total: $totsats Satoshi or $toteuro €
+
+ Satoshis: $i.totsats
+ order $i.timestamp
+ $pending.email
+ $pending.firstname $pending.lastname
+ $if pending.country != 'NO-SHIPPING':
+ $pending.address
+ $pending.postalcode
+ $pending.town
+ $pending.country
+ </pre>
+ <a href='/orders?status=thankyou&key=$i.invoice_key'>thank you</a> | <a href='/orders?status=shipped&key=$i.invoice_key'>shipped</a> | <a href='/orders?status=paid&key=$i.invoice_key'>paid</a> | <a href='/orders?status=pickup&key=$i.invoice_key'>pickup</a> |<a href='/orders?status=paynotice&key=$i.invoice_key'>payment notice</a> | <a href='/orders?status=removed&key=$i.invoice_key'>remove</a>
+ </div>
+ <br>
+
diff --git a/public_html/templates/payln.html b/public_html/templates/payln.html
@@ -1,4 +1,4 @@
-$def with (lninvoice, invoice, bag, productname, float, round)
+$def with (lninvoice,invoice,bag,productname,digitalkey,db,getprice,getrate)
$ qr = '/static/qr/' + invoice['invoice_key'] + '.png'
<script>
function copy() {
@@ -8,28 +8,42 @@ function copy() {
}
</script>
+<div id="container">
$if lninvoice['status'] != 'paid':
<meta http-equiv="refresh" content="30" />
<a href="/checkout">Go back!</a>
<br>
<h2>Pay with Bitcoin Lightning</h2>
$else:
- <h2>Payment recieved!</h2><br>
+ <h2>Payment recieved!</h2>
+ $if digitalkey:
+ <p>link to your digital goodies is in your mail!</p><br>
<img src="/static/jamesfrancothanks.gif" style="width:300px"><br>
<a href="/">Back to beginning</a>
<br>
in your order:<br>
-$ total = 0
+$ totsats=0
+$ toteuro=0
$for i in bag:
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='" +i.product+"';")
$code:
- price = i.quantity * float(i.price/100)
- total = total + price
- $i.quantity x $productname(i.product) $round(price,2)€ <br>
- <img src="/static/img/$i.product/thumb/000.jpeg" style="width:120px"><br>
-
-<h4>Total: € $float(invoice.amount/100)</h4>
-<h4>$invoice.totsats Satoshi</h4>
-<h2>status: $lninvoice['status']</h2>
+ price = getprice(i.product)
+ quantity = i.quantity
+ p_totsats=i.quantity*price[0]
+ p_toteuro=i.quantity*price[1]
+ $i.quantity x $productname(i.product)
+ $p_totsats $p_toteuro€<br>
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$g.soundname" style="width:120px"><br>
+ $code:
+ totsats += p_totsats
+ toteuro += p_toteuro
+$if totsats > 0:
+ <br>
+ total: $totsats Satoshi or $toteuro €<br>
+ with rate: $getrate()€/₿
+ <h2>status: $lninvoice['status']</h2>
<br>
<img src="$qr">
<div id='hash'>
@@ -45,4 +59,5 @@ $lninvoice['bolt11']
<button id="copybutton" onclick="copy()">Copy</button>
<button id="backbutton" autofocus onclick="parent.location='/paybtc/$invoice.invoice_key'">Pay with Bitcoin on-chain</button>
</div>
+</div>
diff --git a/public_html/templates/pending.html b/public_html/templates/pending.html
@@ -1,31 +1,44 @@
-$def with (pending_key, pendingform, pendinginfo, shippinginfo, bag, b, productname, float, round)
-$ tot = 0
+$def with (pending_key,pendingform,pendinginfo,bag,productname,db,getprice,eur_to_sat,ordertype)
+$ totsats = 0
+$ toteuro = 0
<div id="container">
<div id="default">
<a href="/checkout">Go back!</a>
<br>
<h2>Checkout</h2>
-$if bag != []:
- in your order:<br>
- $for i in bag:
- $code:
- price = i.quantity * float(i.price/100)
- $i.quantity x $productname(i.product)
- <a href="/dropitem/$i.product">X</a> $round(price,2)€<br>
- <img src="/static/img/$i.product/thumb/000.jpeg" style="width:120px"><br>
- $code:
- tot += price
+in your order:<br>
+$for i in bag:
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='" +i.product+"';")
+ $code:
+ price = getprice(i.product)
+ quantity = i.quantity
+ p_totsats=i.quantity*price[0]
+ p_toteuro=i.quantity*price[1]
+ $i.quantity x $productname(i.product)
+ <a href="/dropitem/$i.product">X</a> $p_totsats $p_toteuro€<br>
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$g.soundname" style="width:120px"><br>
+ $code:
+ totsats += p_totsats
+ toteuro += p_toteuro
+$if totsats > 0:
+ <br>
+ total: $totsats Satoshi or $toteuro €
+
<br>
Order is only reserved once paid.
<br>
-$if pendinginfo.country == 'NO-SHIPPING':
- No shipping selected, be sure to pick up item yaself okey.
+$if ordertype() == 'digital':
+ <h4>Digital goods will be shipped to your email once invoice paid..</h4>
$else:
- Shipping cost to $pendinginfo.country is $float(shippinginfo.price/100)€ <br>
+ $ shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days')[0]
+ Shipping cost to $pendinginfo.country is $eur_to_sat(shippinginfo.price) Satoshi $(shippinginfo.price/100)€ <br>
Shipping estimate is $shippinginfo.days days<br>
$code:
- tot += float(shippinginfo.price/100)
+ totsats += eur_to_sat(shippinginfo.price)
+ toteuro += shippinginfo.price/100
<pre>
First Name: $pendinginfo.firstname
Last Name: $pendinginfo.lastname
@@ -38,8 +51,8 @@ $else:
<br>
<h3>
-$if tot > 0:
- total: $(tot)€ or in real money $int(b.convert_to_btc(tot, 'EUR') * 100000000) Satoshi
+$if totsats > 0:
+ total: $totsats Satosi $(toteuro)€
</h3>
<br>
<a href="/checkout">Go back!</a>
diff --git a/public_html/templates/products.html b/public_html/templates/products.html
@@ -1,4 +1,4 @@
-$def with (addproduct, listproducts, productimages, idvalue)
+$def with (addproduct, listproducts, goodies, idvalue)
<div id="container">
<div id="default">
<br>
@@ -14,11 +14,19 @@ $:addproduct.render()
</form>
<a href='/products/$idvalue?cmd=del&id=$idvalue'>remove product</a>
<br>
-$for i in productimages:
- <img src="/static/img/$idvalue/thumb/$i">
- <a href='/products/$idvalue?cmd=removeimg&img=$i'>remove</a>
+<hr>
+$if goodies != None:
+ $for i in goodies:
+ $if i.soundname[-5:] == '.jpeg' or i.soundname[-4:] == '.png':
+ <img src="/static/img/thumb/$i.soundname">
+ $else:
+ <p>$i.soundname</p>
+ <br>
+ <a href='/products/$idvalue?cmd=remove&soundname=$i.soundname'>remove</a>
+ <br>
+ <hr>
<form method="POST" enctype="multipart/form-data" action="">
-Image(jpeg): <input type="file" name="imgfile"/> <br>
+<input type="file" name="imgfile"/> <br>
<br/>
<input name="upload", type="submit" value="upload" />
</form>
diff --git a/server.py b/server.py
@@ -26,6 +26,7 @@ urls = (
'/putinbag/(.*)', 'putinbag',
'/dropitem/(.*)?', 'dropitem',
'/payln/(.*)', 'payln',
+ '/goodies/(.*)', 'goodies',
'/lightning?', 'lightning',
'/paybtc/(.*)', 'paybtc',
'/payment/(.*)', 'payment',
@@ -73,6 +74,9 @@ renderop = web.template.render(templatedir, base="op")
db = web.database(dbn='sqlite', db=basedir + "db/cyberpunkcafe.db")
session = web.session.Session(app,store,initializer={'login':0, 'privilege':0, 'bag':[], 'sessionkey':'empty'})
+
+allowedchar = '_','-','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'
+
#----------- Database setup -------------
#Remeber to store Euros in cents
@@ -141,6 +145,7 @@ def dropitems(d):
db.update('customerbag', where="sessionkey='" + session.sessionkey +"' and product='"+str(i.id)+"'", quantity=product.quantity-1)
else:
db.query("DELETE FROM customerbag WHERE sessionkey='" + session.sessionkey +"' AND product='"+str(i.id)+"';")
+ return 'empty'
def addtobag(p):
i = getproduct(p)
@@ -154,7 +159,7 @@ def addtobag(p):
db.update('customerbag', where="sessionkey='" + session.sessionkey +"' and product='"+str(i.id)+"'", quantity=product.quantity+1)
print('gwtdafaakouttahere')
else:
- db.insert('customerbag', sessionkey=session.sessionkey, product=i.id, price=i.price, quantity=1, timeadded=datetime.datetime.now())
+ db.insert('customerbag', sessionkey=session.sessionkey, product=i.id, type=i.type, currency=i.currency, price=i.price, quantity=1, timeadded=datetime.datetime.now())
def productname(productid):
try:
@@ -170,6 +175,14 @@ def getproduct(productid):
return ''
return product
+def ordertype():
+ physical=False
+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
+ for b in bag:
+ if b.type=='physical':
+ return 'physical'
+ return 'digital'
+
def getavailable(productid):
try:
name = db.query("SELECT available FROM products WHERE id='"+str(productid)+"';")[0]
@@ -177,6 +190,32 @@ def getavailable(productid):
return ''
return name.available
+def getprice(productid):
+ p = db.query("SELECT * FROM products WHERE id='"+str(productid)+"';")[0]
+ b = BtcConverter()
+ if p.currency=='euro':
+ sat = b.convert_to_btc(p.price/100, 'EUR')
+ euro = p.price
+ if p.currency=='bitcoin':
+ euro = b.convert_btc_to_cur(p.price/100000000,'EUR')
+ sat = p.price
+ return int(sat), round(euro,2)
+
+def btc_to_eur(amount):
+ b = BtcConverter()
+ euro = round(b.convert_btc_to_cur(amount/100000000,'EUR'),2)
+ return euro
+
+def eur_to_sat(amount):
+ b = BtcConverter()
+ btc = b.convert_to_btc(amount/100, 'EUR')
+ sat=btc*100000000
+ return int(sat)
+
+def getrate():
+ b = BtcConverter()
+ return int(b.get_latest_price('EUR'))
+
def checkforoldbags():
print('checking for old bags')
bags = db.select('customerbag')
@@ -251,31 +290,14 @@ class index():
if session.sessionkey == 'empty':
session.sessionkey = hashlib.sha256(str(random.getrandbits(256)).encode('utf-8')).hexdigest()[15:35]
if i.dropitem != None:
- session.bag = dropitems(int(i.dropitem))
+ session.bag = dropitems(i.dropitem)
print(session.bag)
if i.putinbag != None:
addtobag(i.putinbag)
return web.seeother('/#' + i.putinbag)
print('Cyberpunk cafe')
#print(session.bag)
- b = BtcConverter()
- listproducts = db.query("SELECT * FROM products ORDER BY priority DESC")
- imgfiles = []
- products = []
- # Search product images
- for i in listproducts:
- productimages = ['']
- imgdir = staticdir + 'img/' + str(i.id) + '/web/'
- try:
- productimages = sorted(os.listdir(imgdir))
- if len(productimages) == 0:
- productimages = ['']
- print(productimages)
- except FileNotFoundError:
- print('No product images')
- pass
- i.update({'images':productimages})
- products.append(i)
+ products = db.query("SELECT * FROM products ORDER BY priority DESC")
try:
bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
except:
@@ -287,7 +309,7 @@ class index():
inbag = None
if inbag < 1:
session.sessionkey = 'empty'
- return render.index(products, b, bag, str, int, float, round, session.sessionkey, productname, inbag)
+ return render.index(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate)
class putinbag:
def GET(self, p):
@@ -296,10 +318,13 @@ class putinbag:
class dropitem():
def GET(self, d):
+ referer = web.ctx.env.get('HTTP_REFERER', 'none')
p = web.input()
i = 0
- dropitems(int(d))
- return web.seeother('/#'+d)
+ empty=dropitems(d)
+ if empty=='empty':
+ return web.seeother('/')
+ return web.seeother(referer)
class bigpic():
def GET(self, i):
@@ -316,7 +341,7 @@ class checkout():
for i in shippingcountries:
if i.country != 'NO-SHIPPING':
t.append(i.country)
- form = web.form.Form(
+ shipping = web.form.Form(
web.form.Textbox('email', web.form.notnull, description="Email:"),
web.form.Dropdown('country', t, web.form.notnull, description="Country"),
web.form.Textbox('firstname', web.form.notnull, description="First Name:"),
@@ -325,34 +350,51 @@ class checkout():
web.form.Textbox('town', web.form.notnull, description="Town / City:"),
web.form.Textbox('postalcode', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Postalcode / zip"),
web.form.Button('Calculate shipping cost'))
+ email = web.form.Form(
+ web.form.Textbox('email', web.form.notnull, description="Email:"),
+ web.form.Button('Okey, lets do it!'))
def GET(self):
- errormsg=''
- #checkavailable()
i = web.input(error=None)
+ pendinginfo = getpendinginfo()
+ if ordertype()=='digital':
+ checkoutform = self.email()
+ if pendinginfo:
+ checkoutform.fill(email=pendinginfo.email)
+ if ordertype()=='physical':
+ checkoutform = self.shipping()
+ if pendinginfo:
+ checkoutform.fill(country=pendinginfo.country, firstname=pendinginfo.firstname, lastname=pendinginfo.lastname, address=pendinginfo.address, town=pendinginfo.town, postalcode=pendinginfo.postalcode, email=pendinginfo.email)
+ errormsg=''
if i.error == 'mail':
errormsg = 'Check your mail!'
if i.error == 'shipping':
errormsg = 'Check your shipping address!'
- checkoutform = self.form()
- pendinginfo = getpendinginfo()
- if pendinginfo:
- checkoutform.fill(country=pendinginfo.country, firstname=pendinginfo.firstname, lastname=pendinginfo.lastname, address=pendinginfo.address, town=pendinginfo.town, postalcode=pendinginfo.postalcode, email=pendinginfo.email)
- b = BtcConverter()
bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
- return render.checkout(checkoutform,bag,b,productname,float,round,errormsg)
+ return render.checkout(checkoutform,bag,productname,errormsg,db,getprice)
def POST(self):
+ physical=False
+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
+ checkoutform = self.email()
+ for b in bag:
+ if b.type=='physical':
+ checkoutform = self.shipping()
+ physical=True
+ break
errormsg=''
- checkoutform = self.form()
pendinginfo = getpendinginfo()
i = web.input()
if pendinginfo:
- db.update('pending', where="invoice_key='"+session.sessionkey+"'", invoice_key=session.sessionkey, country=i.country, firstname=i.firstname, lastname=i.lastname, address=i.address, town=i.town, postalcode=str(i.postalcode), email=i.email, dateadded=datetime.datetime.now())
+ if physical==True:
+ db.update('pending', where="invoice_key='"+session.sessionkey+"'", invoice_key=session.sessionkey, country=i.country, firstname=i.firstname, lastname=i.lastname, address=i.address, town=i.town, postalcode=str(i.postalcode), email=i.email, dateadded=datetime.datetime.now())
+ else:
+ db.update('pending', where="invoice_key='"+session.sessionkey+"'", invoice_key=session.sessionkey, email=i.email, dateadded=datetime.datetime.now())
else:
- db.insert('pending', invoice_key=session.sessionkey, country=i.country, firstname=i.firstname, lastname=i.lastname, address=i.address, town=i.town, postalcode=str(i.postalcode), email=i.email, dateadded=datetime.datetime.now())
- if i.country != 'NO-SHIPPING':
- if not checkoutform.validates():
- b = BtcConverter()
- return web.seeother('/checkout?error=shipping')
+ if physical==True:
+ db.insert('pending', invoice_key=session.sessionkey, country=i.country, firstname=i.firstname, lastname=i.lastname, address=i.address, town=i.town, postalcode=str(i.postalcode), email=i.email, dateadded=datetime.datetime.now())
+ else:
+ db.insert('pending', invoice_key=session.sessionkey, email=i.email, dateadded=datetime.datetime.now())
+ if not checkoutform.validates():
+ return web.seeother('/checkout?error=shipping')
if '@' not in i.email:
web.seeother('/checkout?error=mail')
else:
@@ -363,81 +405,96 @@ class pending:
web.form.Dropdown('payment', ['Bitcoin Lightning', 'Bitcoin'], web.form.notnull, description="Select payment method"),
web.form.Button('Pay'))
def GET(self):
- #checkavailable()
pendingform = self.form()
pendinginfo = getpendinginfo()
- if pendinginfo:
- shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days')[0]
- b = BtcConverter()
bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
- return render.pending(session.sessionkey, pendingform, pendinginfo, shippinginfo, bag, b, productname, float, round)
+ return render.pending(session.sessionkey,pendingform,pendinginfo,bag,productname,db,getprice,eur_to_sat,ordertype)
def POST(self):
pendingform = self.form()
pendinginfo = getpendinginfo()
- if pendinginfo:
+ i = web.input()
+
+ #Calculate total amount of bag
+ totalamount = 0
+ description = ''
+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
+ comma = ''
+ for s in bag:
+ totalamount += getprice(s.product)[0] * s.quantity
+ description += comma + str(s.quantity) + ' x ' + productname(s.product)
+ comma = ', '
+ if ordertype()=='physical':
shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days')[0]
- i = web.input()
- #if session.bag != []:
- totalamount = 0
- description = ''
- bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';")
- comma = ''
- for s in bag:
- totalamount += s.price * s.quantity
- description += comma + str(s.quantity) + ' x ' + productname(s.product)
- comma = ', '
- totalamount += shippinginfo.price
- b = BtcConverter()
- totsats = int(b.convert_to_btc(float(totalamount/100), 'EUR') * 100000000)
- totbtc = int(b.convert_to_btc(float(totalamount/100), 'EUR'))
- print(str(totalamount) + ' | ' + description)
- print(str(totsats) + ' | ' + description)
- #make lightning invoice
- label = hashlib.sha256(str(random.getrandbits(64)).encode('utf-8')).hexdigest()[15:35]
- invoice = createinvoice(totsats, description, label)
- time.sleep(1)
- #print(invoice)
- callsubprocess('qrencode -s 3 -o '+ staticdir + 'qr/' + session.sessionkey+'.png '+invoice['bolt11'])
- #make bitcoin address
- bitcoinrpc = AuthServiceProxy(rpcauth)
- newaddress = bitcoinrpc.getnewaddress('Tarina Shop Butik')
- bitcoinrpc = None
- btcuri = 'bitcoin:' + newaddress + '?amount=' + str(totbtc) + '&label=' + description
- callsubprocess('qrencode -s 5 -o '+ staticdir + 'qr/' + newaddress +'.png ' + btcuri)
- try:
- db.query("DELETE FROM invoices WHERE invoice_key='"+session.sessionkey+"';")
- except:
- print('no old invoices to delete')
- db.insert('invoices', invoice_key=session.sessionkey, btc=newaddress, ln=label, products=description, payment=i.payment, amount=totalamount, totsats=totsats, timestamp=time.strftime('%Y-%m-%d %H:%M:%S'))
- # send mail to op
- msg = 'You got a new order, from ' + pendinginfo.firstname + ' ' + pendinginfo.lastname + ' from ' + pendinginfo.country + ' email: ' + pendinginfo.email + ' this dude wantz ' + description + ' for ' + str(int(totalamount/100)) + '€ ' + ' with ' + i.payment
- sendmail(webmaster, 'Tarina Shop', msg)
- # send mail to customer
- if i.payment == 'Bitcoin':
- paymentlink = '/paybtc/'
- if i.payment == 'Bitcoin Lightning':
- paymentlink = '/payln/'
- if pendinginfo.email != '':
- msg = "Thank you for order " + description + " at Tarina shop, we'll be processing your order as soon as possible and send it to " + pendinginfo.firstname + ' ' + pendinginfo.lastname + ', ' + pendinginfo.address + ', ' + str(pendinginfo.postalcode) + ', ' + pendinginfo.town + ', ' + pendinginfo.country + '. To pay/view status of your order please visit ' + baseurl + paymentlink + session.sessionkey
- sendmail(pendinginfo.email, 'Tarina Shop', msg)
- if i.payment == 'Bitcoin':
- return web.seeother('/paybtc/' + session.sessionkey)
- if i.payment == 'Bitcoin Lightning':
- return web.seeother('/payln/' + session.sessionkey)
- else:
- return web.seeother('/')
+ totalamount += eur_to_sat(shippinginfo.price)
+ totsats=totalamount
+ totbtc=totsats/100000000
+
+ #make lightning invoice
+ print(str(totalamount) + ' | ' + description)
+ print(str(totsats) + ' | ' + description)
+ label = hashlib.sha256(str(random.getrandbits(64)).encode('utf-8')).hexdigest()[15:35]
+ invoice = createinvoice(totsats, description, label)
+ time.sleep(1)
+ #print(invoice)
+ callsubprocess('qrencode -s 3 -o '+ staticdir + 'qr/' + session.sessionkey+'.png '+invoice['bolt11'])
+ #make bitcoin address
+ bitcoinrpc = AuthServiceProxy(rpcauth)
+ newaddress = bitcoinrpc.getnewaddress('Tarina Shop Butik')
+ bitcoinrpc = None
+ btcuri = 'bitcoin:' + newaddress + '?amount=' + str(totbtc) + '&label=' + description
+ callsubprocess('qrencode -s 5 -o '+ staticdir + 'qr/' + newaddress +'.png ' + btcuri)
+ try:
+ db.query("DELETE FROM invoices WHERE invoice_key='"+session.sessionkey+"';")
+ except:
+ print('no old invoices to delete')
+ db.insert('invoices', invoice_key=session.sessionkey, btc=newaddress, ln=label, products=description, payment=i.payment, amount=totalamount, totsats=totsats, timestamp=time.strftime('%Y-%m-%d %H:%M:%S'))
+ if i.payment == 'Bitcoin':
+ return web.seeother('/paybtc/' + session.sessionkey)
+ if i.payment == 'Bitcoin Lightning':
+ return web.seeother('/payln/' + session.sessionkey)
+ return web.seeother('/')
class payln:
def GET(self, invoice_key):
- #checkavailable()
- invoice = db.select('invoices', where="invoice_key='"+invoice_key+"'", what='invoice_key, btc, ln, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped')[0]
- bag = db.query("SELECT * FROM customerbag WHERE sessionkey='"+invoice_key+"';")
+ digitalkey = None
+ invoice = db.select('invoices', where="invoice_key='"+invoice_key+"'")[0]
lninvoice = getinvoice(invoice['ln'])
- if lninvoice['status'] == 'paid':
+ if lninvoice['status'] == 'paid' and session.sessionkey != 'empty':
+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='"+invoice_key+"';")
+ customer = db.select('pending', where="invoice_key='"+invoice_key+"'")[0]
db.query("INSERT INTO paidbags SELECT * FROM customerbag WHERE sessionkey='" + invoice_key + "'")
db.query("DELETE FROM customerbag WHERE sessionkey='" + invoice_key + "'")
+ db.update("invoices",where='invoice_key="'+invoice_key+'"', status='paid')
+ digitalkey=hashlib.sha256(str(random.getrandbits(256)).encode('utf-8')).hexdigest()[15:35]
+ db.insert('digitalkey', invoice_key=invoice_key, digitalkey=digitalkey, email=customer.email)
session.sessionkey = 'empty'
- return render.payln(lninvoice, invoice, bag, productname, float, round)
+ # send mail to op
+ if ordertype()=='physical':
+ msg = 'You got a new order, from ' + customer.firstname + ' ' + customer.lastname + ' from ' + customer.country + ' email: ' + customer.email + ' this dude wantz ' + lninvoice['description']
+ else:
+ msg='sup?'
+ sendmail(webmaster, 'Tarina Shop', msg)
+ # send mail to customer
+ if ordertype()=='physical':
+ msg = "Thank you for order " + lninvoice['description'] + " at Tarina shop, we'll be processing your order as soon as possible and send it to " + customer.firstname + ' ' + customer.lastname + ', ' + customer.address + ', ' + str(customer.postalcode) + ', ' + customer.town + ', ' + customer.country + '. To pay/view status or take a look at the digital goodies of your order please visit ' + baseurl + '/goodies/'+digitalkey
+ else:
+ msg='sup? goto '+baseurl+'/goodies/'+digitalkey
+ sendmail(customer.email, 'Tarina Shop', msg)
+ web.seeother('/payln/'+invoice_key)
+ if lninvoice['status'] == 'paid':
+ bag = db.query("SELECT * FROM paidbags WHERE sessionkey='"+invoice_key+"';")
+ digitalkey = db.select('digitalkey', where="invoice_key='"+invoice_key+"'")[0]
+ if lninvoice['status'] != 'paid':
+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='"+invoice_key+"';")
+ return render.payln(lninvoice,invoice,bag,productname,digitalkey,db,getprice,getrate)
+
+class goodies():
+ def GET(self, digitalkey):
+ digitalkey = db.select('digitalkey', where="digitalkey='"+digitalkey+"'")[0]
+ #digitalkeys = db.select('digitalkey', where="email='"+digitalkey.email+"'")
+ digitalkeys = db.query("SELECT * FROM digitalkey WHERE email='"+digitalkey.email+"' ORDER BY timeadded DESC;")
+ return render.goodies(digitalkey,digitalkeys,productname,db,getprice)
+ #check all puraches with same email fuck ye
class paybtc:
def GET(self, invoice_key):
@@ -520,8 +577,8 @@ class orders():
unpaid=unpaid+1
if i.status == "removed":
removed=removed+1
- payments = db.select('invoices', what='btc, ln, invoice_key, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped', order='timestamp DESC')
- return renderop.orders(payments,db,getinvoice,totsats,status,paid,unpaid,shipped,nonshipped,pickup,removed,productname,round)
+ payments = db.select('invoices', order='timestamp DESC')
+ return renderop.orders(payments,db,getinvoice,totsats,status,paid,unpaid,shipped,nonshipped,pickup,removed,productname,getprice)
class payment:
def GET(self, invoice_key):
@@ -599,53 +656,56 @@ class products:
web.form.Dropdown('category', p, web.form.notnull, description="Category:"),
web.form.Textbox('name', web.form.notnull, description="Name:"),
web.form.Textarea('description', web.form.notnull, description="Description:"),
- web.form.Textbox('price', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Price in cents"),
+ web.form.Radio('type', ['digital', 'physical'],description="Type:"),
+ web.form.Radio('currency', ['euro', 'bitcoin'],description="Currency:"),
+ web.form.Textbox('price', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Price:"),
web.form.Textbox('available', web.form.notnull, web.form.regexp('\d+', 'number dumbass!'), description="Available"),
web.form.Textbox('priority', web.form.notnull, web.form.regexp('\d+', 'number dumbass!'), description="Priority (high value more priority)"),
web.form.Button('Save'))
def GET(self, idvalue):
if logged():
- i = web.input()
- if i:
- if i.cmd == 'del':
- db.delete('products', where='id=' + idvalue)
- imgdir = staticdir + 'img/' + idvalue
- try:
- shutil.rmtree(imgdir,ignore_errors=True,onerror=None)
- except:
- print('no picture folder, nothing to remove...')
- pass
- raise web.seeother('/products/')
- if i.cmd == 'removeimg':
- os.remove(staticdir + '/img/' + idvalue + '/' + i.img)
- os.remove(staticdir + '/img/' + idvalue + '/web/' + i.img)
- os.remove(staticdir + '/img/' + idvalue + '/thumb/' + i.img)
- raise web.seeother('/products/' + idvalue)
- organizepics(idvalue)
+ i = web.input(cmd=None,soundname=None)
+ if i.cmd == 'del':
+ db.delete('products', where='id="'+idvalue+'"')
+ imgdir = staticdir + 'img/' + idvalue
+ try:
+ shutil.rmtree(imgdir,ignore_errors=True,onerror=None)
+ except:
+ print('no picture folder, nothing to remove...')
+ pass
+ raise web.seeother('/products/')
+ if i.cmd == 'remove' and i.soundname != None:
+ try:
+ os.remove(staticdir+'/img/thumb/'+i.soundname)
+ os.remove(staticdir+'/img/web/'+i.soundname)
+ except:
+ print('notin to delete')
+ goodies = db.query("DELETE FROM soundlink WHERE id='"+idvalue+"' AND soundname='"+i.soundname+"';")
+ raise web.seeother('/products/' + idvalue)
addproduct = self.form()
- addproduct.fill(available='1', priority='1')
+ addproduct.fill(available='1', priority='1', type='physical',currency='euro')
+ goodies = None
if idvalue:
- oldinfo = db.select('products', where="id=" + idvalue, what='name, description, price, available, priority, category')
- oldinfo = oldinfo[0]
- addproduct.fill(name=oldinfo.name, description=oldinfo.description, price=oldinfo.price, available=oldinfo.available, priority=oldinfo.priority, category=oldinfo.category)
+ oldinfo = db.query("SELECT * FROM products WHERE id='"+idvalue+"';")[0]
+ addproduct.fill(name=oldinfo.name, description=oldinfo.description, type=oldinfo.type, currency=oldinfo.currency, price=oldinfo.price, available=oldinfo.available, priority=oldinfo.priority, category=oldinfo.category)
+ goodies = db.query("SELECT * FROM soundlink WHERE id='"+idvalue+"';")
listproducts = db.query("SELECT * FROM products ORDER BY priority DESC")
- imgdir = staticdir + 'img/' + idvalue + '/web/'
- try:
- productimages = sorted(os.listdir(imgdir))
- print(productimages)
- except:
- productimages = []
- print('No productimages for this product')
- return renderop.products(addproduct, listproducts, productimages, idvalue)
+ return renderop.products(addproduct, listproducts, goodies, idvalue)
else:
raise web.seeother('/login')
def POST(self, idvalue):
listproducts = db.query("SELECT * FROM products ORDER BY priority DESC")
addproduct = self.form()
if logged():
- i = web.input(imgfile={})
- for p in i:
- print(p)
+ i = web.input(imgfile={},name=None,description=None,price=1,available=1)
+ #for p in i:q
+ # print(p)
+ if i.name != None:
+ if idvalue:
+ db.update('products', where='id="'+idvalue+'"', category=i.category,name=i.name,description=i.description,type=i.type,currency=i.currency,price=i.price,available=i.available,priority=i.priority,dateadded=datetime.datetime.now())
+ else:
+ idvalue = hashlib.sha256(str(random.getrandbits(256)).encode('utf-8')).hexdigest()[11:36]
+ db.insert('products', id=idvalue, category=i.category, name=i.name, description=i.description, type=i.type,currency=i.currency, price=i.price, available=i.available, sold=0, priority=i.priority, dateadded=datetime.datetime.now())
if i.imgfile != {}:
if idvalue == '':
print('cant upload a picture to a non existing product')
@@ -658,46 +718,70 @@ class products:
##---------- UPLOAD IMAGE ----------
- imgdir = staticdir + 'img/' + idvalue
- os.makedirs(imgdir, exist_ok=True)
- imgpath=i.imgfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones.
- #filename=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension)
- #filename = hashlib.md5(str(random.getrandbits(256)).encode('utf-8')).hexdigest() + '.jpeg'
- imgname = str(len(os.listdir(imgdir))).zfill(3) + '.jpeg'
- fout = open(imgdir +'/'+ imgname,'wb') # creates the file where the uploaded file should be stored
+ filepath=i.imgfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones.
+ #split and only take the filename with extension
+ #soundpath=filepath.split('/')[-1]
+ #if soundpath == '':
+ # return render.nope("strange, no filename found!")
+ #get filetype, last three
+ imgname=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension)
+ filetype = imgname.split('.')[-1].lower()
+ if filetype == 'jpg':
+ filetype = 'jpeg'
+ soundname = imgname.split('.')[0]
+ #lets remove unwanted characters yes please!
+ sound = ''
+ for p in soundname.lower():
+ if p in allowedchar:
+ sound = sound + p
+ if sound == '':
+ raise web.seeother('/upload?fail=wierdname')
+ soundname = sound + '.' + filetype
+ print(soundname)
+ print("filename is " + imgname + " filetype is " + filetype + " soundname is " + soundname + " trying to upload file from: " + filepath)
+ #if filetype != 'wav' or 'ogg' or 'flac' or 'jpeg' or 'jpg' or 'mp3':
+ # web.seeother('/upload?fail=notsupported')
+ #imghash = hashlib.md5(str(random.getrandbits(256)).encode('utf-8')).hexdigest()
+ #imgname = imghash
+ #imgname = str(len(os.listdir(imgdir))).zfill(3) + '.jpeg'
+ soundlink = hashlib.sha256(str(random.getrandbits(256)).encode('utf-8')).hexdigest()[9:36]
+ imgdir = staticdir+'upload/'+soundlink+'/'
+ os.system('mkdir -p ' + imgdir)
+ fout = open(imgdir + soundname,'wb') # creates the file where the uploaded file should be stored
fout.write(i.imgfile.file.read()) # writes the uploaded file to the newly created file.
fout.close() # closes the file, upload complete.
+
+ ##----------CHECK IF SAME NAME THEN UPDATE-------
+ slink = db.query("SELECT * FROM soundlink WHERE id='"+idvalue+"' AND soundname='"+soundname+"';")
+ if slink:
+ db.update('soundlink', where='"id='+idvalue+'"', soundlink=soundlink, soundname=soundname, timeadded=datetime.datetime.now())
+ else:
+ db.insert('soundlink', id=idvalue, soundlink=soundlink, soundname=soundname, timeadded=datetime.datetime.now())
- ##---------- OPEN FILE & CHEKC IF JPEG --------
+ if filetype == 'jpeg' or filetype == 'png':
+ ##---------- OPEN FILE & CHEKC IF JPEG --------
- image = Image.open(imgdir +'/'+ imgname)
- if image.format != 'JPEG':
- os.remove(imgdir +'/'+ imgname)
- raise web.seeother('/products/' + idvalue)
+ image = Image.open(imgdir +'/'+ soundname)
+ #if image.format != 'JPEG':
+ # os.remove(imgdir +'/'+ soundname)
+ # raise web.seeother('/products/' + idvalue)
- ##---------- RESIZE IMAGE -----------
- try:
- os.makedirs(imgdir + '/web/', exist_ok=True)
- os.makedirs(imgdir + '/thumb/', exist_ok=True)
- except:
- print('Folders is')
- image.thumbnail((900,900), Image.ANTIALIAS)
- image.save(imgdir + '/web/' + imgname)
- image.thumbnail((300,300), Image.ANTIALIAS)
- image.save(imgdir + '/thumb/' + imgname)
+ ##---------- RESIZE IMAGE SAVE TO PRODUCT-----------
- organizepics(idvalue)
- raise web.seeother('/products/' + idvalue)
- if not addproduct.validates():
- raise web.seeother('/products/' + idvalue)
- else:
- if idvalue:
- db.update('products', where='id=' + idvalue, category=i.category, name=i.name, description=i.description, price=i.price, available=i.available, sold=0, priority=i.priority, dateadded=datetime.datetime.now())
- else:
- db.insert('products', category=i.category, name=i.name, description=i.description, price=i.price, available=i.available, sold=0, priority=i.priority, dateadded=datetime.datetime.now())
- raise web.seeother('/products/' + idvalue)
+ imgdir=staticdir+'img'
+ try:
+ os.makedirs(imgdir + '/web/', exist_ok=True)
+ os.makedirs(imgdir + '/thumb/', exist_ok=True)
+ except:
+ print('Folders is')
+ image.thumbnail((900,900), Image.ANTIALIAS)
+ image.save(imgdir + '/web/'+soundname)
+ image.thumbnail((300,300), Image.ANTIALIAS)
+ image.save(imgdir + '/thumb/'+soundname)
+
+ return web.seeother('/products/' + idvalue)
else:
- raise web.seeother('/login')
+ return web.seeother('/login')
class shipping:
form = web.form.Form(
@@ -709,7 +793,7 @@ class shipping:
if logged():
addcountry = self.form()
if idvalue:
- oldinfo = db.select('shipping', where="id=" + idvalue, what='country, price, days')
+ oldinfo = db.select('shipping', where="id='"+idvalue+"'", what='country, price, days')
oldinfo = oldinfo[0]
addcountry.fill(country=oldinfo.country, price=oldinfo.price, days=oldinfo.days)
listcountries = db.query("SELECT * FROM shipping ORDER BY country DESC")
@@ -725,7 +809,7 @@ class shipping:
else:
i = web.input()
if idvalue:
- db.update('shipping', where='id=' + idvalue, country=i.country, price=i.price, days=i.days)
+ db.update('shipping', where='id="'+idvalue+'"', country=i.country, price=i.price, days=i.days)
else:
db.insert('shipping', country=i.country, price=i.price, days=i.days)
raise web.seeother('/shipping/')