Monkey patching satchmo

49 views
Skip to first unread message

Bojan Mihelac

unread,
Sep 18, 2008, 4:27:45 AM9/18/08
to Satchmo users
I monkey patched moneyfmt function to format proper price with
currency for shop I am working on.Currently I have it in urls.py like
this:

# monkey patch moneyfmt
import satchmo.l10n.utils
import imutil.hrmoney
satchmo.l10n.utils.moneyfmt = imutil.hrmoney.hr_moneyfmt

I wonder where is the best place to put monkey patch so it is read
only once when satchmo starts?

thanks,
Bojan

Bruce Kroeze

unread,
Sep 18, 2008, 11:49:43 AM9/18/08
to satchm...@googlegroups.com
When I want to do something like that, I:

1) Set up an app for the local site.  Usually I call it "site", and put it in the project directory for the store.
2) Add a "models.py" to the app, containing only the imports I need.
3) Add "site" to INSTALLED_APPS.

--
Bruce Kroeze
http://solidsitesolutions.com
Dynamic Designs, Optimized

Bojan Mihelac

unread,
Sep 19, 2008, 4:17:18 AM9/19/08
to Satchmo users
Bruce, thanks for answer.
Does models.py get imported automatically for all INSTALLED_APPS?

Bruce Kroeze

unread,
Sep 20, 2008, 1:21:18 AM9/20/08
to satchm...@googlegroups.com
On Fri, Sep 19, 2008 at 1:17 AM, Bojan Mihelac <bmih...@gmail.com> wrote:

Bruce, thanks for answer.
Does models.py get imported automatically for all INSTALLED_APPS?

Yes, it does.  What's more, it gets imported in a fairly flexible manner which can handle a certain amount of out-of-order dependencies in the INSTALLED_APPS list.

+Bruce Kroeze
 

Robert Marsanyi

unread,
Jan 9, 2015, 6:46:19 PM1/9/15
to satchm...@googlegroups.com
Ain't monkeypatching grand?

I patched my own moneyfmt() into l10n.utils in the __init__.py of my multicurrency module, per Bruce's suggestion.  My "multicurrency" app is based on "tieredpricing" for products.

--rbt
Reply all
Reply to author
Forward
0 new messages