Setup site_management for migration to module

This commit is contained in:
Jadowyne Ulve 2025-08-02 19:48:35 -05:00
parent 93390912c0
commit 49d06ad653
14 changed files with 49 additions and 2241 deletions

31
api.py
View File

@ -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)

View File

@ -15,7 +15,7 @@ class DatabaseError(Exception):
self.log_error() self.log_error()
def log_error(self): def log_error(self):
with open("database.log", "a+") as file: with open("logs/database.log", "a+") as file:
file.write("\n") file.write("\n")
file.write(f"{datetime.datetime.now()} --- ERROR --- DatabaseError(message='{self.message}',\n") file.write(f"{datetime.datetime.now()} --- ERROR --- DatabaseError(message='{self.message}',\n")
file.write(f"{" "*41}payload={self.payload},\n") file.write(f"{" "*41}payload={self.payload},\n")

View File

View File

@ -3,29 +3,23 @@ import psycopg2, math, json, datetime, main, copy, requests, process, database,
from config import config, sites_config from config import config, sites_config
from main import unfoldCostLayers from main import unfoldCostLayers
from user_api import login_required 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 @login_required
def workshop(): def site_management_index():
print(session['user']) sites = [site[1] for site in postsqldb.get_sites(session['user']['sites'])]
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
print(session.get('user')['system_admin'])
if not session.get('user')['system_admin']: if not session.get('user')['system_admin']:
return redirect('/logout') return redirect('/logout')
database_config = config() return render_template("site_management.html", current_site=session['selected_site'], sites=sites)
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)
# API CALLS
@workshop_api.route('/workshop/getZones', methods=['GET']) @site_management_api.route('/api/getZones', methods=['GET'])
@login_required @login_required
def getZones(): def getZones():
if request.method == "GET": 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':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'zones': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'}) 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 @login_required
def getLocations(): def getLocations():
if request.method == "GET": 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':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'locations': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'}) 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 @login_required
def getVendors(): def getVendors():
if request.method == "GET": 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':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'vendors': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'}) 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 @login_required
def getBrands(): def getBrands():
if request.method == "GET": 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':False, 'message': 'Zones Loaded Successfully!'})
return jsonify({'brands': records, "end": math.ceil(count/limit), 'error':True, 'message': 'There was a problem loading Zones!'}) 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 @login_required
def getPrefixes(): def getPrefixes():
if request.method == "GET": 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!'}) 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(): def postAddZone():
if request.method == "POST": if request.method == "POST":
database_config = config() database_config = config()
@ -127,7 +121,7 @@ def postAddZone():
return jsonify({'error': False, 'message': f"Zone added to {site_name}."}) 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}."}) 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(): def postEditZone():
if request.method == "POST": if request.method == "POST":
database_config = config() 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': 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}."}) 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(): def postAddLocation():
if request.method == "POST": if request.method == "POST":
database_config = config() database_config = config()
@ -164,7 +158,7 @@ def postAddLocation():
return jsonify({'error': False, 'message': f"Zone added to {site_name}."}) 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}."}) 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(): def postAddVendor():
if request.method == "POST": if request.method == "POST":
database_config = config() database_config = config()
@ -184,7 +178,7 @@ def postAddVendor():
return jsonify({'error': False, 'message': f"Zone added to {site_name}."}) 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}."}) 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(): def postEditVendor():
if request.method == "POST": if request.method == "POST":
database_config = config() 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': 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}."}) 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(): def postAddBrand():
if request.method == "POST": if request.method == "POST":
database_config = config() database_config = config()
@ -217,7 +211,7 @@ def postAddBrand():
return jsonify({'error': False, 'message': f"Brand added to {site_name}."}) 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}."}) 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(): def postEditBrand():
if request.method == "POST": if request.method == "POST":
database_config = config() 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': 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}."}) 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(): def postAddPrefix():
if request.method == "POST": if request.method == "POST":
database_config = config() database_config = config()
@ -252,7 +246,7 @@ def postAddPrefix():
return jsonify({'error': False, 'message': f"Prefix added to {site_name}."}) 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}."}) 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(): def postEditPrefix():
if request.method == "POST": if request.method == "POST":
database_config = config() database_config = config()

View File

