diff --git a/.gitignore b/.gitignore index 894a44cc..a68f00b5 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,16 @@ venv.bak/ # mypy .mypy_cache/ + +# vscode +.vscode + +# gitignore +.gitignore + +# pipfile +Pipfile +Pipfile.lock + +# database stuff +migrations \ No newline at end of file diff --git a/module1-web-application-development-with-flask/web_app/__init__.py b/module1-web-application-development-with-flask/web_app/__init__.py new file mode 100644 index 00000000..2d5439ee --- /dev/null +++ b/module1-web-application-development-with-flask/web_app/__init__.py @@ -0,0 +1,27 @@ +# The init file indicates that the folder lives inside is like a python module +# and facilitates the importing of certain files within that module within that directory. +# The other role that it plays, is it's the entry point. It's the first place to look into that module directory + +# Imports +from flask import Flask +from web_app.models import db, migrate +from web_app.routes.tweets_routes import tweets_routes +from web_app.routes.home_routes import home_routes + +DATABASE_URI = "sqlite:///C:\\Users\\jessi\\OneDrive\\Documents\\School\\Python\\Unit_3\\Sprint_3\\DS-Unit-3-Sprint-3-Productization-and-Cloud\\twitoff_development.db" + +def create_app(): + app = Flask(__name__) + + app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URI + db.init_app(app) + migrate.init_app(app, db) + + app.register_blueprint(tweets_routes) + app.register_blueprint(home_routes) + + return app + +if __name__ == "__main__": + my_app = create_app() + my_app.run(debug=True) \ No newline at end of file diff --git a/module1-web-application-development-with-flask/web_app/models.py b/module1-web-application-development-with-flask/web_app/models.py new file mode 100644 index 00000000..3ec9c5d9 --- /dev/null +++ b/module1-web-application-development-with-flask/web_app/models.py @@ -0,0 +1,13 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_migrate import Migrate + +db = SQLAlchemy() + +migrate = Migrate() + +class Tweets(db.Model): + id = db.Column(db.Integer, primary_key=True) + tweet = db.Column(db.String(128)) + user_id = db.Column(db.String(128)) + \ No newline at end of file diff --git a/module1-web-application-development-with-flask/web_app/routes/home_routes.py b/module1-web-application-development-with-flask/web_app/routes/home_routes.py new file mode 100644 index 00000000..e036de8c --- /dev/null +++ b/module1-web-application-development-with-flask/web_app/routes/home_routes.py @@ -0,0 +1,9 @@ +# web_app/routes/book_routes.py + +from flask import Blueprint, jsonify, request, render_template #, flash, redirect + +home_routes = Blueprint("home_routes", __name__) + +@home_routes.route("/") +def hello(): + return "Hello everyone and welcome to Twitoff!" \ No newline at end of file diff --git a/module1-web-application-development-with-flask/web_app/routes/tweets_routes.py b/module1-web-application-development-with-flask/web_app/routes/tweets_routes.py new file mode 100644 index 00000000..b4456c81 --- /dev/null +++ b/module1-web-application-development-with-flask/web_app/routes/tweets_routes.py @@ -0,0 +1,34 @@ +# web_app/routes/book_routes.py + +from flask import Blueprint, jsonify, request, render_template, flash, redirect +from web_app.models import db, Tweets + +tweets_routes = Blueprint("tweets_routes", __name__) + +@tweets_routes.route("/tweets.json") +def list_tweets(): # my love for the office is vast lmao + tweets = [ + {"id": 1, "Dwight Shrute": "Identiity theft is not a joke JIM."}, + {"id": 2, "Jim Halpert": "Bears. Beets. Battlestar Galactica."}, + {"id": 3, "Michael Scott": "DWIGHT. YOU IGNORANT SLUT"}, + ] + return jsonify(tweets) + +@tweets_routes.route("/tweets/new") +def new_tweet_form(): + return render_template("new_tweet.html") + +@tweets_routes.route("/tweets/create", methods="POST") +def create_tweet(): + print("FORM DATA:", dict(request.form)) #> {"book_title": "___", "author_name": "____"} + + new_tweet = Tweets(tweet=request.form["tweets"], author_id=request.form["author_id"]) + db.session.add(new_tweet) + db.session.commit() + + #return jsonify({ + # "message": "TWEET CREATE OK", + # "book": dict(request.form) + #}) + flash(f"Tweet '{new_tweet.title}' created successfully!", "dark") + return redirect("/tweets") \ No newline at end of file diff --git a/module1-web-application-development-with-flask/web_app/templates/bootstrap_layout.html b/module1-web-application-development-with-flask/web_app/templates/bootstrap_layout.html new file mode 100644 index 00000000..f8624ff3 --- /dev/null +++ b/module1-web-application-development-with-flask/web_app/templates/bootstrap_layout.html @@ -0,0 +1,87 @@ + + +
+ {% block tweet %} +Please fill out the form and submit to create a new tweet!
+ + +{% endblock %} \ No newline at end of file diff --git a/module1-web-application-development-with-flask/web_app/templates/tweets.html b/module1-web-application-development-with-flask/web_app/templates/tweets.html new file mode 100644 index 00000000..7c9872fb --- /dev/null +++ b/module1-web-application-development-with-flask/web_app/templates/tweets.html @@ -0,0 +1,23 @@ + + +{% extends "bootstrap_layout.html" %} +{% set active_page = "tweets" %} + +{% block content %} + +{{ message }}
+ + {% if tweet %} +tweet not found.
+ {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/twitoff_development.db b/twitoff_development.db new file mode 100644 index 00000000..750a2abe Binary files /dev/null and b/twitoff_development.db differ