diff --git a/VeganStuff/README.md b/VeganStuff/README.md new file mode 100644 index 0000000..90f24ae --- /dev/null +++ b/VeganStuff/README.md @@ -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 \ No newline at end of file diff --git a/VeganStuff/__init__.py b/VeganStuff/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/VeganStuff/dbmodels.py b/VeganStuff/dbmodels.py new file mode 100644 index 0000000..2b43a03 --- /dev/null +++ b/VeganStuff/dbmodels.py @@ -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) diff --git a/VeganStuff/dummydata.py b/VeganStuff/dummydata.py new file mode 100644 index 0000000..8c7b35f --- /dev/null +++ b/VeganStuff/dummydata.py @@ -0,0 +1,2 @@ + +#TODO: Fill in the database with english items from your imagination. Keep it short but presentable. diff --git a/VeganStuff/models.db b/VeganStuff/models.db new file mode 100644 index 0000000..64534a1 Binary files /dev/null and b/VeganStuff/models.db differ diff --git a/VeganStuff/templates/category.html b/VeganStuff/templates/category.html new file mode 100644 index 0000000..65fd5c3 --- /dev/null +++ b/VeganStuff/templates/category.html @@ -0,0 +1,10 @@ + + + + + New category + + + + + \ No newline at end of file diff --git a/VeganStuff/templates/index.html b/VeganStuff/templates/index.html new file mode 100644 index 0000000..cfd4783 --- /dev/null +++ b/VeganStuff/templates/index.html @@ -0,0 +1,10 @@ + + + + + It works! + + + + + \ No newline at end of file diff --git a/VeganStuff/veganstuff.py b/VeganStuff/veganstuff.py new file mode 100644 index 0000000..3f00688 --- /dev/null +++ b/VeganStuff/veganstuff.py @@ -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//', methods=['GET', 'POST']) +def category(category_id): + categoriess = sess.query(Category).all + return render_template('category.html', categories=categoriess) + pass + + +@app.route('/categories//items/', methods=['GET', 'POST']) +def category_items(category_id): + return render_template('index.html') + pass + + +@app.route('/categories//items//', methods=['GET', 'POST']) +def category_item(category_id, item_id): + return render_template('index.html') + pass + + +@app.route('/categories//items/new', methods=['GET', 'POST']) +def category_item_new(category_id): + return render_template('index.html') + pass + + +@app.route('/categories//items//update', methods=['GET', 'POST']) +def category_item_update(category_id, item_id): + return render_template('index.html') + pass + + +@app.route('/categories//items//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//edit', methods=['GET', 'POST']) +def edit_category(category_id): + return render_template('index.html') + pass + + +@app.route('/category//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//', 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//edit', methods=['GET', 'POST']) +def shops_update(shops_id): + return render_template('index.html') + pass + + +@app.route('/shop//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//', 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//update', methods=['GET', 'POST']) +def manufacturer_update(manufacturer_id): + return render_template('index.html') + pass + + +@app.route('/manufacturer//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)