Style Based On Instance

6 views
Skip to first unread message

Dan Gentry

unread,
Apr 9, 2010, 11:25:04 AM4/9/10
to geraldo-users
My goal is to change the style of an ObjectValue based on data in the
instance. Specifically, to print certain detail rows in bold when a
Boolean column is true.

I've tried variations of this:


style = ({'fontName': 'Helvetica-Bold'} if
instance.bold_me else None),

But no luck.

Any suggestions?

Thanks in advance.

Dan Gentry

Marinho Brandao

unread,
Apr 9, 2010, 1:48:46 PM4/9/10
to gerald...@googlegroups.com
Hi Dan,

If you are using version 0.4-alpha-x (one of last alpha commits), you
can use event "before_print" to set it, otherwise (if you are using
previous versions) you should implement an inherited class of the
widget you are using (i.e: ObjectValue) and set it on one of its
methods (probably the best choice would be override __init__ and do
it)

Try and let us know if you had success :)

> --
> Você está recebendo esta mensagem porque se inscreveu no grupo "geraldo-users" dos Grupos do Google.
> Para postar neste grupo, envie um e-mail para gerald...@googlegroups.com.
> Para cancelar a inscrição nesse grupo, envie um e-mail para geraldo-user...@googlegroups.com.
> Para obter mais opções, visite esse grupo em http://groups.google.com/group/geraldo-users?hl=pt-BR.
>
>

--
Marinho Brandão (José Mário)
http://marinhobrandao.com/

Dan Gentry

unread,
May 21, 2010, 4:21:09 PM5/21/10
to geraldo-users
(Sorry for the slow response. I've been on another project.)

Using the inherited class makes sense, but I don't understand how to
reference a field in the queryset. Here is the class I wrote:

class ObjectValueBold(ObjectValue):
def __init__(self, **kwargs):
super(ObjectValueBold,self).__init__(**kwargs)
if instance.featured_event:
self.style = {'fontName': 'Helvetica-Bold'}

The field 'featured_event' is a Boolean.
> > Para obter mais opções, visite esse grupo emhttp://groups.google.com/group/geraldo-users?hl=pt-BR.

Marinho Brandao

unread,
May 22, 2010, 11:05:06 AM5/22/10
to gerald...@googlegroups.com
Hi Dan,

on __init__ it won't work, but try the following:

class ObjectValueBold(ObjectValue):
    def get_style(self):
style = getattr(self, '_style', {})
        if getattr(self.instance, 'featured_event', None):
style = style.copy()
style['fontName'] = 'Helvetica-Bold'
return style

def set_style(self, value):
self._style = value

style = property(get_style, set_style)

I didn't test it... let me know if it solve your issue :)

Bye
--
Marinho Brandão (José Mário)

Dan Gentry

unread,
May 23, 2010, 8:58:56 AM5/23/10
to geraldo-users
That did the trick!

Thanks so much for the help, and for the great report framework.

On May 22, 11:05 am, Marinho Brandao <mari...@gmail.com> wrote:
> Hi Dan,
>

Marinho Brandao

unread,
May 23, 2010, 6:50:40 PM5/23/10
to gerald...@googlegroups.com
:P
--
Marinho Brandão (José Mário)
Reply all
Reply to author
Forward
0 new messages