Hello Paolo,

Here some fresher code :

def trip_update():
    # only SQLFORM.factory tested
    form=SQLFORM.factory(db.t_trip, db.t_photos)
    for row in db(db.t_trip.id == request.args(0)).select(db.t_trip.ALL):
        for f in db.t_trip.fields:
            form.vars[f]=row[f]
    photos_files = []
    for row in db(db.t_photos.f_trip_ref ==
request.args(0)).select(db.t_photos.ALL):
        #for f in db.t_photos.fields:
        #f_photo_0:CONTENT_OF_f_title
        #form.vars['f_photo_'+str(i)+':'+row.f_title]=row
        #LI(_title='couleurs (1).png', A('x', _href='javascript:void(0);',
_class='mw_delItem', _title='remove this file'),
I(B(EM(_class='mw_file-ext-png'))), SPAN('test1'))
        photos_files.append(XML(LI(A('x', _href='javascript:void(0);',
_class='mw_delItem', _title='remove this file'),
EM(_class='mw_file-ext-png'), SPAN(row.f_title), _title=row.f_photo)))
    response.js="""var photos_files_list = "{{=photos_files}}"
    $(document).ready( function () {
        if(photos_files_list != 'None') {
            $.each(photos_files_list, function(i, val) {
                $('ul.mw_list').append(photos_files_list[i]);
            });
        };
    });"""

#A(T('Access'),_href=URL(r=request,f='read',args=(request.args(0),str(id))))

        #<li title="couleurs (1).png"><a class="mw_delItem"
href="javascript:void(0);" title="remove this file">x</a><i><b><em
class="mw_file-ext-png"></em></b></i><span>test1</span></li>
    if form.accepts(request, session, onvalidation=lambda
form:check(form)): # Is it possible to use onvalidation with form.process()
syntax ?
        trip_id =
db.t_trip.update_record(**db.t_trip._filter_fields(form.vars))
        nfiles = 0
        for var in request.vars:
            if var.startswith('f_photo') and request.vars[var] != '':
                uploaded = request.vars[var]
                if isinstance(uploaded,list):
                    # files uploaded through input with "multiple"
attribute set on true
                    counter=0
                    for element in uploaded:
                        counter += 1
                        nfiles += 1
                        file_title = element.name.split(":")[-1] # TODO:
could this be made better?
                                                                 # I mean,
the title must be appended to element's name
                                                                 # or is
there another way?
                        db.t_photos.insert(
                            f_trip_ref=trip_id,
                            f_title=file_title+" ("+str(counter)+")" if
file_title!="" else file_title,

f_photo=db.t_photos.f_photo.store(element.file,element.filename))
                else:
                    # only one file uploaded
                    element = request.vars[var]
                    nfiles += 1
                    db.t_photos.insert(
                        f_trip_ref=trip_id,
                        f_title=element.name.split(":")[-1],

f_photo=db.t_photos.f_photo.store(element.file,element.filename))

        session.flash = T('%s photo%s uploaded'%(nfiles, 's' if nfiles>1
else ''))
        redirect(URL('trip_read'))

    if isinstance(form,FORM):
        # hide f_title form's row. Is there a better way to accomplish it?
        del form[0][3]

    return dict(form=form)

On Wed, May 30, 2012 at 6:23 PM, Paolo Caruccio
<[email protected]>wrote:

> Richard,
>
> I saw your email in the discussion regarding bootswatch, but I want to
> answer here for competence.
>
> Multiupload is a my old project. The object of the toy app was demonstrate
> the usage of multiupload control. It wasn't a complete application.
>
> Your intentions, however, are interesting. I will take a look at your code
> and I will try to find a solution.
>
>
> Il giorno mercoledì 30 maggio 2012 16:15:09 UTC+2, Richard ha scritto:
>
>> Hello Paolo,
>>
>> Pretty nice!
>>
>> Did you implement the update of the records also?
>>
>> Is it a straight and easy task or it becomes trickier to implement than
>> the rest of the app??
>>
>> Richard
>>
>> On Sat, Oct 29, 2011 at 6:21 PM, Paolo Caruccio <
>> [email protected]> wrote:
>>
>>> Bruno,
>>>
>>> thanks.
>>>
>>> What do you think about the upload mechanism? Can it be translate in a
>>> web2py widget? or is it better to use a different javascript/jquery library?
>>>
>>> Regards.
>>>
>>> Paolo
>>>
>>
>>

Reply via email to