Global function on `get_context` portal. www folder


I am creating a web app and I am putting all my files on code on www folder.

Let’s say I have this function:

def _logs():
    doc = {
        'doctype': 'Store Logs',
        'type': 'TEST TYpE',
        'comments': 'TEST'
    logs = frappe.get_doc(doc)

I call this function on get_context function, every time I create a View on www folder. It is a hassle and repetitive.
Is there any way that I can call this code before OR after get_context ?
I tried to put a decorator on get_context(context) but the view breaks and it is not rendered.

Thank You!