diff --git a/__pycache__/app.cpython-313.pyc b/__pycache__/app.cpython-313.pyc index 9513668..4ee26a7 100644 Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ 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 0000000..4bb1465 Binary files /dev/null and b/test.db differ