On Thu, Jan 3, 2013 at 2:46 AM, Hiroki Kiyohara <[email protected]> wrote:

> Hi, Russ.
>
> Thanks for your reply.That makes sense.I notice that the configuration of
> my suggestion is complex.
> We need to know what the configuration to take the value.It is necessary
> to re-consider the implementation.
>
> Advantage of my approach
> -------------------------------------
> My approaches enables to reuse the condition of the method calling (as
> `predicate function`).
> For example, considering to header's value, session value or
> request.is_secure.
> By dispatch_config, we can reuse these conditions.
> Yes, in the example, the condition (kwargs.get('corn') == '1') is used
> only one time.
>
> And more
> --------------
> Now the configuration takes one predicate function, however, thinking the
> further reusability,
> We can enable the configuration to get more than one function to call one
> method, like...
>
>     dispatch_config = {'get': {'get_corn_1': (corn_predicate,),
>                                'get_corn_1_secure': (corn_predicate, 
> secure_predicate)}
>                       }
>
>
> It is hard to write all complex conditions in View.get method. and it
> can't be reuse.
>

What do you say?
>
>
I say:

def get(self, request, *args, **kwargs):
   if corn_predicate(request):
      if secure_predicate(request):
         return HttpResponse('secure pony with corn')
      return HttpResponse('pony with corn')
   return HttpResponse('pony')

If reuse of predicates is an issue for you, then by all means, reuse them.
That doesn't mean you need to invent a new, inefficient, and highly
restricted scheme for invoking those predicates.

Yours,
Russ Magee %-)

-- 
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.

Reply via email to