[Cubicweb] Understanding _cw

aurélien campéas aurelien.campeas at gmail.com
Thu May 15 23:02:23 CEST 2014


2014-05-15 20:19 GMT+02:00 Nicolas Chauvat <nicolas.chauvat at logilab.fr>:

> Hi,
>
> On Thu, May 15, 2014 at 09:49:49AM +0200, Aurélien Campéas wrote:
> > On 15/05/2014 09:25, Denis Laxalde wrote:
> > > aurélien campéas a écrit :
> > >> Whatever the future holds for _cw, I'd very much like it were re-cast
> as
> > >> just 'cw'.
> > >
> > > At this point, using a descriptive name wouldn't hurt.
> >
> > Yes it would. "cubicweb_god_object" is descriptive but too long.
>
> 1) _cw is short and that is a quality for a name that is used a lot
>    cw would be shorter, but make it less obvious that it is a private
>    attribute
>


I think it could be a local parameter, as in:


  class HelloView(View):
      __regid__ 'hello'
      __select__ = is_instance('IndexCard') & title('summary')

      def render(self, cw, rset, *args, **kw):
          with cw.t.h1(_class=self.__regid__):
              cw.w(cw._('Hello, World, says %s' % cw.appli.name))
          if cw.cnx.is_anonymous:
              cw.w(cw.t.p('Register now and get a free cw !'))
          cw.view('blogentry', rset)

This extreme version is a bit too cw, cw cw cw, cw cw.
In the case of a render method, it makes sense, for use
frequency reasons, to feed t, _ and w as parameters:

  class HelloView(View):
      __regid__ 'hello'
      __select__ = is_instance('IndexCard') & title('summary')

      def render(self, cw, w, t, _, rset, *args, **kw):
          with t.h1(_class=self.__regid__):
              w(_('Hello, World, says %s' % cw.appli.name))
          if cw.cnx.is_anonymous:
              w(t.p('Register now and get a free cw !'))
          cw.view('blogentry', rset)


This clicks.

Regards,
Aurélien.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20140515/de895940/attachment-0095.html>


More information about the Cubicweb mailing list