Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask application, routes to all the pages needed for the app. Link to … #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions VeganStuff/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Project Name

TODO: Write a project description


TODO: Describe the installation process


TODO: Write usage instructions


1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D


TODO: Write history


TODO: Write credits


TODO: Write license
Empty file added VeganStuff/__init__.py
Empty file.
89 changes: 89 additions & 0 deletions VeganStuff/dbmodels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import os
import sys
from sqlalchemy import Column, ForeignKey, NVARCHAR, INTEGER, BOOLEAN
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()


# TODO: Add picture path and add CRUD functionality, refer to those videos!


class Category(Base):
__tablename__ = 'category'

id = Column(INTEGER, primary_key=True, nullable=False)
name = Column(NVARCHAR, nullable=False)
description = Column(NVARCHAR, nullable=False)

@property
def serialize(self):
"""Return object in easily serializable format"""
return {
'name': self.name,
'description': self.description,
'Unique id': self.id
}


class Manufacturer(Base):
__tablename__ = 'manufacturer'
name = Column(NVARCHAR, primary_key=True, nullable=False)
description = Column(NVARCHAR, nullable=False)

@property
def serialize(self):
"""Return object in easily serializable format"""
return {
'name and unique id': self.name,
'description': self.description,
}


class Shop(Base):
__tablename__ = 'shop'
id = Column(INTEGER, primary_key=True, nullable=False)
name = Column(NVARCHAR, nullable=False)
description = Column(NVARCHAR, nullable=False)

def serialize(self):
"""Return object in easily serializable format"""
return {
'name': self.name,
'description': self.description,
}


class Item(Base):
__tablename__ = 'item'
id = Column(INTEGER, primary_key=True, nullable=False)
type = Column(BOOLEAN, nullable=False)
name = Column(NVARCHAR, nullable=False)
category = Column(INTEGER, ForeignKey('category.id'), nullable=False)
accidentally_vegan = Column(BOOLEAN, nullable=False)
ingredients = Column(NVARCHAR)
m_id = Column(NVARCHAR, ForeignKey('manufacturer.name'), nullable=False)
s_id = Column(INTEGER, ForeignKey('shop.id'), nullable=False)
# Make relationships so the tables know each other or something like that.
Category_id = relationship(Category)
Manufacturer_id = relationship(Manufacturer)
Shop_id = relationship(Shop)

@property
def serialize(self):
"""Return object in easily serializable format"""
return {
'name': self.name,
'category': self.category,
'description': self.description,
'shop id': self.s_id,
'manufacturer': self.m_id,
'unique id': self.id,
}

# Make the database
engine = create_engine('sqlite:///models.db')

Base.metadata.create_all(engine)
2 changes: 2 additions & 0 deletions VeganStuff/dummydata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#TODO: Fill in the database with english items from your imagination. Keep it short but presentable.
Binary file added VeganStuff/models.db
Binary file not shown.
10 changes: 10 additions & 0 deletions VeganStuff/templates/category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>New category</title>
</head>
<body>

</body>
</html>
10 changes: 10 additions & 0 deletions VeganStuff/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>It works!</title>
</head>
<body>

</body>
</html>
151 changes: 151 additions & 0 deletions VeganStuff/veganstuff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
from flask import Flask, render_template, request, redirect, jsonify, url_for
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from dbmodels import Base, Shop, Item, Manufacturer, Category

# TODO: Make everything else here even though you should try to spread out the classes. Reference the MUB project.

app = Flask(__name__)

engine = create_engine('sqlite:///models.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
sess = DBSession()


@app.route('/')
@app.route('/home')
@app.route('/index')
@app.route('/categories/')
def index():
print("You are logged, muhahaha!")
# Show all categories
categories = sess.query(Category).all()
return render_template('index.html', category=categories)
pass


@app.route('/categories/<int:category_id>/', methods=['GET', 'POST'])
def category(category_id):
categoriess = sess.query(Category).all
return render_template('category.html', categories=categoriess)
pass


@app.route('/categories/<int:category_id>/items/', methods=['GET', 'POST'])
def category_items(category_id):
return render_template('index.html')
pass


@app.route('/categories/<int:category_id>/items/<int:item_id>/', methods=['GET', 'POST'])
def category_item(category_id, item_id):
return render_template('index.html')
pass


@app.route('/categories/<int:category_id>/items/new', methods=['GET', 'POST'])
def category_item_new(category_id):
return render_template('index.html')
pass


@app.route('/categories/<int:category_id>/items/<int:item_id>/update', methods=['GET', 'POST'])
def category_item_update(category_id, item_id):
return render_template('index.html')
pass


@app.route('/categories/<int:category_id>/items/<int:item_id>/delete', methods=['GET', 'POST'])
def category_item_delete(category_id, item_id):
return render_template('index.html')
pass


@app.route('/category/new', methods=['GET', 'POST'])
def new_category():
return render_template('index.html')
pass


@app.route('/category/<int:category_id>/edit', methods=['GET', 'POST'])
def edit_category(category_id):
return render_template('index.html')
pass


@app.route('/category/<int:category_id>/delete', methods=['GET', 'POST'])
def delete_category(category_id):
return render_template('index.html')
pass


@app.route('/shops/', methods=['GET', 'POST'])
def shops():
return render_template('index.html')
pass


@app.route('/shops/<int:shop_id>/', methods=['GET', 'POST'])
def shop(shops_id):
return render_template('index.html')
pass


@app.route('/shop/new', methods=['GET', 'POST'])
def shops_new():
return render_template('index.html')
pass


@app.route('/shop/<int:shop_id>/edit', methods=['GET', 'POST'])
def shops_update(shops_id):
return render_template('index.html')
pass


@app.route('/shop/<int:shop_id>/delete', methods=['GET', 'POST'])
def shops_delete(shops_id):
return render_template('index.html')
pass


@app.route('/manufacturers/', methods=['GET', 'POST'])
def manufacturers():
return render_template('index.html')
pass


@app.route('/manufacturers/<int:manufacturer_id>/', methods=['GET', 'POST'])
def manufacturer(manufacturer_id):
return render_template('index.html')
pass


@app.route('/manufacturer/new', methods=['GET', 'POST'])
def manufacturer_new():
return render_template('index.html')
pass


@app.route('/manufacturer/<int:manufacturer_id>/update', methods=['GET', 'POST'])
def manufacturer_update(manufacturer_id):
return render_template('index.html')
pass


@app.route('/manufacturer/<int:manufacturer_id>/delete', methods=['GET', 'POST'])
def manufacturer_delete(manufacturer_id):
return render_template('index.html')
pass
"""
To actually be able to read from a database, remember to use id's AND call them, use unique naming whenever possible.

Conclusion of routes, add additional routes above this comment.
"""

# Standard convention. Call if this is run as the main module.
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5050)