Feat(SQL, UI): Button Icons page, Command Button Links page created with get and set functionality.

This commit is contained in:
2025-07-17 18:58:06 +01:00
parent e0805ec2ed
commit 4e214c3bde
151 changed files with 12224 additions and 463 deletions

View File

@@ -4,7 +4,7 @@ Author: Edward Middleton-Smith
Precision And Research Technology Systems Limited
Technology: App Routing
Feature: Dog - Command Routes
Feature: Dog - Location Routes
Description:
Contact Page Controller.
@@ -13,12 +13,11 @@ Contact Page Controller.
# IMPORTS
# internal
from business_objects.api import API
from business_objects.dog.command import Command
from business_objects.dog.dog_command_link import Dog_Command_Link
from business_objects.dog.location import Location
from datastores.datastore_dog import DataStore_Dog
from forms.dog.command import Filters_Command
from forms.dog.location import Filters_Location
from helpers.helper_app import Helper_App
from models.model_view_dog_command import Model_View_Dog_Command
from models.model_view_dog_location import Model_View_Dog_Location
from models.model_view_home import Model_View_Home
import lib.argument_validation as av
# external
@@ -37,62 +36,62 @@ import datetime
from altcha import ChallengeOptions, create_challenge, verify_solution
routes_dog_command = Blueprint('routes_dog_command', __name__)
routes_dog_location = Blueprint('routes_dog_location', __name__)
@routes_dog_command.route(Model_View_Dog_Command.HASH_PAGE_DOG_COMMANDS, methods=['GET'])
def commands():
Helper_App.console_log('commands')
@routes_dog_location.route(Model_View_Dog_Location.HASH_PAGE_DOG_LOCATIONS, methods=['GET'])
def locations():
Helper_App.console_log('locations')
Helper_App.console_log(f'request_args: {request.args}')
try:
form_filters = Filters_Command.from_json(request.args)
form_filters = Filters_Location.from_json(request.args)
except Exception as e:
Helper_App.console_log(f'Error: {e}')
form_filters = Filters_Command()
form_filters = Filters_Location()
Helper_App.console_log(f'form_filters={form_filters}')
model = Model_View_Dog_Command(form_filters_old = form_filters)
model = Model_View_Dog_Location(form_filters_old = form_filters)
if not model.is_user_logged_in:
return redirect(url_for('routes_core_home.home'))
Helper_App.console_log(f'form_filters={form_filters}')
return render_template('pages/dog/_commands.html', model = model)
return render_template('pages/dog/_locations.html', model = model)
@routes_dog_command.route(Model_View_Dog_Command.HASH_SAVE_DOG_COMMAND, methods=['POST'])
def save_command():
@routes_dog_location.route(Model_View_Dog_Location.HASH_SAVE_DOG_LOCATION, methods=['POST'])
def save_location():
data = Helper_App.get_request_data(request)
try:
form_filters = Filters_Command.from_json(data[Model_View_Dog_Command.FLAG_FORM_FILTERS])
form_filters = Filters_Location.from_json(data[Model_View_Dog_Location.FLAG_FORM_FILTERS])
if not form_filters.validate_on_submit():
return jsonify({
Model_View_Dog_Command.FLAG_STATUS: Model_View_Dog_Command.FLAG_FAILURE,
Model_View_Dog_Command.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}'
Model_View_Dog_Location.FLAG_STATUS: Model_View_Dog_Location.FLAG_FAILURE,
Model_View_Dog_Location.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}'
})
model_return = Model_View_Dog_Command(form_filters_old=form_filters)
model_return = Model_View_Dog_Location(form_filters_old=form_filters)
if not model_return.is_user_logged_in:
raise Exception('User not logged in')
commands = data[Model_View_Dog_Command.FLAG_COMMAND]
if len(commands) == 0:
locations = data[Model_View_Dog_Location.FLAG_LOCATION]
if len(locations) == 0:
return jsonify({
Model_View_Dog_Command.FLAG_STATUS: Model_View_Dog_Command.FLAG_FAILURE,
Model_View_Dog_Command.FLAG_MESSAGE: f'No commands.'
Model_View_Dog_Location.FLAG_STATUS: Model_View_Dog_Location.FLAG_FAILURE,
Model_View_Dog_Location.FLAG_MESSAGE: f'No locations.'
})
objs_command = []
for command in commands:
objs_command.append(Command.from_json(command))
Helper_App.console_log(f'objs_command={objs_command}')
errors = DataStore_Dog.save_commands(data.get('comment', 'No comment'), objs_command)
objs_location = []
for location in locations:
objs_location.append(Location.from_json(location))
Helper_App.console_log(f'objs_location={objs_location}')
errors = DataStore_Dog.save_locations(data.get('comment', 'No comment'), objs_location)
if (len(errors) > 0):
return jsonify({
Model_View_Dog_Command.FLAG_STATUS: Model_View_Dog_Command.FLAG_FAILURE,
Model_View_Dog_Command.FLAG_MESSAGE: f'Error saving commands.\n{model_return.convert_list_objects_to_json(errors)}'
Model_View_Dog_Location.FLAG_STATUS: Model_View_Dog_Location.FLAG_FAILURE,
Model_View_Dog_Location.FLAG_MESSAGE: f'Error saving locations.\n{model_return.convert_list_objects_to_json(errors)}'
})
return jsonify({
Model_View_Dog_Command.FLAG_STATUS: Model_View_Dog_Command.FLAG_SUCCESS,
Model_View_Dog_Command.FLAG_DATA: Model_View_Dog_Command.convert_list_objects_to_json(model_return.commands)
Model_View_Dog_Location.FLAG_STATUS: Model_View_Dog_Location.FLAG_SUCCESS,
Model_View_Dog_Location.FLAG_DATA: Model_View_Dog_Location.convert_list_objects_to_json(model_return.locations)
})
except Exception as e:
return jsonify({
Model_View_Dog_Command.FLAG_STATUS: Model_View_Dog_Command.FLAG_FAILURE,
Model_View_Dog_Command.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'
Model_View_Dog_Location.FLAG_STATUS: Model_View_Dog_Location.FLAG_FAILURE,
Model_View_Dog_Location.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'
})