diff --git a/src/templates/item.html b/src/templates/item.html index 2640b16..e1b75f5 100644 --- a/src/templates/item.html +++ b/src/templates/item.html @@ -1,69 +1,62 @@ {% extends 'base.html' %} {% block content %} -
-

Animation by {{ image.creator }}

- - - - - {{image.name}} -
-

{{ image.name }}

-
-
- - - - - - - - - - - -
Creator{{ image.creator }}
Creation date{{ image.creation_date }}
-
-
- Download -
- -
+
+

Animation by {{ item.uploader.name }}

+
+

+

{{ item.name }}

+

-{% if current_user.is_authenticated %} -
-
-
-
- Write a comment -
- + {{ item.name }} + +
+ {% if purchased %} + Download + {% else %} + Purchase + {% endif %} +
+
+ +
+ + {% if current_user.is_authenticated %} +
+
+ +
+ Write a comment +
+ +
+ +
+ +
+
+ {% endif %} + + {% if item.comments %} + {% for comment in item.comments %} +
+
+

{{ comment.commenter.name }}

+
{{ comment.date }}
+

{{ comment.text }}

- - - -
-
-{% endif %} - -{% if comments %} -{% for comment in comments %} -
-
-

{{ comment.user }}

-
{{ comment.date }}
-

{{ comment.text }}

-
-
-{% endfor %} -{% else %} -
-
-

No comments yet.

-
-
-{% endif %} +
+ {% endfor %} + {% else %} +
+
+

No comments yet.

+
+
+ {% endif %} +
{% endblock %} \ No newline at end of file diff --git a/src/views/itemview.py b/src/views/itemview.py index 5d01355..746af69 100644 --- a/src/views/itemview.py +++ b/src/views/itemview.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 - +from flask import render_template from flask_classful import FlaskView +from flask_security import current_user + +from models import db, Comment, Item, Purchase """ Item VIEW @@ -14,11 +17,14 @@ __version__text__ = "1" class ItemView(FlaskView): - def index(self): - pass + def get(self, id_: int): + item = Item.query.get_or_404(id_) - def download(self): - pass + if not current_user.is_authenticated: + purchased = False + else: + p = Purchase.query.filter( + db.and_(Purchase.purchaser_id == current_user.id, Purchase.item_id == id_)).first() + purchased = bool(p) - def delete(self): - pass + return render_template('item.html', item=item, purchased=purchased)