Skip to content

Commit

Permalink
add web ui@
Browse files Browse the repository at this point in the history
  • Loading branch information
Solomon Berhe committed Feb 5, 2025
1 parent 00e27e0 commit b7218e0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3242,11 +3242,11 @@ <h5>PostgreSQL: A Timeline</h5>
<section>
<h5>Why Was PostgreSQL Invented?</h5>
<ul>
<li><strong>Ingres Limitations:</strong> Lacked extensibility and support for complex data types.</li>
<li><strong>Advanced Data Needs:</strong> Required better handling of objects and relationships.</li>
<li><strong>Scalability:</strong> Needed a more flexible and efficient query engine.</li>
<li><strong>ACID Compliance:</strong> Improved transaction reliability and consistency.</li>
<li><strong>Open-Source Model:</strong> Encouraged community contributions and innovation.</li>
<li><strong>Ingres Limitations:</strong> Lacked extensibility and support for complex data types</li>
<li><strong>Advanced Data Needs:</strong> Required better handling of objects and relationships</li>
<li><strong>Scalability:</strong> Needed a more flexible and efficient query engine</li>
<li><strong>ACID Compliance:</strong> Improved transaction reliability and consistency</li>
<li><strong>Open-Source Model:</strong> Encouraged community contributions and innovation</li>
</ul>
</section>

Expand Down
54 changes: 54 additions & 0 deletions dms/postgress-webserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from flask import Flask, render_template, request, redirect
import psycopg2

app = Flask(__name__)
DATABASE_URL = "postgresql://neondb_owner:npg_M5sVheSzQLv4@ep-shrill-tree-a819xf7v-pooler.eastus2.azure.neon.tech/neondb?sslmode=require"

def get_db_connection():
return psycopg2.connect(DATABASE_URL)

@app.route('/')
def index():
return '''
<h2>Flower Shop Management</h2>
<button onclick="location.href='/flowers'">Manage Flowers</button>
<button onclick="location.href='/customers'">Manage Customers</button>
<button onclick="location.href='/orders'">Manage Orders</button>
'''

@app.route('/flowers')
def manage_flowers():
conn = get_db_connection()
cur = conn.cursor()
cur.execute("SELECT * FROM flowers")
flowers = cur.fetchall()
cur.close()
conn.close()
return render_template('flowers.html', flowers=flowers)

@app.route('/add_flower', methods=['POST'])
def add_flower():
name = request.form['name']
color = request.form['color']
price = request.form['price']
stock = request.form['stock']
conn = get_db_connection()
cur = conn.cursor()
cur.execute("INSERT INTO flowers (name, color, price, stock) VALUES (%s, %s, %s, %s)", (name, color, price, stock))
conn.commit()
cur.close()
conn.close()
return redirect('/flowers')

@app.route('/delete_flower/<int:flower_id>')
def delete_flower(flower_id):
conn = get_db_connection()
cur = conn.cursor()
cur.execute("DELETE FROM flowers WHERE flower_id = %s", (flower_id,))
conn.commit()
cur.close()
conn.close()
return redirect('/flowers')

if __name__ == '__main__':
app.run(debug=True)
29 changes: 29 additions & 0 deletions dms/templates/flowers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flower Shop</title>
</head>
<body>
<h2>Flower Management</h2>

<form action="/add_flower" method="post">
<input type="text" name="name" placeholder="Flower Name" required>
<input type="text" name="color" placeholder="Color">
<input type="number" name="price" placeholder="Price" required>
<input type="number" name="stock" placeholder="Stock" required>
<button type="submit">Add Flower</button>
</form>

<h3>Available Flowers</h3>
<ul>
{% for flower in flowers %}
<li>
{{ flower.name }} ({{ flower.color }}) - ${{ flower.price }} | Stock: {{ flower.stock }}
<a href="/delete_flower/{{ flower.flower_id }}">Delete</a>
</li>
{% endfor %}
</ul>
</body>
</html>

0 comments on commit b7218e0

Please sign in to comment.