From be7bb93395a334769a0cb5d8f9e005e1ae1dcac2 Mon Sep 17 00:00:00 2001 From: cheezedoodle2 Date: Wed, 24 May 2023 14:14:43 -0700 Subject: [PATCH 1/2] Updated list of required modules --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 4b3d80c..9fcfb3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ pandas numpy h5py selenium +sqlalchemy +flask From b231bf21a81d917a54d5cdbe99e9f00c3ec6572d Mon Sep 17 00:00:00 2001 From: cheezedoodle2 Date: Wed, 24 May 2023 14:44:55 -0700 Subject: [PATCH 2/2] Modified startup logic, added user dump --- fp3_1.py | 41 ++++++++++++++++-------------- test3.html => templates/test3.html | 7 +++++ 2 files changed, 29 insertions(+), 19 deletions(-) rename test3.html => templates/test3.html (64%) diff --git a/fp3_1.py b/fp3_1.py index 27626f3..9864cdc 100644 --- a/fp3_1.py +++ b/fp3_1.py @@ -1,5 +1,6 @@ +import sqlalchemy from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, Float, DateTime -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import declarative_base from sqlalchemy.orm import relationship, sessionmaker import sys from flask import Flask, render_template @@ -69,6 +70,8 @@ class User(Base): credentials = Column(String) creation_date = Column(DateTime) modification_date = Column(DateTime) + def __str__(self): + return f"{self.id=} {self.username=} {self.creation_date=} {self.modification_date=}" class RetailerProduct(Base): __tablename__ = 'retailer_product' @@ -78,11 +81,24 @@ class RetailerProduct(Base): # Create the database tables Base.metadata.create_all(engine) +@app.route('/') +def homepage(): + # Create a session + session = Session() + + # Get all the classes from SQLAlchemy + classes = Base.__subclasses__() + + statement = sqlalchemy.select(User) + users = session.scalars(statement).all() + + # Render the template with the classes + return render_template('test3.html', classes=classes, users=users) + # Create command-line arguments for the user class def main(): if len(sys.argv) < 2: - print("Usage: python user_tool.py [create|edit|delete]") - return + app.run() command = sys.argv[1] @@ -143,21 +159,8 @@ def main(): print("User not found.") else: - print("Invalid command.") + print("Usage: python user_tool.py [create|edit|delete]") + return if __name__ == "__main__": - main() - -@app.route('/') -def homepage(): - # Create a session - session = Session() - - # Get all the classes from SQLAlchemy - classes = Base.__subclasses__() - - # Render the template with the classes - return render_template('test3.html', classes=classes) - -if __name__ == '__main__': - app.run() \ No newline at end of file + main() \ No newline at end of file diff --git a/test3.html b/templates/test3.html similarity index 64% rename from test3.html rename to templates/test3.html index fa1d4d5..c9916d6 100644 --- a/test3.html +++ b/templates/test3.html @@ -10,5 +10,12 @@
  • {{ class.__name__ }}
  • {% endfor %} + +

    User Dump

    +