I've been trying out the new jDiv container, which works well with the
exception of forms containing upload fields. I thought I would start a
new thread for this, as my previous post (included below), seemed out
of place in the old thread.

Note that in the example code below, I've also tried replacing edit()
with:

def edit():
    user_profile=db(db.user_profile.owner==auth.user.id).select()[0]
    return crud.update(db.user_profile,user_profile.id)


The above change was order to take SQLForm out of the equation and
stick closer to the examples from the website (using crud). The result
is still the same - the form is always accepted, but only changes to
nickname and bio fields are updated to the database, the upload field
is not updated. Take the crud form out of the jDiv and put it directly
on the index page and it works as it should.



-------------- Original Post --------------------

I'm having a problem using upload fields within forms that are used
within jDiv containers. Testing edit() below by itself provides a
form
that I can successfully select and update an image. When I
encapsulate
the same edit() within a jDiv, all fields update with the exception
of
the upload field, even though form.accepts is successful.
The code below contains the essential elements of what I am doing.
Updating the profile edit form correctly forces a refresh of the
other
jDiv that is displaying the profile info, and all fields are updated
correctly when changed, with the exception of the upload field.
Any help with this is appreciated.
P.S. - Despite this hiccup, I am enthusiastic about this addition of
the jDiv container.
db.py model:
--------------------------
db.define_table('user_profile',
    SQLField('nickname', type='string'),
    SQLField('bio', type='text'),
    SQLField('owner', db.auth_user, notnull=True, required=True,
writable=False),
    SQLField('image', 'upload', uploadfield='image_data'),
    SQLField('image_data', type='blob', default='', writable=False)
    )
profile.py controller:
-----------------------------
def index():
    # create profile form and profile info containers
    profile_form = jDiv('',URL(r=request,f='edit'),_id='1')
    user_profile = jDiv('',URL
(r=request,f='profile'),timeout=0.01,_id='2')
return (profile_form = profile_form )
def edit():
    user_profile=db(db.user_profile.owner==auth.user.id).select()[0]
    form=SQLFORM(db.user_profile, user_profile, deletable=False)
    if form.accepts(request.vars,session):
       # refresh profile container
        jDiv.set(jDiv.trigger('#target_2','load'))
    return dict(form=form,user_profile=user_profile)
def profile():
    # first get our profile, if we don't yet
    # have one, then create it
    try:
        profile=db(db.user_profile.owner==auth.user.id).select()[0]
    except:
        db.user_profile.insert(owner=auth.user.id,nickname='n00by')
        profile=db(q_profile).select()[0]
    return dict(profile=profile)
index.html view:
-----------------------------
{{extend 'layout.html'}}
{{=user_profile}}
<hr/>
{{=profile_form}}
profile.html view:
-------------------------
<img width="100", height="100" src="{{ =URL
(r=request,f='download',args=[profile.image]) }}" />
<h4>{{=auth.user.first_name + " " + auth.user.last_name}}'s Profile</
h4>
<hr/><strong>Nickname: {{ =profile.nickname }}</strong><br/>
email: {{=auth.user.email}}<br/>
{{ =profile.bio }}
edit.html view:
-----------------------
<h3>Edit profile</h3>
{{=form}}
<hr/>
--~--~---------~--~----~------------~-------~--~----~
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