Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Framework Projects/Flask/TODO/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from flask import Flask,request,render_template,redirect,url_for
from flask_wtf import FlaskForm
from wtforms import SubmitField,StringField,PasswordField,IntegerField,SelectField
from wtforms.validators import DataRequired
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
import csv



app = Flask(__name__)
app.config["SECRET_KEY"] = 'sjosnlvdnovheoik'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///cafes.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
Bootstrap(app)







class Form(FlaskForm):
name = StringField(label='name',validators=[DataRequired()])
piority = SelectField(label='piority',choices=['HIGH','MEDIUM','LOW'],validators=[DataRequired()])
description = StringField(label = 'Description',validators=[DataRequired()])
submit = SubmitField(label='submit')


class Task(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(250), unique=True, nullable=False)
piority = db.Column(db.String(500), nullable=False)
description = db.Column(db.String(500), nullable=False)
db.create_all()



@app.route("/")
def table():
form = Task.query.order_by(Task.piority).all()
return render_template('table.html',form = form)



@app.route('/add', methods = ['GET','POST'])
def index():
form = Form()
if form.validate_on_submit():
new_task = Task(
name=form.name.data,
piority=form.piority.data,
description=form.description.data

)
print(form.piority.data)
db.session.add(new_task)
db.session.commit()
return redirect(url_for('table'))
return render_template('index.html',form = form)

@app.route("/delete/<int:id>")
def delete(id):
get_task = Task.query.get(id)
db.session.delete(get_task)
db.session.commit()
return redirect(url_for('table'))

@app.route("/update/<int:id>",methods = ['GET','POST'])
def update(id):
data = Task.query.get(id)
form = Form(
name = data.name,
description = data.description,
piority = data.piority,
)
if form.validate_on_submit():
data.name = form.name.data
data.description = form.description.data
data.piority = form.piority.data
db.session.commit()
return redirect(url_for('table'))
return render_template('index.html',form = form)


if __name__ == '__main__':
app.run(debug=True)
5 changes: 5 additions & 0 deletions Framework Projects/Flask/TODO/requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flask
flask_wtf
wtforms
flask_sqlalchemy
flask_bootstrap
25 changes: 25 additions & 0 deletions Framework Projects/Flask/TODO/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.container{
visibility: hidden;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(73, 166, 233, 0.5);
display: grid;
place-items: center;
z-index: -10;
}

.visible{
visibility: visible;
z-index: 10;
}

.close-button{
position: absolute;
top: 1rem;
right: 1rem;
font-size: 2rem;
cursor: pointer;
}
8 changes: 8 additions & 0 deletions Framework Projects/Flask/TODO/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'bootstrap/base.html' %}
{% import "bootstrap/wtf.html" as wtf %}
{% block content %}

{{ wtf.quick_form(form ,novalidate=True) }}


{% endblock %}
72 changes: 72 additions & 0 deletions Framework Projects/Flask/TODO/templates/table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{% extends 'bootstrap/base.html' %}
{% block title %}table{% endblock %}

{% block styles %}
{{super()}}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<link rel="stylesheet" href="{{url_for('static',filename = 'styles.css')}}">
{% endblock %}


{% block content %}
<table class="table table-dark table-hover">
<thead>
<tr>
<th scope="col" style="font-size:2rem">ID</th>
<th scope="col" style="font-size:2rem">NAME</th>
<th scope="col" style="font-size:2rem">Piority</th>
<th scope="col" style="font-size:2rem">Description</th>
<th scope="col" style="font-size:2rem">UPDATE</th>
<th scope="col" style="font-size:2rem">DELETE</th>

</tr>
</thead>
<tbody>
{% for data in form %}

{% if data.piority == 'HIGH' %}
<tr CLASS="table-danger">
<th scope="row" style="font-size:1.5rem">{{data.id}}</th>
<td style="font-size:1.5rem">{{data.name}}</td>
<td style="font-size:1.5rem"><spa>{{data.piority}}</spa></td>
<td style="font-size:1.5rem">{{data.description}}</td>
<td style="font-size:1.5rem"><a href="{{url_for('update',id = data.id)}}"><button type="button" class="btn btn-outline-success">UPDATE</button></a></td>
<td style="font-size:1.5rem"><a href="{{url_for('delete',id = data.id)}}">🗑️</a></td>
</tr>
{% elif data.piority == 'MEDIUM' %}
<tr CLASS="table-warning">
<th scope="row" style="font-size:1.5rem">{{data.id}}</th>
<td style="font-size:1.5rem">{{data.name}}</td>
<td style="font-size:1.5rem"><spa>{{data.piority}}</spa></td>
<td style="font-size:1.5rem">{{data.description}}</td>
<td style="font-size:1.5rem"><a href="{{url_for('update',id = data.id)}}"><button type="button" class="btn btn-outline-success">UPDATE</button></a></td>
<td style="font-size:1.5rem"><a href="{{url_for('delete',id = data.id)}}">🗑️</a></td>
</tr>
{% else %}
<tr CLASS="table-dark">
<th scope="row" style="font-size:1.5rem">{{data.id}}</th>
<td style="font-size:1.5rem">{{data.name}}</td>
<td style="font-size:1.5rem"><spa>{{data.piority}}</spa></td>
<td style="font-size:1.5rem">{{data.description}}</td>
<td style="font-size:1.5rem"><a href="{{url_for('update',id = data.id)}}"><button type="button" class="btn btn-outline-success">UPDATE</button></a></td>
<td style="font-size:1.5rem"><a href="{{url_for('delete',id = data.id)}}">🗑️</a></td>
</tr>

{% endif %}
<div class="container">
<button class="close">❌</button>
<p id ='text' style="color:white">{{data.description}}</p></div>
{% endfor %}




</tbody>
</table>
<a href="{{url_for('index')}}">
<button type="button"class="btn btn-outline-dark btn-lg" style="width:30%;text-align:center;">ADD MORE TASK</button>
</a>


<script src="{{url_for('static',filename = 'app.js')}}"></script>
{% endblock %}