@ -71,7 +71,7 @@ let zones_current_page = 1
let zones_end_page = 10 let zones_end_page = 10
let zones_limit = 25 let zones_limit = 25
async function fetchZones(){ 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('page', zones_current_page)
url.searchParams.append('limit', zones_limit) url.searchParams.append('limit', zones_limit)
const response = await fetch(url) const response = await fetch(url)
@ -220,7 +220,7 @@ async function postAddZone() {
let zoneName = `${document.getElementById('ZoneName').value}` let zoneName = `${document.getElementById('ZoneName').value}`
let description = `${document.getElementById('ZoneDescription').value}` let description = `${document.getElementById('ZoneDescription').value}`
const response = await fetch(`/workshop/postAddZone`, { const response = await fetch(`/site_management/api/postAddZone`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -251,7 +251,7 @@ async function postAddZone() {
async function postEditZone(zone_id) { async function postEditZone(zone_id) {
let description = `${document.getElementById('ZoneDescription').value}` let description = `${document.getElementById('ZoneDescription').value}`
const response = await fetch(`/workshop/postEditZone`, { const response = await fetch(`/site_management/api/postEditZone`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -284,7 +284,7 @@ let locations_current_page = 1
let locations_end_page = 10 let locations_end_page = 10
let locations_limit = 25 let locations_limit = 25
async function fetchLocations(){ 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('page', locations_current_page)
url.searchParams.append('limit', locations_limit) url.searchParams.append('limit', locations_limit)
const response = await fetch(url) const response = await fetch(url)
@ -417,7 +417,7 @@ async function postAddLocation() {
let zone_name = document.getElementById(`locationzone_${zone_id}`).innerHTML let zone_name = document.getElementById(`locationzone_${zone_id}`).innerHTML
let uuid = `${zone_name}@${locationName}` let uuid = `${zone_name}@${locationName}`
const response = await fetch(`/workshop/postAddLocation`, { const response = await fetch(`/site_management/api/postAddLocation`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -451,7 +451,7 @@ let vendors_current_page = 1
let vendors_end_page = 10 let vendors_end_page = 10
let vendors_limit = 25 let vendors_limit = 25
async function fetchVendors(){ 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('page', vendors_current_page)
url.searchParams.append('limit', vendors_limit) url.searchParams.append('limit', vendors_limit)
const response = await fetch(url) const response = await fetch(url)
@ -604,7 +604,7 @@ async function postAddVendor() {
let vendor_phone_number = document.getElementById('VendorPhoneNumber').value let vendor_phone_number = document.getElementById('VendorPhoneNumber').value
let vendor_address = document.getElementById('VendorAddress').value let vendor_address = document.getElementById('VendorAddress').value
const response = await fetch(`/workshop/postAddVendor`, { const response = await fetch(`/site_management/api/postAddVendor`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -638,7 +638,7 @@ async function postEditVendor(vendor_id) {
let vendor_phone_number = document.getElementById('VendorPhoneNumber').value let vendor_phone_number = document.getElementById('VendorPhoneNumber').value
let vendor_address = document.getElementById('VendorAddress').value let vendor_address = document.getElementById('VendorAddress').value
const response = await fetch(`/workshop/postEditVendor`, { const response = await fetch(`/site_management/api/postEditVendor`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -671,7 +671,7 @@ let brands_current_page = 1
let brands_end_page = 10 let brands_end_page = 10
let brands_limit = 25 let brands_limit = 25
async function fetchBrands(){ 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('page', brands_current_page)
url.searchParams.append('limit', brands_limit) url.searchParams.append('limit', brands_limit)
const response = await fetch(url) const response = await fetch(url)
@ -813,7 +813,7 @@ async function openEditBrandsModal(brand) {
async function postAddBrand() { async function postAddBrand() {
let brand_name = document.getElementById('BrandName').value let brand_name = document.getElementById('BrandName').value
const response = await fetch(`/workshop/postAddBrand`, { const response = await fetch(`/site_management/api/postAddBrand`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -843,7 +843,7 @@ async function postAddBrand() {
async function postEditBrand(brand_id) { async function postEditBrand(brand_id) {
let brand_name = document.getElementById('BrandName').value let brand_name = document.getElementById('BrandName').value
const response = await fetch(`/workshop/postEditBrand`, { const response = await fetch(`/site_management/api/postEditBrand`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -876,7 +876,7 @@ let prefix_current_page = 1
let prefix_end_page = 10 let prefix_end_page = 10
let prefix_limit = 25 let prefix_limit = 25
async function fetchPrefixes(){ 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('page', prefix_current_page)
url.searchParams.append('limit', prefix_limit) url.searchParams.append('limit', prefix_limit)
const response = await fetch(url) const response = await fetch(url)
@ -1029,7 +1029,7 @@ async function postAddPrefix() {
let prefix_name = document.getElementById('PrefixName').value let prefix_name = document.getElementById('PrefixName').value
let prefix_description = document.getElementById('PrefixDescription').value let prefix_description = document.getElementById('PrefixDescription').value
const response = await fetch(`/workshop/postAddPrefix`, { const response = await fetch(`/site_management/api/postAddPrefix`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -1063,7 +1063,7 @@ async function postEditPrefix(prefix_id) {
let prefix_name = document.getElementById('PrefixName').value let prefix_name = document.getElementById('PrefixName').value
let prefix_description = document.getElementById('PrefixDescription').value let prefix_description = document.getElementById('PrefixDescription').value
const response = await fetch(`/workshop/postEditPrefix`, { const response = await fetch(`/site_management/api/postEditPrefix`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View File

@ -481,5 +481,5 @@
<script type="text/javascript" src="{{ ASSET_URL }}"></script> <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% endassets %}
<script>const session = {{session|tojson}}</script> <script>const session = {{session|tojson}}</script>
<script src="{{ url_for('static', filename='handlers/workshopHandler.js') }}"></script> <script src="{{ url_for('site_management_api.static', filename='js/site_management_handler.js') }}"></script>
</html> </html>

File diff suppressed because one or more lines are too long

View File

@ -1,18 +0,0 @@
# Database Management
- the way I look at it is
## Adding a new item
- item info, food info, logistics info created using the barcode and then attached to item.
- Transcation created against logistics info description "Item added", qty X into primary location within logistics info.
- QTY of X inserted into sites default location with {logistics_info_id: X}
- returns location_id and adds the location to the logistics info, location_data {location_id: X}
## Associating a item to a linkedItem
All transaction history needs to have its associated logistic id changed to the new number (barcode stays the same?) and the new items location info and qty on hand needs to be updated.

View File

@ -1,108 +0,0 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8" />
<title>Workshop</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@materializecss/materialize@2.0.3-alpha/dist/css/materialize.min.css" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/@materializecss/materialize@2.0.3-alpha/dist/js/materialize.min.js"></script>
</head>
<body>
<div class="container">
<div class="section">
<div class="row">
<div class="col s12">
<div class="row">
<div class="col s12 m9" style="background-color: whitesmoke;">
<p class="flow-text" style="text-align: center; padding: 10px;"> Welcome to you personalized workshop, this is where you can add/create/modify
alot of the items and functions in your site. These modals will walk you through what basic info you will need
in order to further expand on your site.</p>
</div>
<div class="col s12 m3" style="background-color: aliceblue;">
<div class="col s6 m6 m-2">
<a class="btn elevated green modal-trigger" href="#modal1" style="width: 100%;">Add Group</a>
</div>
<div class="col s6 m6 m-2">
<button class="btn elevated orange" style="width: 100%;">Add Item</button>
</div>
<div class="col s6 m6 m-2">
<button class="btn elevated blue" style="width: 100%;">Add Shopping List</button>
</div>
<div class="col s6 m6 m-2">
<button class="btn elevated purple" style="width: 100%;">Add Recipe</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Adding a Group...</h4>
<div class="row">
<div class="col s12">
<div class="card-panel">
<span class="blue-text">Groups are internal "grouping" of items that can be of the same type, tag, process, etc. The point of them is that you
can keep track of all of one thing in a list for quick reference.</span>
</div>
</div>
<div class="col s12 m6 input-field outlined p-2">
<input id="group_name" type="text" placeholder=" " maxlength="64">
<label for="group_name">Group Name</label>
<!--<span class="supporting-text">Supporting Text</span>-->
</div>
<div class="input-field col s12 m6 p-2">
<select id="group_type">
<option value="plain" selected>Plain Group</option>
<option value="exclusive">Exclusive Group</option>
<option value="inclusive">Inclusive Group</option>
</select>
<label for="group_type">Group Type</label>
</div>
<div class="input-field col s12 p-2">
<textarea id="group_description" class="materialize-textarea" placeholder="A short description for what this group represents..."></textarea>
<label for="group_description">Group Description</label>
</div>
</div>
</div>
<div class="modal-footer">
<a onclick="addGroup()" class="waves-effect btn">Add</a>
</div>
</div>
</body>
<script>
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.modal');
var instances = M.Modal.init(elems, {
// specify options here
});
});
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems, {
// specify options here
});
});
function addGroup(){
var name = document.getElementById("group_name").value
var description = document.getElementById("group_description").value
var type = document.getElementById("group_type").value
const url = new URL('/addGroup', window.location.origin);
url.searchParams.append('name', name);
url.searchParams.append('description', description);
url.searchParams.append('type', type);
fetch(url)
.then(response => response.json())
.then(data => {
console.log(data)
})
}
</script>
</html>

18
test.py
View File

@ -1,18 +0,0 @@
from config import config
import psycopg2, ast, database, datetime, json, MyDataclasses, process, pprint
import random, uuid, csv, postsqldb
import pdf2image, os, pymupdf, PIL
from pywebpush import webpush, WebPushException
site = MyDataclasses.SitePayload(
"testA",
"Test site A",
1
)
print("payload", site)
x = site.__dict__
print("dict", x)

View File

@ -1,11 +1,11 @@
from flask import Flask, render_template, session, request, redirect, jsonify from flask import Flask, render_template, session, request, redirect, jsonify
from flask_assets import Environment, Bundle from flask_assets import Environment, Bundle
import api, config, user_api, psycopg2, main import config, user_api, psycopg2, main
from user_api import login_required, update_session_user from user_api import login_required, update_session_user
from workshop_api import workshop_api
import database import database
from webpush import trigger_push_notifications_for_subscriptions from webpush import trigger_push_notifications_for_subscriptions
from application.administration import administration_api from application.administration import administration_api
from application.site_management import site_management_api
from application.recipes import recipes_api from application.recipes import recipes_api
from application.items import items_API from application.items import items_API
from application.poe import poe_api from application.poe import poe_api
@ -25,18 +25,15 @@ app.config['FILES_FOLDER'] = FILES_FOLDER
assets = Environment(app) assets = Environment(app)
app.secret_key = '11gs22h2h1a4h6ah8e413a45' app.secret_key = '11gs22h2h1a4h6ah8e413a45'
app.register_blueprint(api.database_api)
app.register_blueprint(user_api.login_app) app.register_blueprint(user_api.login_app)
app.register_blueprint(administration_api.admin_api, url_prefix='/admin') app.register_blueprint(administration_api.admin_api, url_prefix='/admin')
app.register_blueprint(items_API.items_api, url_prefix='/items') app.register_blueprint(items_API.items_api, url_prefix='/items')
app.register_blueprint(poe_api.point_of_ease, url_prefix='/poe') app.register_blueprint(poe_api.point_of_ease, url_prefix='/poe')
app.register_blueprint(workshop_api) app.register_blueprint(site_management_api.site_management_api, url_prefix="/site_management")
app.register_blueprint(receipts_api.receipt_api, url_prefix='/receipts') app.register_blueprint(receipts_api.receipt_api, url_prefix='/receipts')
app.register_blueprint(shoplist_api.shopping_list_api, url_prefix="/shopping-lists") app.register_blueprint(shoplist_api.shopping_list_api, url_prefix="/shopping-lists")
app.register_blueprint(recipes_api.recipes_api, url_prefix='/recipes') app.register_blueprint(recipes_api.recipes_api, url_prefix='/recipes')
js = Bundle('js/uikit.min.js', 'js/uikit-icons.min.js', output='gen/main.js') js = Bundle('js/uikit.min.js', 'js/uikit-icons.min.js', output='gen/main.js')
assets.register('js_all', js) assets.register('js_all', js)
@ -66,6 +63,12 @@ def inject_user():
return dict(username="") return dict(username="")
@app.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!'})
@app.route("/api/push-subscriptions", methods=["POST"]) @app.route("/api/push-subscriptions", methods=["POST"])
def create_push_subscription(): def create_push_subscription():