first commit

This commit is contained in:
ilgazca
2025-07-28 14:57:53 +03:00
commit ef6114eff9
13 changed files with 196 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

10
.idea/FlaskIntroduction.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.13 (FlaskIntroduction)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.13 (FlaskIntroduction)" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FlaskIntroduction.iml" filepath="$PROJECT_DIR$/.idea/FlaskIntroduction.iml" />
</modules>
</component>
</project>

7
README.md Normal file
View File

@ -0,0 +1,7 @@
Task Master
This small Python webapp is to keep track of tasks.
The code is taken completely from freeCodeCamp.org Youtube tutorial
"Learn Fask for Python - Full Tutorial". I don't have any claim of ownership of either
the idea or the code.

Binary file not shown.

61
app.py Normal file
View File

@ -0,0 +1,61 @@
from flask import Flask, render_template, url_for, request, redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.app_context().push()
db = SQLAlchemy(app)
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 '<Task %r>' % self.id
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
task_content = request.form['content']
new_task = Todo(content=task_content)
try:
db.session.add(new_task)
db.session.commit()
return redirect("/")
except:
return "There was an issue adding your task"
else:
tasks = Todo.query.order_by(Todo.date_created).all()
return render_template("index.html", tasks=tasks)
@app.route("/delete/<int:id>")
def delete(id):
task_to_delete = Todo.query.get_or_404(id)
try:
db.session.delete(task_to_delete)
db.session.commit()
return redirect("/")
except:
return "There was an issue deleting your task"
@app.route("/update/<int:id>", 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 "There was an issue updating your task"
else:
return render_template("update.html", task=task)
if __name__ == '__main__':
app.run(debug=True)

BIN
instance/test.db Normal file

Binary file not shown.

19
static/css/main.css Normal file
View File

@ -0,0 +1,19 @@
body {
margin: 0;
font-family: sans-serif;
}
table {
border-collapse: collapse; /* optional: merges borders between cells */
margin: 0 auto;
}
form {
margin: 0 auto;
width: max-content; /* ensures the form's width is not 100% */
}
th, td {
border: 1px solid black; /* adds border around each cell */
padding: 8px; /* optional: adds space inside cells */
text-align: left; /* optional: aligns text to the left */
}

11
templates/base.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"
{% block head %}{% endblock %}
</head>
<body style="align-content: center">
{% block body %}{% endblock %}
</body>
</html>

43
templates/index.html Normal file
View File

@ -0,0 +1,43 @@
{% extends 'base.html' %}
{% block head %}
<title>Task Master</title>
{% endblock %}
{% block body %}
<div class="content">
<h1 style="text-align: center">Task Master</h1>
{% if tasks|length < 1 %}
<h4 style="text-align: center">There are no tasks. Create one below</h4>
{% else %}
<table>
<tr>
<th>Task</th>
<th>Added</th>
<th>Actions</th>
</tr>
{% for task in tasks %}
<tr>
<td>{{ task.content }}</td>
<td>{{ task.date_created.date() }}</td>
<td>
<a href="/delete/{{task.id}}">Delete</a>
<br>
<a href="/update/{{task.id}}">Update</a>
</td>
</tr>
{% endfor %}
</table>
{% endif %}
<form action="/" method="POST">
<input type="text" name="content" id="content" placeholder="Task name">
<input type="submit" value="Add Task">
</form>
</div>
{% endblock %}

17
templates/update.html Normal file
View File

@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% block head %}
<title>Task Master</title>
{% endblock %}
{% block body %}
<div class="content">
<h1 style="text-align: center">Update Task</h1>
<form action="/update/{{task.id}}" method="POST">
<input type="text" name="content" id="content" placeholder="Task name" value="{{task.content}}">
<input type="submit" value="Update Task">
</form>
</div>
{% endblock %}