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