Browse Source

Add v0.1.3 client edit page and home link consistency

main
def 2 weeks ago
parent
commit
e20ef371c9
  1. 2
      VERSION
  2. 65
      backend/app.py
  3. 74
      templates/clients/edit.html
  4. 8
      templates/clients/list.html

2
VERSION

@ -1 +1 @@
0.1.2
0.1.3

65
backend/app.py

@ -105,7 +105,12 @@ def dbtest():
cursor.execute("SELECT NOW()")
result = cursor.fetchone()
conn.close()
return f"<h1>Database OK</h1><p>DB server time (UTC): {result[0]}</p><p>Displayed local time: {fmt_local(result[0])}</p>"
return f"""
<h1>Database OK</h1>
<p><a href="/">Home</a></p>
<p>DB server time (UTC): {result[0]}</p>
<p>Displayed local time: {fmt_local(result[0])}</p>
"""
except Exception as e:
return f"<h1>Database FAILED</h1><pre>{e}</pre>"
@ -150,6 +155,64 @@ def new_client():
return render_template("clients/new.html")
@app.route("/clients/edit/<int:client_id>", methods=["GET", "POST"])
def edit_client(client_id):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
if request.method == "POST":
company_name = request.form.get("company_name", "").strip()
contact_name = request.form.get("contact_name", "").strip()
email = request.form.get("email", "").strip()
phone = request.form.get("phone", "").strip()
status = request.form.get("status", "").strip()
notes = request.form.get("notes", "").strip()
errors = []
if not company_name:
errors.append("Company name is required.")
if not status:
errors.append("Status is required.")
if errors:
cursor.execute("SELECT * FROM clients WHERE id = %s", (client_id,))
client = cursor.fetchone()
conn.close()
return render_template("clients/edit.html", client=client, errors=errors)
update_cursor = conn.cursor()
update_cursor.execute("""
UPDATE clients
SET company_name = %s,
contact_name = %s,
email = %s,
phone = %s,
status = %s,
notes = %s
WHERE id = %s
""", (
company_name,
contact_name or None,
email or None,
phone or None,
status,
notes or None,
client_id
))
conn.commit()
conn.close()
return redirect("/clients")
cursor.execute("SELECT * FROM clients WHERE id = %s", (client_id,))
client = cursor.fetchone()
conn.close()
if not client:
return "Client not found", 404
return render_template("clients/edit.html", client=client, errors=[])
@app.route("/services")
def services():
conn = get_db_connection()

74
templates/clients/edit.html

@ -0,0 +1,74 @@
<!doctype html>
<html>
<head>
<title>Edit Client</title>
</head>
<body>
<h1>Edit Client</h1>
<p><a href="/">Home</a></p>
<p><a href="/clients">Back to Clients</a></p>
{% if errors %}
<div style="border:1px solid red; padding:10px; margin-bottom:15px;">
<strong>Please fix the following:</strong>
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<form method="post">
<p>
Client Code<br>
<input value="{{ client.client_code }}" readonly>
</p>
<p>
Company Name *<br>
<input name="company_name" value="{{ client.company_name }}" required>
</p>
<p>
Contact Name<br>
<input name="contact_name" value="{{ client.contact_name or '' }}">
</p>
<p>
Email<br>
<input name="email" value="{{ client.email or '' }}">
</p>
<p>
Phone<br>
<input name="phone" value="{{ client.phone or '' }}">
</p>
<p>
Status *<br>
<select name="status" required>
<option value="lead" {% if client.status == 'lead' %}selected{% endif %}>lead</option>
<option value="active" {% if client.status == 'active' %}selected{% endif %}>active</option>
<option value="inactive" {% if client.status == 'inactive' %}selected{% endif %}>inactive</option>
<option value="suspended" {% if client.status == 'suspended' %}selected{% endif %}>suspended</option>
</select>
</p>
<p>
Notes<br>
<textarea name="notes" rows="5" cols="60">{{ client.notes or '' }}</textarea>
</p>
<p>
<button type="submit">Save Client</button>
</p>
</form>
</body>
</html>

8
templates/clients/list.html

@ -8,10 +8,10 @@
<h1>Clients</h1>
<p><a href="/">Home</a></p>
<p><a href="/clients/new">Add Client</a></p>
<table border="1" cellpadding="6">
<tr>
<th>ID</th>
<th>Code</th>
@ -19,10 +19,11 @@
<th>Contact</th>
<th>Email</th>
<th>Phone</th>
<th>Status</th>
<th>Actions</th>
</tr>
{% for c in clients %}
<tr>
<td>{{ c.id }}</td>
<td>{{ c.client_code }}</td>
@ -30,8 +31,9 @@
<td>{{ c.contact_name }}</td>
<td>{{ c.email }}</td>
<td>{{ c.phone }}</td>
<td>{{ c.status }}</td>
<td><a href="/clients/edit/{{ c.id }}">Edit</a></td>
</tr>
{% endfor %}
</table>

Loading…
Cancel
Save