Implemented purchase

This commit is contained in:
Pünkösd Marcell 2020-11-29 00:00:01 +01:00
parent 8a3ac21d61
commit d28cc70519
3 changed files with 30 additions and 4 deletions

View File

@ -15,7 +15,8 @@
<a href="{{ url_for('ContentView:caff', id_=item.id) }}" class="btn btn-lg btn-success" <a href="{{ url_for('ContentView:caff', id_=item.id) }}" class="btn btn-lg btn-success"
target="_self">Download</a> target="_self">Download</a>
{% else %} {% 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 %} {% endif %}
</div> </div>
</div> </div>

View File

@ -22,6 +22,10 @@
<th scope="row">Upload date</th> <th scope="row">Upload date</th>
<td>{{ item.upload_date }}</td> <td>{{ item.upload_date }}</td>
</tr> </tr>
<tr class="table-active">
<th scope="row">Price</th>
<td> </td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -1,15 +1,36 @@
#!/usr/bin/env python3 #!/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_classful import FlaskView
from flask_security.decorators import login_required from flask_security.decorators import login_required
from flask_security import current_user 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): class PurchaseView(FlaskView):
def get(self, id_:int): def get(self, id_: int):
item = Item.query.get_or_404(id_) 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) 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_))