More modularity
This commit is contained in:
parent
a7265dc6c1
commit
bf0298e342
2
app.py
2
app.py
@ -1,6 +1,6 @@
|
|||||||
from flask import Flask, redirect
|
from flask import Flask, redirect
|
||||||
from sqlalchemy import exc
|
from sqlalchemy import exc
|
||||||
from models import *
|
from definitions.models import *
|
||||||
|
|
||||||
# Import the Blueprints
|
# Import the Blueprints
|
||||||
from routes.viewall import viewall_bp
|
from routes.viewall import viewall_bp
|
||||||
|
13
config.py
13
config.py
@ -1,15 +1,4 @@
|
|||||||
class Attribute:
|
from definitions.attribute import Attribute
|
||||||
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
|
|
||||||
self.unique = unique
|
|
||||||
self.primary = primary
|
|
||||||
self.regex = regex
|
|
||||||
self.min = min
|
|
||||||
self.max = max
|
|
||||||
self.options = options
|
|
||||||
self.default_val = default_val
|
|
||||||
|
|
||||||
item_attributes = {
|
item_attributes = {
|
||||||
"assettag": Attribute(
|
"assettag": Attribute(
|
||||||
|
15
definitions/attribute.py
Normal file
15
definitions/attribute.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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, default_val="", auto_increment=False, index=False, comment=""):
|
||||||
|
self.display_name = display_name
|
||||||
|
self.html_input_type = html_input_type
|
||||||
|
self.required = required
|
||||||
|
self.unique = unique
|
||||||
|
self.primary = primary
|
||||||
|
self.regex = regex
|
||||||
|
self.min = min
|
||||||
|
self.max = max
|
||||||
|
self.options = options
|
||||||
|
self.default_val = default_val
|
||||||
|
self.auto_increment = auto_increment
|
||||||
|
self.index = index
|
||||||
|
self.comment = comment
|
@ -22,24 +22,3 @@ class Asset(db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<AssetTest {self.assettag}: {self.hostname}>"
|
return f"<AssetTest {self.assettag}: {self.hostname}>"
|
||||||
|
|
||||||
""" Original code
|
|
||||||
class Item(db.Model):
|
|
||||||
__tablename__ = "Item"
|
|
||||||
|
|
||||||
id = db.Column(db.Integer(), primary_key=True)
|
|
||||||
sku = db.Column(db.String(), unique=True)
|
|
||||||
name = db.Column(db.String())
|
|
||||||
description = db.Column(db.String())
|
|
||||||
price = db.Column(db.DECIMAL(9, 2))
|
|
||||||
qty = db.Column(db.Integer())
|
|
||||||
|
|
||||||
def __init__(self, sku, name, description, price, qty):
|
|
||||||
self.sku = sku
|
|
||||||
self.name = name
|
|
||||||
self.description = description
|
|
||||||
self.price = price
|
|
||||||
self.qty = qty
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"{self.name}:{self.sku}"
|
|
||||||
"""
|
|
@ -15,7 +15,7 @@ def get_csv_data(file):
|
|||||||
raise ValueError(f"CSV file must include headers: {', '.join(required_headers)}.")
|
raise ValueError(f"CSV file must include headers: {', '.join(required_headers)}.")
|
||||||
|
|
||||||
# Check for invalid headers
|
# Check for invalid headers
|
||||||
if extra_headers := csv_headers - valid_headers:
|
if extra_headers := csv_headers - required_headers:
|
||||||
raise ValueError(f"Unexpected headers found: {', '.join(extra_headers)}")
|
raise ValueError(f"Unexpected headers found: {', '.join(extra_headers)}")
|
||||||
|
|
||||||
# Extract data dynamically based on config
|
# Extract data dynamically based on config
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, redirect, session, request, jsonify
|
from flask import Blueprint, redirect, session, request, jsonify
|
||||||
from models import Asset, db
|
from definitions.models import Asset, db
|
||||||
import json
|
import json
|
||||||
from config import item_attributes # Import the configuration
|
from config import item_attributes # Import the configuration
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, request, render_template, redirect
|
from flask import Blueprint, request, render_template, redirect
|
||||||
from models import Asset, db
|
from definitions.models import Asset, db
|
||||||
from config import item_attributes
|
from config import item_attributes
|
||||||
|
|
||||||
addasset_bp = Blueprint('addasset', __name__)
|
addasset_bp = Blueprint('addasset', __name__)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, request, render_template, redirect, abort
|
from flask import Blueprint, request, render_template, redirect, abort
|
||||||
from models import Asset, db
|
from definitions.models import Asset, db
|
||||||
from config import item_attributes
|
from config import item_attributes
|
||||||
|
|
||||||
delete_bp = Blueprint('deleteasset', __name__)
|
delete_bp = Blueprint('deleteasset', __name__)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, Response
|
from flask import Blueprint, Response
|
||||||
from models import Asset
|
from definitions.models import Asset
|
||||||
import csv
|
import csv
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, request, render_template, redirect
|
from flask import Blueprint, request, render_template, redirect
|
||||||
from models import Asset, db
|
from definitions.models import Asset, db
|
||||||
from config import item_attributes
|
from config import item_attributes
|
||||||
from sqlalchemy import exc # Import exc for database exceptions
|
from sqlalchemy import exc # Import exc for database exceptions
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from flask import Blueprint, request, render_template, redirect, session
|
from flask import Blueprint, request, render_template, redirect, session
|
||||||
import csv
|
import csv
|
||||||
from io import TextIOWrapper
|
from io import TextIOWrapper
|
||||||
from models import Asset, db
|
from definitions.models import Asset, db
|
||||||
from process_csv import get_csv_data # Import the CSV processing function
|
from process_csv import get_csv_data # Import the CSV processing function
|
||||||
from config import item_attributes # Import the configuration
|
from config import item_attributes # Import the configuration
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, render_template
|
from flask import Blueprint, render_template
|
||||||
from models import Asset
|
from definitions.models import Asset
|
||||||
from config import item_attributes
|
from config import item_attributes
|
||||||
|
|
||||||
viewall_bp = Blueprint('viewall', __name__)
|
viewall_bp = Blueprint('viewall', __name__)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, request, render_template
|
from flask import Blueprint, request, render_template
|
||||||
from models import Asset, db
|
from definitions.models import Asset, db
|
||||||
|
|
||||||
viewasset_bp = Blueprint('viewasset', __name__)
|
viewasset_bp = Blueprint('viewasset', __name__)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user