Skip to content

Commit 3a70426

Browse files
Add files via upload
1 parent 28d8286 commit 3a70426

File tree

7 files changed

+190
-0
lines changed

7 files changed

+190
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Cafe Name,Location,Open,Close,Coffee,Wifi,Power
2+
Lighthaus,https://goo.gl/maps/2EvhB4oq4gyUXKXx9,11AM, 3:30PM,☕☕☕☕️,💪💪,🔌🔌🔌
3+
Esters,https://goo.gl/maps/13Tjc36HuPWLELaSA,8AM,3PM,☕☕☕☕,💪💪💪,🔌
4+
Ginger & White,https://goo.gl/maps/DqMx2g5LiAqv3pJQ9,7:30AM,5:30PM,☕☕☕,✘,🔌
5+
Mare Street Market,https://goo.gl/maps/ALR8iBiNN6tVfuAA8,8AM,1PM,☕☕,💪💪💪,🔌🔌🔌
6+
7+
My Cafe,https://wtforms.readthedocs.io/en/2.3.x/validators/,11 Am,2 Am,☕☕☕☕☕,💪💪💪💪,🔌🔌🔌,

24. Cafe and Wifi Rating/main.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from flask import Flask, render_template
2+
from flask_bootstrap import Bootstrap
3+
from flask_wtf import FlaskForm
4+
from wtforms import StringField, SubmitField,SelectField,URLField
5+
from wtforms.validators import DataRequired,URL
6+
import csv
7+
8+
9+
app = Flask(__name__)
10+
app.config['SECRET_KEY'] = '8BYkEfBA6O6donzWlSihBXox7C0sKR6b'
11+
Bootstrap(app)
12+
13+
14+
class CafeForm(FlaskForm):
15+
cafe = StringField('Cafe name', validators=[DataRequired()])
16+
location = URLField('Cafe Location On Google Map', validators=[URL(require_tld=True, message="Not A Valid URL")])
17+
opening = StringField('Opening Time', validators=[DataRequired()])
18+
closing = StringField('Closing Time', validators=[DataRequired()])
19+
coffe_rating = SelectField('Coffee Rating', choices=['☕','☕☕','☕☕☕','☕☕☕☕','☕☕☕☕☕'],validators=[DataRequired()])
20+
wifi_rating = SelectField('Wifi Strength', choices=['💪', '💪💪', '💪💪💪', '💪💪💪💪', '💪💪💪💪💪'], validators=[DataRequired()])
21+
power = SelectField('Power Socket Availability', choices=['🔌','🔌🔌','🔌🔌🔌','🔌🔌🔌🔌','🔌🔌🔌🔌🔌'],validators=[DataRequired()])
22+
submit = SubmitField('Submit')
23+
24+
25+
26+
27+
# all Flask routes below
28+
@app.route("/")
29+
def home():
30+
return render_template("index.html")
31+
32+
33+
@app.route('/add',methods=["GET","POST"])
34+
def add_cafe():
35+
form = CafeForm()
36+
if form.validate_on_submit():
37+
with open('cafe-data.csv',mode='a') as file:
38+
file.write('\n')
39+
for key in form.data :
40+
if key=='csrf_token' or key=="submit":
41+
continue
42+
file.write(f"{form.data[key]},")
43+
return cafes()
44+
# Exercise:
45+
# Make the form write a new row into cafe-data.csv
46+
# with if form.validate_on_submit()
47+
return render_template('add.html', form=form)
48+
49+
50+
@app.route('/cafes')
51+
def cafes():
52+
with open('cafe-data.csv', newline='') as csv_file:
53+
csv_data = csv.reader(csv_file, delimiter=',')
54+
list_of_rows = []
55+
for row in csv_data:
56+
list_of_rows.append(row)
57+
return render_template('cafes.html', cafes=list_of_rows)
58+
59+
60+
if __name__ == '__main__':
61+
app.run(debug=True,port=8081)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
click==7.1.2
2+
dominate==2.5.2
3+
Flask==1.1.2
4+
Flask-Bootstrap==3.3.7.1
5+
Flask-WTF==0.14.3
6+
itsdangerous==1.1.0
7+
Jinja2==2.11.2
8+
MarkupSafe==1.1.1
9+
visitor==0.1.3
10+
Werkzeug==1.0.1
11+
WTForms==2.3.3
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* This CSS file will need to be added to the styling of
2+
your web pages for the styles to be rendered. */
3+
4+
body {
5+
background-color: #333;
6+
color: white;
7+
}
8+
9+
a {
10+
color: #ffc107;
11+
}
12+
13+
.jumbotron {
14+
display: flex;
15+
align-items: center;
16+
margin: 0;
17+
height: 100vh;
18+
color: white;
19+
background-color: #333;
20+
}
21+
22+
.space-above {
23+
margin-top: 20px;
24+
padding-top: 20px;
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends 'bootstrap/base.html' %}
2+
{% import 'bootstrap/wtf.html' as wtf %}
3+
{% block styles %}
4+
{{super()}}
5+
<link rel="stylesheet"
6+
href="{{url_for('.static', filename='css/styles.css')}}">
7+
{% endblock %}
8+
{% block title %}Add A New Cafe{% endblock %}
9+
10+
{% block content %}
11+
<div class="container">
12+
<div class="row">
13+
<div class="col-sm-12 col-md-8">
14+
15+
<h1>Add a new cafe into the database</h1>
16+
17+
{{ wtf.quick_form(form,novalidate=True) }}
18+
19+
<p class="space-above"><a href="{{url_for('home')}}">See all cafes</a></p>
20+
21+
</div>
22+
</div>
23+
</div>
24+
25+
{% endblock %}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends 'bootstrap/base.html' %}
2+
{% block styles %}
3+
{{super()}}
4+
<link rel="stylesheet"
5+
href="{{url_for('.static', filename='css/styles.css')}}">
6+
{% endblock %}
7+
{% block title %}Restaurants{% endblock %}
8+
9+
{% block content %}
10+
11+
<div class="container">
12+
<div class="row">
13+
<div class="col-sm-12">
14+
15+
<h1>All Cafes</h1>
16+
17+
<table class="table">
18+
{% for cafe in cafes %}
19+
<tr>
20+
{% for item in cafe %}
21+
{% if "http" in item %}
22+
<td><a href ="{{item}}">Maps</a></td>
23+
{% else %}
24+
<td>{{item}}</td>
25+
{%- endif %}
26+
{%- endfor %}
27+
</tr>
28+
{% endfor%}
29+
</table>
30+
31+
<p><a href="{{url_for('home')}}">Return to index page</a></p>
32+
33+
</div>
34+
</div>
35+
</div>
36+
37+
{% endblock %}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends 'bootstrap/base.html' %}
2+
3+
{% block styles %}
4+
{{super()}}
5+
<link rel="stylesheet"
6+
href="{{url_for('.static', filename='css/styles.css')}}">
7+
{% endblock %}
8+
9+
10+
{% block title %}Coffee and Wifi{% endblock %}
11+
12+
13+
{% block content %}
14+
<div class="jumbotron text-center">
15+
<div class="container">
16+
<h1 class="display-4">☕️ Coffee & Wifi 💻</h1>
17+
<p class="lead">Want to work in a cafe but need power and wifi?</p>
18+
<hr class="my-4">
19+
<p>You've found the right place! Checkout my collection of cafes with data on power socket availability, wifi speed and coffee quality.</p>
20+
<a class="btn btn-warning btn-lg" href="{{url_for('cafes')}}" role="button">Show Me!</a>
21+
</div>
22+
</div>
23+
24+
{% endblock %}

0 commit comments

Comments
 (0)