This commit is contained in:
Justine Pelletreau 2022-04-05 14:31:44 +02:00
parent aa6a0f8e5e
commit 1ab22c765f
2 changed files with 28 additions and 29 deletions

View File

@ -13,9 +13,8 @@ from random import choice
#----------! MAIN
app = Flask(__name__)
mktaskdir()
#Theme variable will be made global in every flask function
#css path will then be deducted
#Homepage, GET : getting the page. Maybe getting it with arguments generated by a button on the page, in which case we take it into account
@app.route('/', methods=['GET'])
def render():
#Does the user have a theme ?
@ -36,6 +35,7 @@ def render():
if request.args.get("delete") is not None:
todelete = request.args.get("delete")
deltask(int(todelete))
resp = make_response(render_template("homepage.html", ntodo = todotasks(gettasks()), ndone = donetasks(gettasks()), csslink = csslink))
#Edit has been clicked
elif request.args.get("edit") is not None:
@ -51,7 +51,6 @@ def render():
csslink = choice(themes)
#Commiting new theme, setting cookie for it, return template
#resp = make_response(render_template("homepage.html", nr = cattasks(gettasks()), csslink = csslink))
resp = make_response(redirect(request.path,code=302))
resp.set_cookie('csslink', csslink)
return resp
@ -75,13 +74,37 @@ def render():
return resp
#Homepage, POST : a task has been written and posted
@app.route('/', methods=['POST'])
def homepage():
import time
#theme
csslink = request.cookies.get('csslink')
#New task
try:
tasktitle = request.form['title']
tasktext = request.form['text']
print("PING")
priority = request.form['priority']
print(f"Got new task with prio {priority}")
rightnow = int(time.time())
newtask = task(createtime=rightnow, modtime=rightnow, title=tasktitle, text=tasktext, done=False, priority=int(priority))
addtask(newtask)
except:
pass
return render_template("homepage.html", ntodo = todotasks(gettasks()), ndone = donetasks(gettasks()), csslink = csslink)
#Export mode
@app.route('/export', methods=['GET'])
def rawtasks():
#No theme in export
return render_template("export.html", rawtasks = exporttasks())
#Edition mode
@app.route('/edit', methods=['GET', 'POST'])
def edit():
@ -124,29 +147,5 @@ def edit():
#Basic route, allows task creation
@app.route('/', methods=['POST'])
def homepage():
import time
#theme
csslink = request.cookies.get('csslink')
#New task
try:
tasktitle = request.form['title']
tasktext = request.form['text']
print("PING")
priority = request.form['priority']
print(f"Got new task with prio {priority}")
rightnow = int(time.time())
newtask = task(createtime=rightnow, modtime=rightnow, title=tasktitle, text=tasktext, done=False, priority=int(priority))
addtask(newtask)
except:
pass
return render_template("homepage.html", ntodo = todotasks(gettasks()), ndone = donetasks(gettasks()), csslink = csslink)
if __name__ == '__main__':
app.run(host="0.0.0.0")

View File

@ -43,7 +43,7 @@ class task:
<hr>
<div class="tasktitle">{self.donemark} {Markup.escape(self.title)}</div>
<form action="." method="GET" name="{self.createtime}">
<button type="submit" name="toswitch" value="{self.createtime}" class "taskbutton">Done/Todo</button>|<button type="submit" name="delete" value="{self.createtime}" class="taskbutton" onclick="return confirm('Really ?')">Delete</button>|<button type="submit" name="edit" value="{self.createtime}" class="taskbutton">Edit</button>|<a href="{ url_for('render') }" class="backlink">Back</a>
<button type="submit" name="toswitch" value="{self.createtime}" class "taskbutton">Done/Todo</button>|<button type="submit" name="delete" value="{self.createtime}" class="taskbutton" onclick="return confirm('Really ?')">Delete</button>|<button type="submit" name="edit" value="{self.createtime}" class="taskbutton">Edit</button>
</form>
<div class="tasktime">Priority: {self.priority}</div>
<div class="tasktime">Created : {self.rendertime(self.createtime)}