Updated edit itemm page
This commit is contained in:
parent
7378e56dc6
commit
4c4f0b25c7
@ -1,5 +1,6 @@
|
|||||||
from flask import Blueprint, request, render_template, redirect
|
from flask import Blueprint, request, render_template, redirect
|
||||||
from models import Asset, db
|
from models import Asset, db
|
||||||
|
from config import item_attributes
|
||||||
|
|
||||||
update_bp = Blueprint('editasset', __name__)
|
update_bp = Blueprint('editasset', __name__)
|
||||||
|
|
||||||
@ -13,11 +14,11 @@ def update(assettag):
|
|||||||
warrantyfrom = request.form['warrantyfrom']
|
warrantyfrom = request.form['warrantyfrom']
|
||||||
status = request.form['status']
|
status = request.form['status']
|
||||||
if status not in ['Active', 'Inactive']:
|
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:
|
try:
|
||||||
staffnum = int(request.form['staffnum'])
|
staffnum = int(request.form['staffnum'])
|
||||||
except ValueError:
|
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:
|
try:
|
||||||
setattr(item, 'assettag', assettag)
|
setattr(item, 'assettag', assettag)
|
||||||
@ -28,11 +29,11 @@ def update(assettag):
|
|||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except exc.IntegrityError:
|
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:
|
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 redirect(f'/viewall/')
|
||||||
return f"Asset {assettag} is not found"
|
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)
|
@ -8,26 +8,32 @@
|
|||||||
<h2 align="center">Update Item</h2>
|
<h2 align="center">Update Item</h2>
|
||||||
|
|
||||||
<form action='' method = "POST">
|
<form action='' method = "POST">
|
||||||
|
{% for attrib, properties in item_attributes.items() -%}
|
||||||
<p>
|
<p>
|
||||||
<label for="assettag">Asset Tag:</label>
|
<label for="{{ attrib }}">{{ properties.display_name }}:</label>
|
||||||
<input id="assettag" type = "text" name = "assettag" value="{{item.assettag}}" required/>
|
{%- if properties.html_input_type == "select" %}
|
||||||
</p>
|
<select
|
||||||
<p>
|
id="{{ attrib }}"
|
||||||
<label for="hostname">Host Name:</label>
|
name="{{ attrib }}"
|
||||||
<input id="hostname" type = "text" name = "hostname" value="{{item.hostname}}" required/>
|
{%- if properties.required %} required {% endif -%}
|
||||||
</p>
|
>
|
||||||
<p>
|
{% for option in properties.options -%}
|
||||||
<label for="warrantyfrom">Warranty From:</label>
|
<option value="{{ option }}">{{ option }}</option>
|
||||||
<input id="warrantyfrom" type = "date" name = "warrantyfrom" value="{{item.warrantyfrom}}" required/>
|
{% endfor -%}
|
||||||
</p>
|
</select>
|
||||||
<p>
|
{% else %}
|
||||||
<label for="status">Status:</label>
|
<input
|
||||||
<input id="status" type = "integer" name = "status" value="{{item.status}}" required/>
|
id="{{ attrib }}"
|
||||||
</p>
|
type="{{ properties.html_input_type }}"
|
||||||
<p>
|
name="{{ attrib }}"
|
||||||
<label for="staffnum">Staff No:</label>
|
{%- if properties.required %} required {% endif -%}
|
||||||
<input id="staffnum" type = "integer" name = "staffnum" value="{{item.staffnum}}" required/>
|
{%- 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>
|
</p>
|
||||||
|
{% endfor %}
|
||||||
<p><input type = "submit" value = "Update" /></p>
|
<p><input type = "submit" value = "Update" /></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user