netclock/countdown/views.py

38 lines
1.3 KiB
Python
Raw Normal View History

2020-09-13 13:07:11 +00:00
from flask import render_template, request, flash, redirect, url_for, session
2020-09-12 10:58:38 +00:00
2020-09-12 17:51:47 +00:00
from . import app
from . import forms
2020-09-13 13:07:11 +00:00
from .countdown import Cache
2020-09-12 10:58:38 +00:00
2020-09-13 13:07:11 +00:00
@app.route('/', methods=['GET', 'POST'])
def create():
session.permanent = True
if not session.get('created_countdowns'):
session['created_countdowns'] = []
2020-09-12 10:58:38 +00:00
2020-09-12 17:51:47 +00:00
form = forms.CountdownAdminForm(request.form)
2020-09-12 10:58:38 +00:00
if request.method == 'POST' and form.validate():
2020-09-13 13:07:11 +00:00
cache = Cache.getInstance()
total = form.seconds.data or 0
total += (form.minutes.data or 0) * 60
total += (form.hours.data or 0) * 60 * 60
countdown_id = cache.add_countdown(total)
2020-09-12 17:51:47 +00:00
# user = User(form.username.data, form.email.data,
# form.password.data)
# db_session.add(user)
2020-09-13 13:07:11 +00:00
session['created_countdowns'].append(str(countdown_id))
session.modified = True
return redirect(url_for('countdown.created'))
return render_template('countdown/create.html', form=form, clock=None)
@app.route('/mine', methods=['GET'])
def created():
return render_template('countdown/created.html', clocks=session['created_countdowns'])
@app.route('/<uuid:countdown_id>', methods=['GET'])
def view(countdown_id):
return render_template('countdown/countdown.html', countdown_id=countdown_id)
2020-09-12 10:58:38 +00:00