Make it pretty and update the current cycle calculation
This commit is contained in:
parent
bc78e17de6
commit
153f55f7b0
@ -15,6 +15,18 @@ bp = Blueprint('cycles', __name__)
|
|||||||
@bp.route('/')
|
@bp.route('/')
|
||||||
def index():
|
def index():
|
||||||
db = get_db()
|
db = get_db()
|
||||||
|
current_cycle = db.execute('SELECT * from cycle ORDER BY id DESC LIMIT 1').fetchone()
|
||||||
|
print(current_cycle['start_time'])
|
||||||
|
start_time = pendulum.parse(current_cycle['start_time'])
|
||||||
|
if current_cycle['end_time'] is None:
|
||||||
|
cycle_length = (pendulum.now() - start_time).days
|
||||||
|
|
||||||
|
db.execute(
|
||||||
|
'UPDATE cycle SET cycle_length = ?'
|
||||||
|
' WHERE id = ?',
|
||||||
|
(cycle_length, current_cycle['id'])
|
||||||
|
)
|
||||||
|
|
||||||
cycles = db.execute(
|
cycles = db.execute(
|
||||||
'SELECT id, start_time, end_time, cycle_length'
|
'SELECT id, start_time, end_time, cycle_length'
|
||||||
' FROM cycle ORDER BY start_time DESC'
|
' FROM cycle ORDER BY start_time DESC'
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
margin: 30px 0;
|
margin: 30px 0;
|
||||||
}
|
}
|
||||||
.table-wrapper {
|
.table-wrapper {
|
||||||
min-width: 1000px;
|
/* min-width: 1000px; */
|
||||||
background: #fff;
|
background: #fff;
|
||||||
padding: 20px 25px;
|
padding: 20px 25px;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
@ -8,38 +8,32 @@
|
|||||||
<div class="table-wrapper">
|
<div class="table-wrapper">
|
||||||
<div class="table-title">
|
<div class="table-title">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
|
||||||
{% block header %}
|
|
||||||
<h2>{% block title %}Cycles{% endblock %}</h2>
|
|
||||||
{% endblock %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-striped table-hover">
|
|
||||||
{% for cycle in cycles %}
|
{% for cycle in cycles %}
|
||||||
<tr>
|
<div class="card text-center" style="width: 18rem;">
|
||||||
<article class="post">
|
<div class="card-body">
|
||||||
<header>
|
<h5 class="card-title">
|
||||||
<div>
|
{% if cycle['cycle_length'] %}
|
||||||
<div class="about"><b>Started:</b> {{ cycle['start_time'] }}</div>
|
{% if loop.first %}
|
||||||
<b>Ended: </b>{{ cycle['end_time'] }}</div>
|
Day <b>{{ cycle['cycle_length'] }}</b>
|
||||||
|
{% else %}
|
||||||
|
<b>{{ cycle['cycle_length'] }}</b> days.
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{% endif %}</h5>
|
||||||
|
<p class="card-text"><b>Started:</b> {{ cycle['start_time'][:10] }}
|
||||||
|
<br>
|
||||||
|
{% if not loop.first %}
|
||||||
|
<b>Ended: </b>{{ cycle['end_time'][:10] }}
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
<a href="{{ url_for('cycles.update', id=cycle['id'])}}"class="btn btn-primary">Edit</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
|
||||||
<p class="body">
|
|
||||||
{% if cycle['cycle_length'] %}
|
|
||||||
Cycle Length: <b>{{ cycle['cycle_length'] }} days</b>.
|
|
||||||
{% else %}
|
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
|
||||||
<a class="action" href="{{ url_for('cycles.update', id=cycle['id'])}}">Edit</a> - {{ cycle['id'] }}
|
|
||||||
</article>
|
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
<hr>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user