diff --git a/src/templates/item.html b/src/templates/item.html
index 4c6824d..aa80914 100644
--- a/src/templates/item.html
+++ b/src/templates/item.html
@@ -15,7 +15,8 @@
Download
{% else %}
- Purchase
+ Purchase
{% endif %}
diff --git a/src/templates/purchase.html b/src/templates/purchase.html
index ea76ffb..221464e 100644
--- a/src/templates/purchase.html
+++ b/src/templates/purchase.html
@@ -22,6 +22,10 @@
Upload date |
{{ item.upload_date }} |
+
+ Price |
+ 1 currency |
+
diff --git a/src/views/purchaseview.py b/src/views/purchaseview.py
index a04dfb8..d07b7a9 100644
--- a/src/views/purchaseview.py
+++ b/src/views/purchaseview.py
@@ -1,15 +1,36 @@
#!/usr/bin/env python3
-from flask import render_template
+from flask import render_template, redirect, url_for, abort, flash
from flask_classful import FlaskView
from flask_security.decorators import login_required
from flask_security import current_user
-from models import Item
+from models import db, Item, Purchase
+
+from utils import user_can_access_caff
class PurchaseView(FlaskView):
- def get(self, id_:int):
+ def get(self, id_: int):
item = Item.query.get_or_404(id_)
+
+ if user_can_access_caff(item):
+ flash("You don't need to purchase this image", "primary")
+ return redirect(url_for("ItemView:get", id_=id_))
+
return render_template('purchase.html', item=item)
+
+ @login_required
+ def post(self, id_: int):
+ item = Item.query.get_or_404(id_)
+
+ if user_can_access_caff(item):
+ flash("You don't need to purchase this image", "primary")
+ return redirect(url_for("ItemView:get", id_=id_))
+
+ p = Purchase(purchaser=current_user, item=item)
+ db.session.add(p)
+ db.session.commit()
+ flash("Successful purchase! Click download to get your animation!", "success")
+ return redirect(url_for("ItemView:get", id_=id_))