Pergunta

I've seen the question asked a lot around the forums, but still no good answer.

I have a field. It's a URL. It's 'read only'

Keeping it REALLY simple:

   atapi.StringField('Url',
                     mode="r")

The user is not meant to provide a URL, but when they hit 'save' on the edit form, the url will be generated.

Specifically, an event will fire, an attached file will be sent somewhere else, and the result is a url where you can get the file - think "Upload to Youtube" or something.

Now, when the object is in edit mode, I want to display the url - but of course not let them edit it - or even give them the impression that they can edit it. It's a "computed field" but really, it's just a string. No need to compute anything really, so I'm avoiding using an 'expression'.

How do you define this field in archetypes?


Figured it out before I could get the question completed and submitted, so I posted my solution below. Still interested in other answers, tho.

Foi útil?

Solução

HEH. Figured it out as I was typing up the question.

I am using a StringField with a ComputedWidget.

The edit form shows the field, but renders it simply as plain text.

atapi.StringField('Url',
                   mode="rw",
                   widget=atapi.ComputedWidget(label="Url",
                                            description="Url set after upload",
                                            visible = { 'edit' :'visible', 
                                                        'view' : 'visible' },
                                            ),
                  ), 

Hope this helps someone else.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top