Implemented basic item view

This commit is contained in:
Pünkösd Marcell 2020-11-28 22:04:03 +01:00
parent 3ce60047ff
commit 9a204bd3ba
2 changed files with 70 additions and 71 deletions

View File

@ -1,69 +1,62 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
<div class="card mb-3"> <div class="card mb-3">
<h3 class="card-header">Animation by {{ image.creator }}</h3> <h3 class="card-header">Animation by {{ item.uploader.name }}</h3>
<!-- <div class="card-body">--> <div class="card-body">
<!-- <h5 class="card-title">Special title treatment</h5>--> <h4>
<!-- <h6 class="card-subtitle text-muted">Support card subtitle</h6>--> <p class="card-text">{{ item.name }}</p>
<!-- </div>--> </h4>
<img src="{{image.preview}}" class="card-img" style="padding: 30px" alt="{{image.name}}">
<div class="card-body">
<p class="card-text">{{ image.name }}</p>
</div>
<div class="card-body">
<table class="table table-responsive">
<tbody>
<tr class="table-active">
<th scope="row">Creator</th>
<td>{{ image.creator }}</td>
</tr>
<tr class="table-active">
<th scope="row">Creation date</th>
<td>{{ image.creation_date }}</td>
</tr>
</tbody>
</table>
</div>
<div class="card-body">
<a href="{{ url_for('download', id=image.id) }}" class="card-link" target="_blank">Download</a>
</div>
<div class="card-footer text-muted">
Uploaded: {{ image.upload_date }}
</div>
</div>
{% if current_user.is_authenticated %} <img src="{{ url_for('ContentView:preview', id_=item.id) }}" class="card-img" style="padding: 30px"
<div class="card"> alt="{{ item.name }}">
<div class="card-body">
<form> <div class="card-text text-center">
<fieldset> {% if purchased %}
<legend>Write a comment</legend> <a href="{{ url_for('ContentView:caff', id_=item.id) }}" class="btn btn-lg btn-success"
<div class="form-group"> target="_self">Download</a>
<textarea class="form-control" id="commentTextarea" rows="3" , {% else %}
placeholder="Type your comment here"></textarea> <a href="#" class="btn btn-lg btn-primary" target="_blank">Purchase</a>
{% endif %}
</div>
</div>
<div class="card-footer text-muted">
Uploaded: {{ item.upload_date }}
</div>
</div>
{% if current_user.is_authenticated %}
<div class="card my-2">
<div class="card-body">
<form>
<fieldset>
<legend>Write a comment</legend>
<div class="form-group">
<textarea class="form-control" id="commentTextarea" rows="3"
placeholder="Type your comment here"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>
</div>
</div>
{% endif %}
{% if item.comments %}
{% for comment in item.comments %}
<div class="card my-2">
<div class="card-body">
<h4 class="card-title">{{ comment.commenter.name }}</h4>
<h6 class="card-subtitle mb-2 text-muted">{{ comment.date }}</h6>
<p class="card-text">{{ comment.text }}</p>
</div> </div>
<button type="submit" class="btn btn-primary">Submit</button> </div>
</fieldset> {% endfor %}
</form> {% else %}
</div> <div class="card my-2">
</div> <div class="card-body">
{% endif %} <p>No comments yet.</p>
</div>
{% if comments %} </div>
{% for comment in comments %} {% endif %}
<div class="card"> <div class="my-4"></div>
<div class="card-body">
<h4 class="card-title">{{ comment.user }}</h4>
<h6 class="card-subtitle mb-2 text-muted">{{ comment.date }}</h6>
<p class="card-text">{{ comment.text }}</p>
</div>
</div>
{% endfor %}
{% else %}
<div class="card">
<div class="card-body">
<p>No comments yet.</p>
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from flask import render_template
from flask_classful import FlaskView from flask_classful import FlaskView
from flask_security import current_user
from models import db, Comment, Item, Purchase
""" """
Item VIEW Item VIEW
@ -14,11 +17,14 @@ __version__text__ = "1"
class ItemView(FlaskView): class ItemView(FlaskView):
def index(self): def get(self, id_: int):
pass item = Item.query.get_or_404(id_)
def download(self): if not current_user.is_authenticated:
pass 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): return render_template('item.html', item=item, purchased=purchased)
pass