Feat(SQL, UI): Button Icons page, Command Button Links page created with get and set functionality.
This commit is contained in:
97
controllers/dog/button_icon.py
Normal file
97
controllers/dog/button_icon.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Dog - Button Icon Routes
|
||||
|
||||
Description:
|
||||
Contact Page Controller.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from business_objects.api import API
|
||||
from business_objects.dog.button_icon import Button_Icon
|
||||
from datastores.datastore_dog import DataStore_Dog
|
||||
from forms.dog.button_icon import Filters_Button_Icon
|
||||
from helpers.helper_app import Helper_App
|
||||
from models.model_view_dog_button_icon import Model_View_Dog_Button_Icon
|
||||
from models.model_view_home import Model_View_Home
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app, flash
|
||||
from flask_mail import Mail, Message
|
||||
from extensions import db, oauth, mail
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
import json
|
||||
import base64
|
||||
import hmac
|
||||
import hashlib
|
||||
import datetime
|
||||
from altcha import ChallengeOptions, create_challenge, verify_solution
|
||||
|
||||
|
||||
routes_dog_button_icon = Blueprint('routes_dog_button_icon', __name__)
|
||||
|
||||
|
||||
@routes_dog_button_icon.route(Model_View_Dog_Button_Icon.HASH_PAGE_DOG_BUTTON_ICONS, methods=['GET'])
|
||||
def button_icons():
|
||||
Helper_App.console_log('button_icons')
|
||||
Helper_App.console_log(f'request_args: {request.args}')
|
||||
try:
|
||||
form_filters = Filters_Button_Icon.from_json(request.args)
|
||||
except Exception as e:
|
||||
Helper_App.console_log(f'Error: {e}')
|
||||
form_filters = Filters_Button_Icon()
|
||||
Helper_App.console_log(f'form_filters={form_filters}')
|
||||
model = Model_View_Dog_Button_Icon(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/_button_icons.html', model = model)
|
||||
|
||||
@routes_dog_button_icon.route(Model_View_Dog_Button_Icon.HASH_SAVE_DOG_BUTTON_ICON, methods=['POST'])
|
||||
def save_button_icon():
|
||||
data = Helper_App.get_request_data(request)
|
||||
try:
|
||||
form_filters = Filters_Button_Icon.from_json(data[Model_View_Dog_Button_Icon.FLAG_FORM_FILTERS])
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({
|
||||
Model_View_Dog_Button_Icon.FLAG_STATUS: Model_View_Dog_Button_Icon.FLAG_FAILURE,
|
||||
Model_View_Dog_Button_Icon.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}'
|
||||
})
|
||||
model_return = Model_View_Dog_Button_Icon(form_filters_old=form_filters)
|
||||
if not model_return.is_user_logged_in:
|
||||
raise Exception('User not logged in')
|
||||
|
||||
button_icons = data[Model_View_Dog_Button_Icon.FLAG_BUTTON_ICON]
|
||||
if len(button_icons) == 0:
|
||||
return jsonify({
|
||||
Model_View_Dog_Button_Icon.FLAG_STATUS: Model_View_Dog_Button_Icon.FLAG_FAILURE,
|
||||
Model_View_Dog_Button_Icon.FLAG_MESSAGE: f'No button icons.'
|
||||
})
|
||||
objs_button_icon = []
|
||||
for button_icon in button_icons:
|
||||
objs_button_icon.append(Button_Icon.from_json(button_icon))
|
||||
Helper_App.console_log(f'objs_button_icon={objs_button_icon}')
|
||||
errors = DataStore_Dog.save_button_icons(data.get('comment', 'No comment'), objs_button_icon)
|
||||
|
||||
if (len(errors) > 0):
|
||||
return jsonify({
|
||||
Model_View_Dog_Button_Icon.FLAG_STATUS: Model_View_Dog_Button_Icon.FLAG_FAILURE,
|
||||
Model_View_Dog_Button_Icon.FLAG_MESSAGE: f'Error saving button icons.\n{model_return.convert_list_objects_to_json(errors)}'
|
||||
})
|
||||
return jsonify({
|
||||
Model_View_Dog_Button_Icon.FLAG_STATUS: Model_View_Dog_Button_Icon.FLAG_SUCCESS,
|
||||
Model_View_Dog_Button_Icon.FLAG_DATA: Model_View_Dog_Button_Icon.convert_list_objects_to_json(model_return.button_icons)
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
Model_View_Dog_Button_Icon.FLAG_STATUS: Model_View_Dog_Button_Icon.FLAG_FAILURE,
|
||||
Model_View_Dog_Button_Icon.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'
|
||||
})
|
||||
98
controllers/dog/command_button_link.py
Normal file
98
controllers/dog/command_button_link.py
Normal file
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Dog - Dog Command Link Routes
|
||||
|
||||
Description:
|
||||
Contact Page Controller.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from business_objects.api import API
|
||||
from business_objects.dog.command import Command
|
||||
from business_objects.dog.command_button_link import Command_Button_Link
|
||||
from datastores.datastore_dog import DataStore_Dog
|
||||
from forms.dog.command_button_link import Filters_Command_Button_Link
|
||||
from helpers.helper_app import Helper_App
|
||||
from models.model_view_dog_command_button_link import Model_View_Dog_Command_Button_Link
|
||||
from models.model_view_home import Model_View_Home
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app, flash
|
||||
from flask_mail import Mail, Message
|
||||
from extensions import db, oauth, mail
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
import json
|
||||
import base64
|
||||
import hmac
|
||||
import hashlib
|
||||
import datetime
|
||||
from altcha import ChallengeOptions, create_challenge, verify_solution
|
||||
|
||||
|
||||
routes_dog_command_button_link = Blueprint('routes_dog_command_button_link', __name__)
|
||||
|
||||
|
||||
@routes_dog_command_button_link.route(Model_View_Dog_Command_Button_Link.HASH_PAGE_DOG_COMMAND_BUTTON_LINKS, methods=['GET'])
|
||||
def command_button_links():
|
||||
Helper_App.console_log('command_button_links')
|
||||
Helper_App.console_log(f'request_args: {request.args}')
|
||||
try:
|
||||
form_filters = Filters_Command_Button_Link.from_json(request.args)
|
||||
except Exception as e:
|
||||
Helper_App.console_log(f'Error: {e}')
|
||||
form_filters = Filters_Command_Button_Link()
|
||||
Helper_App.console_log(f'form_filters={form_filters}')
|
||||
model = Model_View_Dog_Command_Button_Link(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/_command_button_links.html', model = model)
|
||||
|
||||
@routes_dog_command_button_link.route(Model_View_Dog_Command_Button_Link.HASH_SAVE_DOG_COMMAND_BUTTON_LINK, methods=['POST'])
|
||||
def save_command_button_link():
|
||||
data = Helper_App.get_request_data(request)
|
||||
try:
|
||||
form_filters = Filters_Command_Button_Link.from_json(data[Model_View_Dog_Command_Button_Link.FLAG_FORM_FILTERS])
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({
|
||||
Model_View_Dog_Command_Button_Link.FLAG_STATUS: Model_View_Dog_Command_Button_Link.FLAG_FAILURE,
|
||||
Model_View_Dog_Command_Button_Link.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}'
|
||||
})
|
||||
model_return = Model_View_Dog_Command_Button_Link(form_filters_old=form_filters)
|
||||
if not model_return.is_user_logged_in:
|
||||
raise Exception('User not logged in')
|
||||
|
||||
command_button_links = data[Model_View_Dog_Command_Button_Link.FLAG_COMMAND_BUTTON_LINK]
|
||||
if len(command_button_links) == 0:
|
||||
return jsonify({
|
||||
Model_View_Dog_Command_Button_Link.FLAG_STATUS: Model_View_Dog_Command_Button_Link.FLAG_FAILURE,
|
||||
Model_View_Dog_Command_Button_Link.FLAG_MESSAGE: f'No dog command links.'
|
||||
})
|
||||
objs_command_button_link = []
|
||||
for command_button_link in command_button_links:
|
||||
objs_command_button_link.append(Command_Button_Link.from_json(command_button_link))
|
||||
Helper_App.console_log(f'objs_command_button_link={objs_command_button_link}')
|
||||
errors = DataStore_Dog.save_command_button_links(data.get('comment', 'No comment'), objs_command_button_link)
|
||||
|
||||
if (len(errors) > 0):
|
||||
return jsonify({
|
||||
Model_View_Dog_Command_Button_Link.FLAG_STATUS: Model_View_Dog_Command_Button_Link.FLAG_FAILURE,
|
||||
Model_View_Dog_Command_Button_Link.FLAG_MESSAGE: f'Error saving dog command links.\n{model_return.convert_list_objects_to_json(errors)}'
|
||||
})
|
||||
return jsonify({
|
||||
Model_View_Dog_Command_Button_Link.FLAG_STATUS: Model_View_Dog_Command_Button_Link.FLAG_SUCCESS,
|
||||
Model_View_Dog_Command_Button_Link.FLAG_DATA: Model_View_Dog_Command_Button_Link.convert_list_objects_to_json(model_return.command_button_links)
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
Model_View_Dog_Command_Button_Link.FLAG_STATUS: Model_View_Dog_Command_Button_Link.FLAG_FAILURE,
|
||||
Model_View_Dog_Command_Button_Link.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'
|
||||
})
|
||||
@@ -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}'
|
||||
})
|
||||
Reference in New Issue
Block a user