Skip to content
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
14 changes: 9 additions & 5 deletions .replit
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
entrypoint = "wsgi.py"
modules = ["python-3.10:v18-20230807-322e88b"]
modules = ["python-3.10", "nix"]

hidden = [".pythonlibs"]
run = "flask run -h 0.0.0.0 -p 8080 --reload"

[nix]
channel = "stable-23_05"
channel = "stable-24_05"

[deployment]
run = ["python3", "wsgi.py"]
deploymentTarget = "cloudrun"
run = ["sh", "-c", "flask run -h 0.0.0.0 -p 8080 --reload"]
deploymentTarget = "cloudrun"

[[ports]]
localPort = 8080
externalPort = 80
Binary file modified instance/project.db
Binary file not shown.
50 changes: 49 additions & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,52 @@ def initialize():
db.create_all()
bob = User('bob', 'bob@mail.com', 'bobpass')
print(bob)
print('database intialized')
print('database intialized')
db.session.add(bob)
db.session.commit()
print(bob)

@app.cli.command("get-user", help="Retrieves a User")
@click.argument('username', default='bob')
def get_user(username):
bob = User.query.filter_by(username=username).first()
if not bob:
print(f'{username} not found!')
return
print(bob)

@app.cli.command('get-users')
def get_users():
# gets all objects of a model
users = User.query.all()
print(users)

@app.cli.command("change-email")
@click.argument('username', default='bob')
@click.argument('email', default='bob@mail.com')
def change_email(username, email):
bob = User.query.filter_by(username=username).first()
if not bob:
print(f'{username} not found!')
return
bob.email = email
db.session.add(bob)
db.session.commit()
print(bob)

@app.cli.command('create-user')
@click.argument('username', default='rick')
@click.argument('email', default='rick@mail.com')
@click.argument('password', default='rickpass')
def create_user(username, email, password):
newuser = User(username, email, password)
try:
db.session.add(newuser)
db.session.commit()
except IntegrityError as e:
#let's the database undo any previous steps of a transaction
db.session.rollback()
# print(e.orig) #optionally print the error raised by the database
print("Username or email already taken!") #give the user a useful message
else:
print(newuser) # print the newly created user