Skip to content

Commit

Permalink
Code after the sixth episode of Flask Series
Browse files Browse the repository at this point in the history
  • Loading branch information
jimdevops19 committed Dec 15, 2020
1 parent 93ba5fa commit ddaed50
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 06 - Project Restructure/market/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///market.db'
db = SQLAlchemy(app)

from market import routes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 06 - Project Restructure/market/market.db
Binary file not shown.
12 changes: 12 additions & 0 deletions 06 - Project Restructure/market/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from market import db


class Item(db.Model):
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(length=30), nullable=False, unique=True)
price = db.Column(db.Integer(), nullable=False)
barcode = db.Column(db.String(length=12), nullable=False, unique=True)
description = db.Column(db.String(length=1024), nullable=False, unique=True)

def __repr__(self):
return f'Item {self.name}'
13 changes: 13 additions & 0 deletions 06 - Project Restructure/market/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from market import app
from flask import render_template
from market.models import Item

@app.route('/')
@app.route('/home')
def home_page():
return render_template('home.html')

@app.route('/market')
def market_page():
items = Item.query.all()
return render_template('market.html', items=items)
60 changes: 60 additions & 0 deletions 06 - Project Restructure/market/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<title>
{% block title %}

{% endblock %}
</title>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="#">Flask Market</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{{ url_for('home_page') }}">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('market_page') }}">Market</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Register</a>
</li>
</ul>
</div>
</nav>
{% block content %}

{% endblock %}
<!-- Future Content here -->



<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
<style>
body {
background-color: #212121;
color: white
}
</style>
</html>
8 changes: 8 additions & 0 deletions 06 - Project Restructure/market/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% block title %}
Home Page
{% endblock %}

{% block content %}
This is our content for the Home Page
{% endblock %}
34 changes: 34 additions & 0 deletions 06 - Project Restructure/market/templates/market.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'base.html' %}
{% block title %}
Market Page
{% endblock %}

{% block content %}
<table class="table table-hover table-dark">
<thead>
<tr>
<!-- Your Columns HERE -->
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Barcode</th>
<th scope="col">Price</th>
<th scope="col">Options</th>
</tr>
</thead>
<tbody>
<!-- Your rows inside the table HERE: -->
{% for item in items %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.barcode }}</td>
<td>{{ item.price }}$</td>
<td>
<button class="btn btn-outline btn-info">More Info</button>
<button class="btn btn-outline btn-success">Purchase this Item</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
5 changes: 5 additions & 0 deletions 06 - Project Restructure/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from market import app

#Checks if the run.py file has executed directly and not imported
if __name__ == '__main__':
app.run(debug=True)

0 comments on commit ddaed50

Please sign in to comment.