Create page uses config
This commit is contained in:
parent
aee98cb2b6
commit
c0cfb3c202
@ -1,5 +1,5 @@
|
||||
class Attribute:
|
||||
def __init__(self, display_name, html_input_type="text", required=False, unique=False, primary=False, regex=None, min=None, max=None, options=None):
|
||||
def __init__(self, display_name, html_input_type="text", required=False, unique=False, primary=False, regex=None, min=None, max=None, options=None, default_val=""):
|
||||
self.display_name = display_name
|
||||
self.html_input_type = html_input_type
|
||||
self.required = required
|
||||
@ -9,8 +9,9 @@ class Attribute:
|
||||
self.min = min
|
||||
self.max = max
|
||||
self.options = options
|
||||
self.default_val = default_val
|
||||
|
||||
tableitems = {
|
||||
item_attributes = {
|
||||
"assettag": Attribute(
|
||||
display_name="Asset Tag",
|
||||
html_input_type="text",
|
||||
@ -29,6 +30,7 @@ tableitems = {
|
||||
"warrantyfrom": Attribute(
|
||||
display_name="Warranty From",
|
||||
html_input_type="date",
|
||||
default_val="2020-03-09",
|
||||
required=True
|
||||
),
|
||||
"status": Attribute(
|
||||
|
@ -1,12 +1,13 @@
|
||||
from flask import Blueprint, request, render_template, redirect
|
||||
from models import Asset, db
|
||||
from config import item_attributes
|
||||
|
||||
addasset_bp = Blueprint('addasset', __name__)
|
||||
|
||||
@addasset_bp.route('/create/', methods=['GET', 'POST'])
|
||||
def create():
|
||||
if request.method == 'GET':
|
||||
return render_template('create.html')
|
||||
return render_template('create.html', item_attributes=item_attributes)
|
||||
|
||||
if request.method == 'POST':
|
||||
assettag = request.form['assettag']
|
||||
|
@ -8,39 +8,45 @@
|
||||
<h2 align="center">Add new Item</h2>
|
||||
|
||||
<form method = "POST">
|
||||
{% for attrib, properties in item_attributes.items() -%}
|
||||
<p>
|
||||
<label for="assettag">Asset Tag:</label>
|
||||
<input id="assettag" type = "text" name = "assettag" required/>
|
||||
</p>
|
||||
<p>
|
||||
<label for="hostname">Host Name:</label>
|
||||
<input id="hostname" type = "text" name = "hostname" required/>
|
||||
</p>
|
||||
<p>
|
||||
<label for="warrantyfrom">Warranty From:</label>
|
||||
<input id="warrantyfrom" type = "date" name = "warrantyfrom" required/>
|
||||
</p>
|
||||
<p>
|
||||
<label for="status">Status:</label>
|
||||
<input id="status" type = "integer" name = "status" required/>
|
||||
</p>
|
||||
<p>
|
||||
<label for="staffnum">Staff No.:</label>
|
||||
<input id="staffnum" type = "integer" name = "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 properties.default_val %} value="{{ properties.default_val }}" {% endif -%}
|
||||
/>
|
||||
{% endif -%}
|
||||
</p>
|
||||
{% endfor %}
|
||||
<p><input type = "submit" value = "Submit" /></p>
|
||||
</form>
|
||||
|
||||
<p align="center">
|
||||
{% if exc == 'integrity' %}
|
||||
{%- if exc == 'integrity' -%}
|
||||
Item with the same assettag already exists
|
||||
{% endif %}
|
||||
{% if exc == 'status' %}
|
||||
Data input error. Price must have a numeric value
|
||||
{% endif %}
|
||||
{% if exc == 'staffnum' %}
|
||||
{%- endif -%}
|
||||
{%- if exc == 'status' -%}
|
||||
Data input error. Invalid status value
|
||||
{%- endif -%}
|
||||
{%- if exc == 'staffnum' -%}
|
||||
Data input error. Staff number must be an integer
|
||||
{% endif %}
|
||||
{%- endif -%}
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user