I have just checked a side project that I did today, and noticed that I
wasnt able to see the pic either. I have been able to fix it using the
upload field:
form = SQLFORM(db.person, record, upload=URL('download'))
I simply added that : upload=URL('download') to my SQLFORM() syntax and it
worked. But I dont think it will work on create, just on updates (because
you wont able to see the pic until is submitted, so it wouldnt be possible
to see it on create).
Give it a try
El martes, 18 de agosto de 2015, 17:47:43 (UTC+2), Carlos Cesar Caballero
escribió:
>
> 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' in request.args or 'new' in request.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:
>
> def posts():
> 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 if auth.has_membership('admin') or
> auth.has_membership('editor'):
> posts_query = db.post
>
> if auth.has_membership('admin') or auth.has_membership('editor') or
> auth.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,)
>
> if request.args(0) in ['edit']:
> db.post.created_on.readable = True post =
> db.post(request.args(2))
> form = SQLFORM(db.post, post)
> if form.process().accepted:
> new_tags = [tag.strip() for tag in request.vars.tags.split(',')]
> post.update_tags(new_tags)
> response.flash = T("Post Updated")
> return dict(grid=form, tags=post.tags)
>
> if request.args(0) in ['new']:
> form = SQLFORM.factory(db.post)
> post_tags = []
> if form.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() for tag in request.vars.tags.split(',')]
> post.update_tags(new_tags)
> post_tags = post.tags
> redirect(URL('dashboard', 'posts'))
> return dict(grid=form, tags=post_tags)
>
> return dict(grid=grid)
>
> and the model:
>
> """ Post model file"""""" Table definition"""import
> redb.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 thumbnailsthumb.create(db.post.image, (175, 175),
> use_imageops=True)
> # Make table sercheablesearch.create(db.post.body)""" Virtual and method
> fields"""# get post tags objectsdb.post.get_post_tags = Field.Method(lambda
> row: [post_tag for post_tag
> in db(db.post_tags.post_id ==
> row.post.id).select()])
> # virtual field for post tagsdb.post.tags = Field.Virtual(lambda row:
> [post_tag.tag_id.name for post_tag
> in db(db.post_tags.post_id ==
> row.post.id).select()])
>
> # update post tagsdef _(row, new_tags):
> self = row.post
> db(db.post_tags.post_id == self.id).delete()
> for tag in new_tags:
> if tag:
> if not db((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 commentsdb.post.get_comments = Field.Method(lambda row:
> db((db.comments.post_id ==
> row.post.id)).select())
> """ Functions"""# get post by iddef get_post_by_id(post_id):
> return db(db.post.id == post_id).select().first()
>
> # get posts by langdef get_posts_by_lang(actual_lang=T.accepted_language):
> return db((db.post.lang == actual_lang) & (db.post.published ==
> True)).select(orderby=~db.post.created_on)
>
> # get post by URLdef get_post_by_url(post_url):
> return db((db.post.url == post_url)).select()
>
> # get posts for paginationdef get_posts_per_page_and_lang(page=0,
> items_per_page=5, actual_lang=T.accepted_language):
> page = 0 if not page else page
> 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)
> return dict(rows=rows, page=page, items_per_page=items_per_page)
>
> # get posts by authordef get_posts_by_author(author_id, lang=None):
> if not lang:
> query = (db.post.created_by == author_id)
> else:
> query = ((db.post.created_by == author_id) & (db.post.lang == lang))
> return db(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 = Falsedb.post.created_on.writable =
> db.post.created_on.readable = Falsedb.post.created_by.writable =
> db.post.created_by.readable = Falsedb.post.modified_on.writable =
> db.post.modified_on.readable = Falsedb.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.
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.