From 92e012842544e765e7dccec36f7ae39a8ee6deb1 Mon Sep 17 00:00:00 2001 From: robertorincos Date: Sun, 16 Mar 2025 22:57:23 -0300 Subject: [PATCH] =?UTF-8?q?atualiza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __pycache__/app.cpython-313.pyc | Bin 180 -> 2347 bytes app.py | 61 +++++++++++++++++++++++++++++--- static/css/main.css | 34 +++++++++++++++++- templates/base.html | 3 +- templates/index.html | 35 +++++++++++++++--- templates/update.html | 18 ++++++++++ test.db | Bin 0 -> 8192 bytes 7 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 templates/update.html create mode 100644 test.db diff --git a/__pycache__/app.cpython-313.pyc b/__pycache__/app.cpython-313.pyc index 951366859e59989629e0e47c30b595ecdb8866d0..4ee26a7c926b14e6ec433e8070c1fbc9f041ad61 100644 GIT binary patch literal 2347 zcmah~O-vg{6rTO_`VZTL5@Mo&8%)4b165j@*iBOL7ZQii#tWhqmR9~*oK@Dl&g@z# zD2j|y6(dywR7E)IAxQ0^y`{bM-cyfuNd;LYs;Y9yjfzyNsvi1g%|c`n^&Q^4c{A_L z%zNK^v)k0sI{TGD$NI(L06~!q`#c52(8O+34%*Hv)g~%Fx z)e+}0Z^_J6XWWUMA(W&}qNHnps(Zq2flay-N9_X+MuF>rNs@=%?)}}~W9TFj9PLQp zlio!8!ERd`VCoX~f!9u3doT)4!6mr+X~7ev1#deV*jvJZq)TXueT+~l0H?YWT?aO{ zB=`h>lnS9-AQy-4xdV zQdY)N#)wd+TevO3X*74!Xqt`wW zM+PSchX#dFaVl{oW8aI6`-yoBllv%%FeM;N3lwIOY{K*M*18N@?_sS#3rv*8{A+ER zUtz=A=@B@=0oJb9TEB7FI_XIqJFFFW@Y5tX+Y$B&F6_^_BOa5T)Uw)h7wn#dn0X3V z&ZqF4cvG5t{xc{qkwB_NMM|~DTfnF35DYA&c1gyeSg0O~3HgPLq1YZ^-?)2-xK1W+F&vI}nxN>GKwi^5P-Ey$%db>2V zH!TP>|?(bZ@r@o?tB%%k2P`@ipBiB?;NO5=ag z6xUrpjT~fB{U-a-hr*=EjExd}@OjC&p=I?$Wn!iO3rOF6Gy{fpN)TW)kU&}eKteC? zgO1op0!^w~aeIpS8ci6sC4R1Ka&l z74{1>jAj7XbxIturGqg+^435vS-hf4+jmWn+&7SY7nPnlZZ8RrDVh{_7`=%?s1xP5 z3rr`Pr6SG=+zXrVNnjDm8Zh|)=9@<`)^I45%>r0M1{CAGTZUHqY2OVauRx+XqSGTj zOrB;s>S;GwXubJ51UrbH*Ckz-HPvLmlj+E4`Mhjkk};Em_Kcx6HB1_KdJcCJEt66d zOtKweOfNY?+^-W=x-Ak7ehZd$f~Qa@WMSUqtgGR(pd<0uSAmt#Ht$=!yKuL1bc64F z+SajlXZ6ndm0DY0*}L7+w(hO9oGv?eSkBe+)azT0FU6N9mL@9a9(%)k^G)xGn)k$G zZ|BpN7ue@Erc zqk)<~T6ISM-f5y-Jx^Lr{iBnD`C*VB`T+g(0X@txq_yNzvMP$Ca=5INF6Jg8M@(*( z{B4-L&2 z4LXMvER(@SwV{ES&hzyycM%VQGtzMN&w%YP6h-}pMt(&j&rr`ZbmDi1r+oRIR${h# z-!CzX?ge+%6Rx4|C!BwUxhIzB7c570m(MJpTRQgwfw&VuG`ARB2$tWe99?g%_)Ebm u)%zzMpkliWq9Z#*+Bt<-Z+U)$32w3c;@HC2O1L!k3){BCAhz9VJpTbBXzg(T delta 141 zcmZ22w1qL@GcPX}0}xCTy_zlwq#uJgFu(+5d=>yQrZNOG1T%Uwcrg|+DlnuoX)?bA zNoz9RVs*<&EY9}RWV*$g24WR41I1S|dE8+l(FamKgi1C4$ Ok&*EpgLn}ekOKfj!5WzW diff --git a/app.py b/app.py index 2527a19..f833ef7 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,63 @@ -from flask import Flask, render_template +from flask import Flask, render_template, url_for, request, redirect +from flask_sqlalchemy import SQLAlchemy +from datetime import datetime -app =Flask(__name__) +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' +db = SQLAlchemy(app) -@app.route('/') +class Todo(db.Model): + id = db.Column(db.Integer, primary_key=True) + content = db.Column(db.String(200), nullable=False) + date_created = db.Column(db.DateTime, default=datetime.utcnow) + def __repr__(self): + return '' % self.id + + +@app.route('/', methods=['POST', 'GET']) def index(): - return render_template('index.html') + if request.method == 'POST': + task_content = request.form['content'] + #task_content é o conteudo do form + new_task = Todo(content=task_content) + + try: + db.session.add(new_task) + db.session.commit() + return redirect('/') + except: + return 'Error adding task' + + else: + tasks = Todo.query.order_by(Todo.date_created).all() + #ordena e mostra todo database criado + return render_template('index.html', tasks=tasks) + +@app.route('/delete/') +def delete(id): + task_delete = Todo.query.get_or_404(id) + + try: + db.session.delete(task_delete) + db.session.commit() + return redirect('/') + except: + return'error in delete' + +@app.route('/update/', methods=['GET', 'POST']) +def update(id): + task = Todo.query.get_or_404(id) + + if request.method == 'POST': + task.content = request.form['content'] + try: + db.session.commit() + return redirect('/') + except: + return'update error' + else: + return render_template('update.html', task=task) + if __name__ == "__main__": app.run(debug=True) \ No newline at end of file diff --git a/static/css/main.css b/static/css/main.css index 183685b..b98ead3 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,4 +1,36 @@ -body { +body, html { margin: 0; font-family: sans-serif; + background-color: lightblue; +} + +.content { + margin: 0 auto; + width: 400px; +} + +table, td, th { + border: 1px solid #aaa; +} + +table { + border-collapse: collapse; + width: 100%; +} + +th { + height: 30px; +} + +td { + text-align: center; + padding: 5px; +} + +.form { + margin-top: 20px; +} + +#content { + width: 70%; } \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index ec7ed53..b31b70a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,7 +3,8 @@ - + {% block head %}{% endblock %} diff --git a/templates/index.html b/templates/index.html index 1c3ee38..56a3f95 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,9 +1,36 @@ -{% extends 'base.html'%} - +{% extends 'base.html' %} {% block head %} - +Fazer coisas {% endblock %} {% block body %} -

Template

+
+

Task Master

+ + + + + + + + + {% for task in tasks %} + + + + + + {% endfor %} +
TaskAddedAction
{{ task.content }}{{ task.date_created.date() }} + Delete +
+ Update +
+ +
+ + +
+
+ {% endblock %} \ No newline at end of file diff --git a/templates/update.html b/templates/update.html new file mode 100644 index 0000000..4fb30e4 --- /dev/null +++ b/templates/update.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% block head %} +Fazer coisas +{% endblock %} + +{% block body %} +
+

Update Master

+ +
+
+ + +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/test.db b/test.db new file mode 100644 index 0000000000000000000000000000000000000000..4bb14651938d469d471d155871816b0e78727133 GIT binary patch literal 8192 zcmeI#K~KUk6bJB@kQhh^5<|E?;sp{}x^)xT$%>7l19eUlPNri>5Z7*Gy|GMqB(;gp!sZQZFTg{aQP7VpBN4iHkr&eg<0Q(lmj=D3Vt)gwb6Dqo*J^fpRI%7CK#Mcot#*T7)f!vGz_NQ96Bz zSE(5ixHRiVgQ3i?yblLM5su+jj-fS8+U555zxjq#H`Qgn?ZrpHmqY;+Kmim$0Te(1 z6hHwKKmim$fqxcg7K`LaWHaS3$LlcOvAe)*pPl(0vwEKG+T1+B{P&2