2010/10/3 Łukasz Rekucki <lreku...@gmail.com>:
> On 3 October 2010 04:44, Russell Keith-Magee <russ...@keith-magee.com> wrote:
>> 2010/10/3 Łukasz Rekucki <lreku...@gmail.com>:

>>>>> def with_args(view_cls, **kwargs):
>>>>>    return type(view_cls.__name__, (view_cls,), kwargs)
>>>>>
>>>>> # in urls.py:
>>>>>
>>>>>  (r'^somepath', with_args(MyView, option=False)),
>>>>>  # or even
>>>>>  (r'^somepath', MyView.with(option=False)),
>>>>
>>>> I can't deny this would work. It just doesn't feel very Pythonic to me.
>>>
>>> I don't share your feeling about this. Django already uses a similar
>>> idiom in ModelForms - you pass in a base form, some extra options and
>>> get a new subclass. Also, I would consider this as a shortcut for
>>> advanced users and advice beginners to use subclassing.
>>
>> I'm not sure I see the comparison. ModelForms are declared using a
>> metaclass; instances are defined in the normal way that every class is
>> defined. There is a modelform_factory() et al, but they're not class
>> methods; they're standalone functions that can be used to construct
>> new classes.
>>
>> MyView.with(xxx) -- a class method that is a class factory -- isn't a
>> construct with precedent in Django's codebase AFAICT.
>
> We can leave this as a standalone function if that changes anything.
> Another common pattern in use is an instance method that is a instance
> factory. Going up one level seems natural.
>
> PS. I'll try to put up some code today, to represent this approach. Is
> it okay to add this to the wiki page ?

Feel free. Even if we don't end up adopting your proposal, it's
helpful for future generations to know that it *was* proposed (and if
it wasn't accepted, why it wasn't accepted).

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 django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to