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/>
On Apr 6, 12:45 pm, mdipierro <
mdipie...@cs.depaul.edu> wrote:
> I stole it on the web. Not my artwork. Hope the author does not mind.
>
> Massimo
>
> On Apr 6, 2:37 pm, desfrenes <
desfre...@gmail.com> wrote:
>
> > liking the background :-)
>
> > On 6 avr, 21:34, mdipierro <
mdipie...@cs.depaul.edu> wrote:
>
> > > This can already be done. Here is a better layout and absolute Divs.
>
> > >
http://www.web2py.com/events/default/index
>
> > > On Apr 6, 1:52 pm, ceej <
cjlaz...@googlemail.com> wrote:
>
> > > > I think there should defiantly be a way to specify what div the
> > > > response is loaded in and also the option to load different parts of
> > > > the response in different divs.
>
> > > > On Apr 6, 1:42 pm, desfrenes <
desfre...@gmail.com> wrote:
>
> > > > > ok, I understand.
>
> > > > > On 6 avr, 18:17, mdipierro <
mdipie...@cs.depaul.edu> wrote:
>
> > > > > > because, as far as I understand, this does something different.
>
> > > > > > the main point is thatjDivcatches the self-submitting forms and