Implemented purchase
This commit is contained in:
parent
8a3ac21d61
commit
d28cc70519
@ -15,7 +15,8 @@
|
||||
<a href="{{ url_for('ContentView:caff', id_=item.id) }}" class="btn btn-lg btn-success"
|
||||
target="_self">Download</a>
|
||||
{% else %}
|
||||
<a href="#" class="btn btn-lg btn-primary" target="_blank">Purchase</a>
|
||||
<a href="{{ url_for("PurchaseView:get", id_=item.id) }}" class="btn btn-lg btn-primary"
|
||||
target="_self">Purchase</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -22,6 +22,10 @@
|
||||
<th scope="row">Upload date</th>
|
||||
<td>{{ item.upload_date }}</td>
|
||||
</tr>
|
||||
<tr class="table-active">
|
||||
<th scope="row">Price</th>
|
||||
<td>1 currency</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -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_))
|
||||
|
Loading…
Reference in New Issue
Block a user