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

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

Asheesh Laroia lists at asheesh.org
Sun Jan 8 16:35:44 UTC 2012


Excerpts from Nathan Yergler's message of Sun Jan 08 01:35:00 -0500 2012:
> I haven't looked at the specific example you give, but here are some
> general thoughts:
> 
> * Every project of a certain size is going to need some "workhorse"
> tools. Some people call them "utils", some people call them
> "controllers". I'm not a huge fan of "controller" because it's so
> overloaded in other web frameworks that it makes it harder to explain
> what it means for your project.

(-:

We seem to mix the name "helpers" and the name "controllers," which I
find confusing.

> * In my experience passing around requests is usually a sign you don't
> have a very well defined (or test[ed|able]) API; happy to hear you're
> trying to avoid that.

Yay (-:

> * If the utility is model-related, it should obviously go in models
> (and usually on the manager if it doesn't deal with a specific
> instance).

*nod*

> * I really love class based views in Django, particularly once you
> wrap your head around the mixins available
> * I haven't yet done enough with them, however, to have an intuitive
> feeling for how you test their members.

I do, too, and the missions are moving toward that. I just ported the
Subversion mission over yesterday.

The one thing I find totally weird is the way they integrate with urls.py.
I used to really enjoy keeping function names in urls.py, but now you have
to use .as_view(), which means you have to name each URL, which leads to
ugliness like:

        (r'^missions/svn/diff$', mysite.missions.svn.views.Diff.as_view(), None, 'svn_diff'),

rather than the simply and tidy function-based sample:

        (r'^missions/svn/resetrepo$', 'mysite.missions.svn.views.resetrepo'),

(see mysite/urls.py)

> I'll look at the profile code tomorrow (probably evening) and see if
> anything else comes to mind. I suppose a question for you is why are
> you second-guessing what you've done already? Is it intuition, or are
> you running into issues? Is get_geoip_guess_for_ip() an egregious
> example for a particular reason?

It generally feels hard to know where to find code that one is thinking of.

Part of that is that we also use apps somewhat sloppily.

Part of it is that we have both "helpers" and "controllers".

I also just have an intuition that calling this stuff "controllers" feels
icky given how loaded that term means when explaining things to other
people.

-- Asheesh.


More information about the Devel mailing list