On Fri, 2010-10-01 at 11:12 +0200, Hanne Moa wrote: > On 1 October 2010 07:26, Russell Keith-Magee <[email protected]> wrote: > > I already have one specific piece of API feedback: the current > > implementation requires that all view logic is contained in GET(), > > POST() etc style views. This is fine, except for the fact that there > > are occasions where GET and POST share a lot of common logic. > > This! is! Python! Any shared logic can be in another method, or > function for that matter, and need not be canonicalized in an API. All > that would be needed is an example in the docs: > > class TheView(views.ClassView): > > ....def _common(self, bla): > ........# set up models, forms, other preprocessing here > ........# return models/forms or set them on class > ........# could be run from __init__ or __new__ or whatever we wind up with > > ....def GET(self, bla): > ........self._common(bla) > > ....def POST(self, bla): > ........self._common(bla)
Passing things around between '_common' and GET and POST makes a simple view much more complex than it needs to be, especially when you have various local variables that you now have to assign in some way. In the end you will end up just routing it all to the one method: ....def GET(self, *args, **kwargs): ........return self._common(*args, **kwargs) ....def POST(self, *args, **kwargs): ........return self._common(*args, **kwargs) This is just 4 lines of annoying boilerplate to undo the dispatching that was 'helpfully' done for you. I would definitely support a 'request' method (perhaps call it 'dispatch'?) that allows us to avoid that logic. I suspect that every view I've created that used a form would be hampered by having dispatch based on HTTP verb done first. Luke -- "Despair: It's always darkest just before it goes pitch black." (despair.com) Luke Plant || http://lukeplant.me.uk/ -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
