Hi,
I tried the Web2py manual sample in article "3.6 An Image Blog" and it
worked well with jpeg files, failed to display pdf files. The file
extension in "uploads" folder revealed jpeg files doesn't have
extension but pdf files has. I tried Massimo's solution on
"pdf/doc attachments work in sqlite, not in gql" but didn't work
either, maybe not applicable or missed something. Massimo's solution:
1) the download action should be
def download(): return response.download(request,db)

This will be modified later for download of application forms.
Solution will be along this lines. The following is the code(I copied
it in Web2py manual article 3.6):

models/db.py
--------------------
db.define_table('image',
    SQLField('title'),
    SQLField('author'),
    SQLField('file','upload'))

db.define_table('comment',
    SQLField('image_id', db.image),
    SQLField('author'),
    SQLField('email'),
    SQLField('body','text'))

controllers/default.py
------------------------------
def index():
    images=db().select(db.image.ALL,orderby=db.image.title)
    return dict(images=images)

def show():
    image=db(db.image.id==request.args[0]).select()[0]
    form=SQLFORM(db.comment,fields=['author','email','body'])
    form.vars.image_id=image.id
    if form.accepts(request.vars,session):
        response.flash='your comment is posted'
    comments=db(db.comment.image_id==image.id).select()
    return dict(image=image,comments=comments,form=form)

def download():
    import os
    path=os.path.join(request.folder,'uploads',request.args[0])
    return response.stream(path)

views/default/index.html
----------------------------------
{{extend 'layout.html'}}
<h1>Current Images</h1>
<u1>
{{for image in images:}}
{{=LI(A(image.title,_href=URL(r=request,f="show",args=[image.id])))}}
{{pass}}
</ul>


views/default/show.html
----------------------------------
{{extend 'layout.html'}}
<h1>Image: {{=image.title}}</h1>
<center>
<img width='300px' height='600px' src="{{=URL
(r=request,f='download',args=[image.file])}}"/>

</center>
{{if len(comments):}}
    <h2>Comments</h2><br /><p>
    {{for comment in comments:}}
        <p>{{=comment.author}} says <i>{{=comment.body}}</i></p>
    {{pass}}</p>
{{else:}}
    <h2>No comments posted yet</h2>
{{pass}}
<h2>Post a comment</h2>
{{=form}}

Thank you very much in advance for your help.
Ed
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to