Add Delete Function
This commit is contained in:
parent
58e2d7901f
commit
bc78e17de6
@ -54,8 +54,9 @@ def create():
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
db.execute(
|
db.execute(
|
||||||
'INSERT INTO cycle (start_time, cycle_length) VALUES (?, ?)',
|
'INSERT INTO cycle (start_time)'
|
||||||
(start_time_stamp, cycle_length)
|
' VALUES (?)',
|
||||||
|
(start_time.to_datetime_string(),)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
@ -118,4 +119,12 @@ def update(id):
|
|||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
return render_template('cycle/update.html', cycle=cycle)
|
return render_template('cycle/update.html', cycle=cycle)
|
||||||
|
|
||||||
|
@bp.route('/<int:id>/delete', methods=('POST',))
|
||||||
|
def delete(id):
|
||||||
|
get_cycle(id)
|
||||||
|
db = get_db()
|
||||||
|
db.execute('DELETE FROM cycle WHERE id = ?', (id,))
|
||||||
|
db.commit()
|
||||||
|
return redirect(url_for('index'))
|
@ -25,7 +25,13 @@
|
|||||||
<b>Ended: </b>{{ cycle['end_time'] }}</div>
|
<b>Ended: </b>{{ cycle['end_time'] }}</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<p class="body">Cycle Length: <b>{{ cycle['cycle_length'] }} days</b>.</p>
|
<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'] }}
|
<a class="action" href="{{ url_for('cycles.update', id=cycle['id'])}}">Edit</a> - {{ cycle['id'] }}
|
||||||
</article>
|
</article>
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
|
@ -12,4 +12,9 @@
|
|||||||
<input name="end_time" id="end_time" value="{{ request.form['end_time'] or cycle['end_time'][:10] if cycle['end_time'] is not none }}" type="date">
|
<input name="end_time" id="end_time" value="{{ request.form['end_time'] or cycle['end_time'][:10] if cycle['end_time'] is not none }}" type="date">
|
||||||
<input type="submit" value="Save">
|
<input type="submit" value="Save">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
<form action="{{ url_for('cycles.delete', id=cycle['id']) }}" method="post">
|
||||||
|
<input class="danger" type="submit" value="Delete" onclick="return confirm('Are you sure you want to delete this cycle?');">
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user