python – Planning out a Form class with subclasses help

Context: I work with Ignition, a server software that allows drag and drop to create JavaSwing UI. It doesn’t allow coding of windows directly in fact, only drag and dropping of components to make a window. Its a jython coding environment. Recently, they added a new way to drag and drop ReactJS websites. Additionally, they also allow you to manually craft a backend API that you can serve up regular HTML with for a traditional HTML/CSS/JS type UI. Before I got here, most of the time, a button on the form would have 20 lines like columnValue1 = event.source.getComponent("Text Field").text, some check conditionals, and then a very long SQL query to run.

Current Updates I made to this: Now, I have a function that grabs all the data from the window automatically using naming conventions of components, and puts them into a dictionary, and I built a SQL Query builder to go from dictionary->query, this itself has eliminated a lot of spaghetti code, but I think I can go even farther. I had a script for each module but they all follow the same steps for exmaple

# Sales order module
def create(data):
    result, new_id = db_insert(data)
    post_insert(data, new_id, result)

So I am trying to create a Form class (because again, jython, most python libraries I am cut off from and cannot use) and sub class each individual form for their unique validating/modifying/etc functions. Here is what I have sketched out so far –

class Form(object):
    Generic form class for rendering forms via HTML for WebDev or for Vision - cross compatability.
    form_payload = {}
    form_id = None
    name = None
    def __init__(self, form_payload, form_id=None):
        print "in Form init"
        self.form_payload = form_payload
        self.form_id = form_id

    def validateInsert(self):
        print "validating"
    def modifyInsert(self):
        print "modifying"
    def db_insert(self):
        print "inserting"
    def postInsert(self):
        print "post insert procedure"

    def validateUpdate(self):
        print "validating pre update"
    def modifyUpdate(self):
        print "modifying update"
    def db_update(self):
        print "updating with db"
    def postUpdate(self):
        print "after update"
    def insert(self):
        if self.form_id is not None:
            raise ValueError("Cannot run insert for form that already exists")

    def update(self):
        if self.form_id is None:
            raise ValueError("Cannot run update with an id")

class SalesOrder(Form):
    def __init__(self, form_payload, form_id=None):
        print "in so init"
        super(SalesOrder, self).__init__(form_payload, form_id)
    def validateInsert(self):
        print "actually we need to do this for sales order inserts"
    def validateUpdate(self):
        print "we need to do x, y, and z to validate updating of of sales order"

to get used to writing OOP and seeing how things work. This seems to work properly when I test it – the functions I define inside my subclass get called when defined instead of the base class ones.

Here’s my big question – how do I integrate this class with 3 different types of GUI’s? I have my JavaSwing gui that I use a function to put data into a dictionary, same with the React GUI that has it’s own unique function, and will eventually have to have the same thing with the standard HTML/CSS/JS that will hit an actual API endpoint instead of just directly calling a jython function directly.

Should my Form class have a getData() function that is fed an event or window and is able to parse out the data no matter the GUI source (if it’s even from a GUI at all) and how would I integrate that while keeping the ability to say read a CSV file and run inserts per row?

Lastly, what about going from Form to GUI? For two out of three of the GUI options, I can dynamically code the front end with HTML for the JavaSwing and of course raw HTML/CSS/JS using the Mako jython library (currently impossible for the built in React stuff). Should that be a part of the Form class? Or should that be another class or just a function that gets fed some subclass of my Form class and it works from there?

I guess what I am really getting at is a separation of concerns here. I don’t know where the cutoff should be and where I should include things in either my general class form, or the subclass, if I should make another class or function that handles the data parsing separate from this class, etc. It’s been a while since I’ve seriously done OOP and could use some guidance. I have cleaned up our code base a lot but its still just all functions calling functions and while readable, say I needed to change something for every single form – I would have to change it in as many places as we have forms (a lot) instead of just my base class. Any advice or examples of how you may have handled making your own Form class would be appreciated.