diff --git a/api.py b/api.py
deleted file mode 100644
index 9267eac..0000000
--- a/api.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from flask import Blueprint, request, render_template, redirect, session, url_for, send_file, jsonify, Response
-import psycopg2, math, json, datetime, main, copy, requests, process, database
-from config import config, sites_config
-from main import unfoldCostLayers
-
-# this is a test!
-
-database_api= Blueprint('database_api', __name__)
-
-@database_api.route("/changeSite", methods=["POST"])
-def changeSite():
- if request.method == "POST":
- site = request.json['site']
- session['selected_site'] = site
- return jsonify({'error': False, 'message': 'Site Changed!'})
-
-@database_api.route("/getVendors")
-def get_vendors():
- database_config = config()
- site_name = session['selected_site']
- vendors = []
- with psycopg2.connect(**database_config) as conn:
- try:
- with conn.cursor() as cur:
- sql = f"SELECT * FROM {site_name}_vendors;"
- cur.execute(sql)
- vendors = cur.fetchall()
- except (Exception, psycopg2.DatabaseError) as error:
- print(error)
-
- return jsonify(vendors=vendors)
\ No newline at end of file
diff --git a/uom.csv b/application/administration/static/uom.csv
similarity index 100%
rename from uom.csv
rename to application/administration/static/uom.csv
diff --git a/application/postsqldb.py b/application/postsqldb.py
index 27b82d2..43706dd 100644
--- a/application/postsqldb.py
+++ b/application/postsqldb.py
@@ -15,7 +15,7 @@ class DatabaseError(Exception):
self.log_error()
def log_error(self):
- with open("database.log", "a+") as file:
+ with open("logs/database.log", "a+") as file:
file.write("\n")
file.write(f"{datetime.datetime.now()} --- ERROR --- DatabaseError(message='{self.message}',\n")
file.write(f"{" "*41}payload={self.payload},\n")
diff --git a/application/site_management/__init__.py b/application/site_management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/workshop_api.py b/application/site_management/site_management_api.py
similarity index 88%
rename from workshop_api.py
rename to application/site_management/site_management_api.py
index 15b7df3..fd5f825 100644
--- a/workshop_api.py
+++ b/application/site_management/site_management_api.py
@@ -3,29 +3,23 @@ import psycopg2, math, json, datetime, main, copy, requests, process, database,
from config import config, sites_config
from main import unfoldCostLayers
from user_api import login_required
-import postsqldb
-workshop_api = Blueprint('workshop_api', __name__)
-@workshop_api.route("/workshop")
+from application import postsqldb, database_payloads
+
+site_management_api = Blueprint('site_management_api', __name__, template_folder="templates", static_folder="static")
+
+# ROOT TEMPLATE ROUTES
+@site_management_api.route("/")
@login_required
-def workshop():
- print(session['user'])
- sites = [site[1] for site in main.get_sites(session['user']['sites'])]
- print(session.get('user')['system_admin'])
+def site_management_index():
+ sites = [site[1] for site in postsqldb.get_sites(session['user']['sites'])]
if not session.get('user')['system_admin']:
return redirect('/logout')
- database_config = config()
- site_name = session['selected_site']
- with psycopg2.connect(**database_config) as conn:
- with conn.cursor() as cur:
- sql = f"SELECT id, name FROM {site_name}_zones;"
- cur.execute(sql)
- zones = cur.fetchall()
- return render_template("other/workshop.html", current_site=session['selected_site'], sites=sites, zones=zones)
+ return render_template("site_management.html", current_site=session['selected_site'], sites=sites)
-
-@workshop_api.route('/workshop/getZones', methods=['GET'])
+# API CALLS
+@site_management_api.route('/api/getZones', methods=['GET'])
@login_required
def getZones():
if request.method == "GET":
@@ -41,7 +35,7 @@ def getZones():
return jsonify({'zones': records, "end": math.ceil(count/limit), 'error':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'zones': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'})
-@workshop_api.route('/workshop/getLocations', methods=['GET'])
+@site_management_api.route('/api/getLocations', methods=['GET'])
@login_required
def getLocations():
if request.method == "GET":
@@ -57,7 +51,7 @@ def getLocations():
return jsonify({'locations': records, "end": math.ceil(count/limit), 'error':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'locations': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'})
-@workshop_api.route('/workshop/getVendors', methods=['GET'])
+@site_management_api.route('/api/getVendors', methods=['GET'])
@login_required
def getVendors():
if request.method == "GET":
@@ -73,7 +67,7 @@ def getVendors():
return jsonify({'vendors': records, "end": math.ceil(count/limit), 'error':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'vendors': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'})
-@workshop_api.route('/workshop/getBrands', methods=['GET'])
+@site_management_api.route('/api/getBrands', methods=['GET'])
@login_required
def getBrands():
if request.method == "GET":
@@ -89,7 +83,7 @@ def getBrands():
return jsonify({'brands': records, "end": math.ceil(count/limit), 'error':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'brands': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'})
-@workshop_api.route('/workshop/getPrefixes', methods=['GET'])
+@site_management_api.route('/api/getPrefixes', methods=['GET'])
@login_required
def getPrefixes():
if request.method == "GET":
@@ -106,7 +100,7 @@ def getPrefixes():
return jsonify({'prefixes': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'})
-@workshop_api.route('/workshop/postAddZone', methods=["POST"])
+@site_management_api.route('/api/postAddZone', methods=["POST"])
def postAddZone():
if request.method == "POST":
database_config = config()
@@ -127,7 +121,7 @@ def postAddZone():
return jsonify({'error': False, 'message': f"Zone added to {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with adding this Zone to {site_name}."})
-@workshop_api.route('/workshop/postEditZone', methods=["POST"])
+@site_management_api.route('/api/postEditZone', methods=["POST"])
def postEditZone():
if request.method == "POST":
database_config = config()
@@ -143,7 +137,7 @@ def postEditZone():
return jsonify({'error': False, 'message': f"{zone['name']} edited in site {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with editing Zone {zone['name']} in {site_name}."})
-@workshop_api.route('/workshop/postAddLocation', methods=["POST"])
+@site_management_api.route('/api/postAddLocation', methods=["POST"])
def postAddLocation():
if request.method == "POST":
database_config = config()
@@ -164,7 +158,7 @@ def postAddLocation():
return jsonify({'error': False, 'message': f"Zone added to {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with adding this Zone to {site_name}."})
-@workshop_api.route('/workshop/postAddVendor', methods=["POST"])
+@site_management_api.route('/api/postAddVendor', methods=["POST"])
def postAddVendor():
if request.method == "POST":
database_config = config()
@@ -184,7 +178,7 @@ def postAddVendor():
return jsonify({'error': False, 'message': f"Zone added to {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with adding this Zone to {site_name}."})
-@workshop_api.route('/workshop/postEditVendor', methods=["POST"])
+@site_management_api.route('/api/postEditVendor', methods=["POST"])
def postEditVendor():
if request.method == "POST":
database_config = config()
@@ -200,7 +194,7 @@ def postEditVendor():
return jsonify({'error': False, 'message': f"{vendor['vendor_name']} edited in site {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with editing Zone {vendor['vendor_name']} in {site_name}."})
-@workshop_api.route('/workshop/postAddBrand', methods=["POST"])
+@site_management_api.route('/api/postAddBrand', methods=["POST"])
def postAddBrand():
if request.method == "POST":
database_config = config()
@@ -217,7 +211,7 @@ def postAddBrand():
return jsonify({'error': False, 'message': f"Brand added to {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with adding this Zone to {site_name}."})
-@workshop_api.route('/workshop/postEditBrand', methods=["POST"])
+@site_management_api.route('/api/postEditBrand', methods=["POST"])
def postEditBrand():
if request.method == "POST":
database_config = config()
@@ -233,7 +227,7 @@ def postEditBrand():
return jsonify({'error': False, 'message': f"{brand['name']} edited in site {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with editing Zone {brand['name']} in {site_name}."})
-@workshop_api.route('/workshop/postAddPrefix', methods=["POST"])
+@site_management_api.route('/api/postAddPrefix', methods=["POST"])
def postAddPrefix():
if request.method == "POST":
database_config = config()
@@ -252,7 +246,7 @@ def postAddPrefix():
return jsonify({'error': False, 'message': f"Prefix added to {site_name}."})
return jsonify({'error': True, 'message': f"These was an error with adding this Prefix to {site_name}."})
-@workshop_api.route('/workshop/postEditPrefix', methods=["POST"])
+@site_management_api.route('/api/postEditPrefix', methods=["POST"])
def postEditPrefix():
if request.method == "POST":
database_config = config()
diff --git a/application/site_management/site_management_database.py b/application/site_management/site_management_database.py
new file mode 100644
index 0000000..e69de29
diff --git a/application/site_management/site_management_processes.py b/application/site_management/site_management_processes.py
new file mode 100644
index 0000000..e69de29
diff --git a/static/handlers/workshopHandler.js b/application/site_management/static/js/site_management_handler.js
similarity index 97%
rename from static/handlers/workshopHandler.js
rename to application/site_management/static/js/site_management_handler.js
index 17a4612..c0a174c 100644
--- a/static/handlers/workshopHandler.js
+++ b/application/site_management/static/js/site_management_handler.js
@@ -71,7 +71,7 @@ let zones_current_page = 1
let zones_end_page = 10
let zones_limit = 25
async function fetchZones(){
- const url = new URL('/workshop/getZones', window.location.origin)
+ const url = new URL('/site_management/api/getZones', window.location.origin)
url.searchParams.append('page', zones_current_page)
url.searchParams.append('limit', zones_limit)
const response = await fetch(url)
@@ -220,7 +220,7 @@ async function postAddZone() {
let zoneName = `${document.getElementById('ZoneName').value}`
let description = `${document.getElementById('ZoneDescription').value}`
- const response = await fetch(`/workshop/postAddZone`, {
+ const response = await fetch(`/site_management/api/postAddZone`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -251,7 +251,7 @@ async function postAddZone() {
async function postEditZone(zone_id) {
let description = `${document.getElementById('ZoneDescription').value}`
- const response = await fetch(`/workshop/postEditZone`, {
+ const response = await fetch(`/site_management/api/postEditZone`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -284,7 +284,7 @@ let locations_current_page = 1
let locations_end_page = 10
let locations_limit = 25
async function fetchLocations(){
- const url = new URL('/workshop/getLocations', window.location.origin)
+ const url = new URL('/site_management/api/getLocations', window.location.origin)
url.searchParams.append('page', locations_current_page)
url.searchParams.append('limit', locations_limit)
const response = await fetch(url)
@@ -417,7 +417,7 @@ async function postAddLocation() {
let zone_name = document.getElementById(`locationzone_${zone_id}`).innerHTML
let uuid = `${zone_name}@${locationName}`
- const response = await fetch(`/workshop/postAddLocation`, {
+ const response = await fetch(`/site_management/api/postAddLocation`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -451,7 +451,7 @@ let vendors_current_page = 1
let vendors_end_page = 10
let vendors_limit = 25
async function fetchVendors(){
- const url = new URL('/workshop/getVendors', window.location.origin)
+ const url = new URL('/site_management/api/getVendors', window.location.origin)
url.searchParams.append('page', vendors_current_page)
url.searchParams.append('limit', vendors_limit)
const response = await fetch(url)
@@ -604,7 +604,7 @@ async function postAddVendor() {
let vendor_phone_number = document.getElementById('VendorPhoneNumber').value
let vendor_address = document.getElementById('VendorAddress').value
- const response = await fetch(`/workshop/postAddVendor`, {
+ const response = await fetch(`/site_management/api/postAddVendor`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -638,7 +638,7 @@ async function postEditVendor(vendor_id) {
let vendor_phone_number = document.getElementById('VendorPhoneNumber').value
let vendor_address = document.getElementById('VendorAddress').value
- const response = await fetch(`/workshop/postEditVendor`, {
+ const response = await fetch(`/site_management/api/postEditVendor`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -671,7 +671,7 @@ let brands_current_page = 1
let brands_end_page = 10
let brands_limit = 25
async function fetchBrands(){
- const url = new URL('/workshop/getBrands', window.location.origin)
+ const url = new URL('/site_management/api/getBrands', window.location.origin)
url.searchParams.append('page', brands_current_page)
url.searchParams.append('limit', brands_limit)
const response = await fetch(url)
@@ -813,7 +813,7 @@ async function openEditBrandsModal(brand) {
async function postAddBrand() {
let brand_name = document.getElementById('BrandName').value
- const response = await fetch(`/workshop/postAddBrand`, {
+ const response = await fetch(`/site_management/api/postAddBrand`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -843,7 +843,7 @@ async function postAddBrand() {
async function postEditBrand(brand_id) {
let brand_name = document.getElementById('BrandName').value
- const response = await fetch(`/workshop/postEditBrand`, {
+ const response = await fetch(`/site_management/api/postEditBrand`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -876,7 +876,7 @@ let prefix_current_page = 1
let prefix_end_page = 10
let prefix_limit = 25
async function fetchPrefixes(){
- const url = new URL('/workshop/getPrefixes', window.location.origin)
+ const url = new URL('/site_management/api/getPrefixes', window.location.origin)
url.searchParams.append('page', prefix_current_page)
url.searchParams.append('limit', prefix_limit)
const response = await fetch(url)
@@ -1029,7 +1029,7 @@ async function postAddPrefix() {
let prefix_name = document.getElementById('PrefixName').value
let prefix_description = document.getElementById('PrefixDescription').value
- const response = await fetch(`/workshop/postAddPrefix`, {
+ const response = await fetch(`/site_management/api/postAddPrefix`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -1063,7 +1063,7 @@ async function postEditPrefix(prefix_id) {
let prefix_name = document.getElementById('PrefixName').value
let prefix_description = document.getElementById('PrefixDescription').value
- const response = await fetch(`/workshop/postEditPrefix`, {
+ const response = await fetch(`/site_management/api/postEditPrefix`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
diff --git a/templates/other/workshop.html b/application/site_management/templates/site_management.html
similarity index 99%
rename from templates/other/workshop.html
rename to application/site_management/templates/site_management.html
index 957a8f4..b5d5ba6 100644
--- a/templates/other/workshop.html
+++ b/application/site_management/templates/site_management.html
@@ -481,5 +481,5 @@
{% endassets %}
-
+