Updated edit itemm page

This commit is contained in:
Candifloss 2025-02-06 16:13:09 +05:30
parent 7378e56dc6
commit 4c4f0b25c7
2 changed files with 30 additions and 23 deletions

View File

@ -1,5 +1,6 @@
from flask import Blueprint, request, render_template, redirect
from models import Asset, db
from config import item_attributes
update_bp = Blueprint('editasset', __name__)
@ -13,11 +14,11 @@ def update(assettag):
warrantyfrom = request.form['warrantyfrom']
status = request.form['status']
if status not in ['Active', 'Inactive']:
return render_template('update.html', item=item, exc='status') # Ensure status is valid
return render_template('update.html', item=item, exc='status', item_attributes=item_attributes) # Ensure status is valid
try:
staffnum = int(request.form['staffnum'])
except ValueError:
return render_template('update.html', item=item, exc='staffnum')
return render_template('update.html', item=item, exc='staffnum', item_attributes=item_attributes)
try:
setattr(item, 'assettag', assettag)
@ -28,11 +29,11 @@ def update(assettag):
db.session.commit()
except exc.IntegrityError:
return render_template('update.html', item=item, exc='integrity')
return render_template('update.html', item=item, exc='integrity', item_attributes=item_attributes)
except (exc.StatementError, exc.InvalidRequestError) as e:
return render_template('update.html', item=item, exc='status')
return render_template('update.html', item=item, exc='status', item_attributes=item_attributes)
return redirect(f'/viewall/')
return f"Asset {assettag} is not found"
return render_template('update.html', item=item)
return render_template('update.html', item=item, item_attributes=item_attributes)

View File

@ -8,26 +8,32 @@
<h2 align="center">Update Item</h2>
<form action='' method = "POST">
{% for attrib, properties in item_attributes.items() -%}
<p>
<label for="assettag">Asset Tag:</label>
<input id="assettag" type = "text" name = "assettag" value="{{item.assettag}}" required/>
</p>
<p>
<label for="hostname">Host Name:</label>
<input id="hostname" type = "text" name = "hostname" value="{{item.hostname}}" required/>
</p>
<p>
<label for="warrantyfrom">Warranty From:</label>
<input id="warrantyfrom" type = "date" name = "warrantyfrom" value="{{item.warrantyfrom}}" required/>
</p>
<p>
<label for="status">Status:</label>
<input id="status" type = "integer" name = "status" value="{{item.status}}" required/>
</p>
<p>
<label for="staffnum">Staff No:</label>
<input id="staffnum" type = "integer" name = "staffnum" value="{{item.staffnum}}" required/>
<label for="{{ attrib }}">{{ properties.display_name }}:</label>
{%- if properties.html_input_type == "select" %}
<select
id="{{ attrib }}"
name="{{ attrib }}"
{%- if properties.required %} required {% endif -%}
>
{% for option in properties.options -%}
<option value="{{ option }}">{{ option }}</option>
{% endfor -%}
</select>
{% else %}
<input
id="{{ attrib }}"
type="{{ properties.html_input_type }}"
name="{{ attrib }}"
{%- if properties.required %} required {% endif -%}
{%- if properties.min is not none %} min="{{ properties.min }}" {% endif -%}
{%- if properties.max is not none %} max="{{ properties.max }}" {% endif -%}
{%- if item.attrib %} value="{{ item.attrib }}" {% endif -%}
/>
{% endif -%}
</p>
{% endfor %}
<p><input type = "submit" value = "Update" /></p>
</form>