Python Monkey Patch Static Method

Posted By admin On 01/09/21

May 31, 2021 Unfortunately datetime.date is written in C, and so I couldn’t just monkey-patch out the static date.today method. I found a simple way of doing this that involved effectively wrapping the date class with a mock, but passing through calls to the constructor to the real class (and returning real instances). MakeCode programs can be authored in Blocks, Static TypeScript or Static Python.

Python Monkey Patch Static Method

Here is a classic editable list in OpenERP v6.0 :

  1. The big question here is why you are using static methods in the first place. Don't try to use methods from TestCase here. You could just use assert here: assert apiobject.statuscode 200.
  2. PHP KahlanPlugin Monkey::patch - 12件のコード例が見つかりました。すべてオープンソースプロジェクトから抽出されたPHPのKahlanPluginMonkey::patchの実例で、最も評価が高いものを厳選しています。コード例の評価を行っていただくことで、より質の高いコード例が表示されるようになります。.

It’s a custom view I created this month at work for one of our customer to let him select a list of products, then batch-print their labels on stickers.

The view above is produced by the following XML :

If you start searching a product template with the first field, you’ll get a pop-up similar to this one:

As you can see, these kind of pop-up inherits the width of their parent field, which hide the end of all lines if they are too long. It becomes difficult to distinguish the items when all found objects have the same long prefix.

Now I want to get rid of this behavior and let the pop-up menu take all the necessary width it needs to fully display its content.

My instinct told me that this default style could easily be overridden with some static CSS directives. But digging deeper into OpenERP web client code , I realized that the width is dynamically set by the many2one widget itself.

MethodPython Monkey Patch Static Method

The code responsible for this behavior is located in the addons/openerp/static/javascript/m2o.js file, in the ManyToOne.prototype.on_keydown method: Pro tools 12 mac crack torrent.

My goal is now to alter this default behavior, without touching the code in m2o.js .

And thanks to Bryan Forbes’ article , I engineered a method to monkey patch the original ManyToOne.prototype.on_keydown Javascript method.

Here is the code I added in the XML view, just below the line_ids field:

The result of this is a nice looking pop-up which doesn’t break any vanilla Javascript of the OpenERP web client:

Tactical Trunk Monkey Patch

Related content

Python Monkey Patch Static Method Example

Please enable JavaScript to view the comments powered by Disqus .