Hi, I am creatig a blog app and I am having a problem with the grid, when I create or update a post, the post image is never visible in the form (the form show that there is no image), but everything is ok in the db, I supouse that is something related with the code for tagging, there is my view code:

{{
if'edit'inrequest.argsor'new'inrequest.args:
    value =','.join(tags)
    tags_field = DIV(LABEL(T('Tags')+':', _class='control-label col-sm-3'), 
DIV(INPUT(_name='tags',value=value, _class='form-control string'), 
_class='col-sm-9'), _class='form-group')
    grid[0].insert(-1, tags_field)
pass
}}
{{=grid}}


and my controller:

defposts():
    db.post.created_by.readable =True
    db.post.created_on.readable =True
    db.post.modified_by.readable =True
    db.post.modified_on.readable =True

    posts_query = (db.post.created_by == auth.user_id)
    create_post =False

    ifauth.has_membership('admin')orauth.has_membership('editor'):
        posts_query = db.post

    
ifauth.has_membership('admin')orauth.has_membership('editor')orauth.has_membership('author'):
        create_post =True

    grid = SQLFORM.grid(posts_query,orderby=~db.post.created_on,
                        
fields=[db.post.lang,db.post.title,db.post.published,db.post.created_on],
                        paginate=10,create=create_post,)

    ifrequest.args(0)in['edit']:
        db.post.created_on.readable =True
        post = db.post(request.args(2))
        form = SQLFORM(db.post,post)
        ifform.process().accepted:
            new_tags = [tag.strip()fortaginrequest.vars.tags.split(',')]
            post.update_tags(new_tags)
            response.flash = T("Post Updated")
        returndict(grid=form,tags=post.tags)

    ifrequest.args(0)in['new']:
        form = SQLFORM.factory(db.post)
        post_tags = []
        ifform.process().accepted:
            post_id = db.post.insert(**db.post._filter_fields(form.vars))
            post = db(db.post.id == post_id).select().first()
            new_tags = [tag.strip()fortaginrequest.vars.tags.split(',')]
            post.update_tags(new_tags)
            post_tags = post.tags
            redirect(URL('dashboard','posts'))
        returndict(grid=form,tags=post_tags)

    returndict(grid=grid)

and the model:

"""
    Post model file
"""

"""
    Table definition
"""
importre

db.define_table('post',
                Field('lang',label=T('Language')),
                Field('title',unique=True,label=T('Title')),
                Field('url',unique=True,label=T('URL')),
                Field('abstract','text',label=T('Abstract')),
                Field('body','text',widget=ckeditor.widget,label=T('Body')),
                Field('image','upload',autodelete=True,label=T('Image')),
                Field('published','boolean',default=True,label=T('Published')),
                Field('show_title','boolean',default=True,label=T('Show 
title')),
                Field('show_comments','boolean',default=True,label=T('Show 
comments')),
                Field('close_comments','boolean',default=False,label=T('Close 
comments')),
                Field('show_tags','boolean',default=True,label=T('Show tags')),
                auth.signature,
                )

# post image thumbnails
thumb.create(db.post.image,(175,175),use_imageops=True)

# Make table sercheable
search.create(db.post.body)

"""
    Virtual and method fields
"""

# get post tags objects
db.post.get_post_tags = Field.Method(lambdarow: [post_tagforpost_tag
                            indb(db.post_tags.post_id == row.post.id).select()])

# virtual field for post tags
db.post.tags = Field.Virtual(lambdarow: [post_tag.tag_id.nameforpost_tag
                            indb(db.post_tags.post_id == row.post.id).select()])


# update post tags
def_(row,new_tags):
    self = row.post
    db(db.post_tags.post_id == self.id).delete()
    fortaginnew_tags:
        iftag:
            if notdb((db.tags.name == tag) & (db.tags.lang == 
self.lang)).select():
                db.tags.insert(name=tag,lang=self.lang)
            tag_id = db((db.tags.name == tag) & (db.tags.lang == 
self.lang)).select().first().id
            db.post_tags.insert(post_id=self.id,tag_id=tag_id)
    db.commit()
db.post.update_tags = Field.Method(_)


# get post comments
db.post.get_comments = Field.Method(lambdarow:
                                    db((db.comments.post_id == 
row.post.id)).select())

"""
    Functions
"""


# get post by id
defget_post_by_id(post_id):
    returndb(db.post.id == post_id).select().first()


# get posts by lang
defget_posts_by_lang(actual_lang=T.accepted_language):
    returndb((db.post.lang == actual_lang) & (db.post.published 
==True)).select(orderby=~db.post.created_on)


# get post by URL
defget_post_by_url(post_url):
    returndb((db.post.url == post_url)).select()


# get posts for pagination
defget_posts_per_page_and_lang(page=0,items_per_page=5,actual_lang=T.accepted_language):
    page =0if notpageelsepage
    limit_by = (page*items_per_page,(page+1)*items_per_page+1)
    rows = db((db.post.lang == actual_lang) & (db.post.published 
==True)).select(db.post.ALL,limitby=limit_by,orderby=~db.post.created_on)
    returndict(rows=rows,page=page,items_per_page=items_per_page)


# get posts by author
defget_posts_by_author(author_id,lang=None):
    if notlang:
        query = (db.post.created_by == author_id)
    else:
        query = ((db.post.created_by == author_id) & (db.post.lang == lang))
    returndb(query).select()


"""
    Validations
"""

db.post.lang.requires = IS_IN_SET(lang_set)
db.post.title.requires = [IS_NOT_EMPTY(),IS_NOT_IN_DB(db,db.post.title)]
db.post.url.requires = [IS_NOT_EMPTY(),IS_SLUG(),IS_NOT_IN_DB(db,db.post.url)]
db.post.abstract.requires = IS_NOT_EMPTY()
db.post.body.requires = IS_NOT_EMPTY()
db.post.published.requires = IS_NOT_EMPTY()
db.post.is_active.writable = db.post.is_active.readable =False
db.post.created_on.writable = db.post.created_on.readable =False
db.post.created_by.writable = db.post.created_by.readable =False
db.post.modified_on.writable = db.post.modified_on.readable =False
db.post.modified_by.writable = db.post.modified_by.readable =False



I can't find the problem, but maybe someone have resolved the same issue, or can see something in the code that I not.




--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to