Easy to use, it will directly override the whitelisted method
Cons
It is an override, not an extension which I don’t really like it much.
Can only be used with floating whitelisted methods (not Class’s whitelist methods)
Can’t be used with non-whitelisted methods (which will need last resource, the monkey patch)
4) Monkey patch
This method must be said to be not the Framework’s approach, but in many cases it cannot be avoided (floating and non-whitelisted methods)
Pros
It is the last ways
Disadvantages
It is an override, not an extension
Writing a patch in __ init __.py will work even if the app with this patch is not installed (if not installed, you have to delete it from the apps folder).
So, how you find this useful, and please correct me if there are better ways out there.
I believe there is a 5) Server Script, which has similar capabilities to editing hooks.
Pros
You make changes via a web browser, instead of hooks.py. This makes it a bit more accessible.
Disadvantages
Your changes aren’t as visible/obvious. Another person who examines `hooks.py’ won’t see anything. They must remember to also go look in the Server Scripts. Comparing and contrasting what’s in there.
And I guess 6) would be Forking. I’ve had to do that sometimes, because what I needed to accomplish was too awkward or risky with Monkey Patching. Or because I just wanted an easy way to perform a diff between my code, versus official code.
There is also System Console which might be useful for one-off interventions with specialized code, or even stuff done from time to time only (made more useable and sustainable with documenting it with your own SOPs [Standard Operation Procedures]).
Also very useful for testing code-bits and getting things right.
Great for getting imports to work.
It has a log so you can re-check later if you forgot code that worked, etc.
It’s not clear whom you mean by “you” and what you mean by “this”. Anyway,
if you want an example for system console, just type “system console” (or the appropriate translation according to your setup) in awesomebar and see what you get. Then run one of the simplest of python code, something like
print('Hello World')
then hit Execute button and see the output below on the page.
To the left of the Execute Button there is another one to open the Logs of what you run.
See the documentation for the Python Script API to get an idea of what you can run in this console, it has certain limitations which you will run into at some point if you know python.
The System Console resembles Server Script, but the latter are linked to certain actions which need to happen for server scripts to run, whereas in the System Console you run your code similarly to a REPL.