This site is an archive; learn more about 8 years of OpenHatch.

[OH-Dev] views.py + controllers.py: refactoring thoughts requested

Asheesh Laroia asheesh at asheesh.org
Sat Jan 7 19:17:52 UTC 2012


Hi OH-Dev folks,

Something that we've done in OpenHatch's codebase typically is separate 
some generic workhorse code from the stuff that users interact with. The 
idea is to make little pieces that are accessible from lots of parts of 
the code.

I've called these little pieces "controllers", and the user-facing part 
"views". In general, I've tried to make it so that "controllers" don't 
take "request" objects, making them generally easier to test.

I'm starting to second-guess this practice, and wanted tips from people 
who have read/written more Django code than I have.

Sample "controllers" function:

* get_geoip_guess_for_ip(), in mysite/profile/controllers.py

What would be a good way to re-organize this?

For some of these workhorse things, they're only actually used by one 
view. In those cases, we can move the code into a method on a view class, 
so long as the we switch that view to being class-based.

Quite curious to know how to do things well,

-- Asheesh.

P.S. Nathan, I'm especially curious what you think.


More information about the Devel mailing list