Feat(SQL, UI): Button Icons page, Command Button Links page created with get and set functionality.
This commit is contained in:
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}'
|
||||
})
|
||||
Reference in New Issue
Block a user