To answer your second question:

there is a validator named IS_IMAGE so in your model you could write something like:

Field('f_image', type='upload',          represent=lambda x: x and
A('download',_href=URL('download',args=x)) or '',          label=T('Image')
requires = IS_EMPTY_OR(IS_IMAGE('jpeg'))),

This should work, havn´t tested.


Kenneth

I have used the wizard to start working on an app. one of the tabled
upload an file (image). How should I modify the view/control to
display the image? The view and control and db are those created by
the wizard but I have pasted them below.
What is the recommended way to require the uploaded file be a jpg?
I assume what I am asking is documented somewhere I just could not
find it. What should I be reading to know more about images and
web2py?

db.define_table('t_student',
     Field('id','id',
           represent=lambda id:SPAN(id,'
',A('view',_href=URL('student_read',args=id)))),
     Field('f_first_name', type='string', notnull=True,
           label=T('First Name')),
<SNIP>
     Field('f_image', type='upload',
           represent=lambda x: x and
A('download',_href=URL('download',args=x)) or '',
           label=T('Image')),
<SNIP>

CONTROLLER
@auth.requires_login()
def student_read():
     record = db.t_student(request.args(0)) or redirect(URL('error'))
     form=crud.read(db.t_student,record)
     return dict(form=form)

VIEW
{{extend 'layout.html'}}

<h2>Read student</h2>
{{=A(T('edit
student'),_href=URL('student_update',args=request.args(0)))}}
<br/>

{{=form}}
{{for t,f in db.t_student._referenced_by:}}{{if not
t[-8:]=='_archive':}}
[{{=A(t[2:],_href=URL('%s_select'%t[2:],args=(f,form.record.id)))}}]
{{pass}}{{pass}}

Thanks
Vincent

Reply via email to