[web2py] upload from Edit page

2012-12-18 Thread ArNew
Hi Everyone,

I need help urgently.

In my application, I am have included upload fields in Create and edit 
page. Through create page, it was very straight forward with:
{{=form.custom.widget.attachment}} (View)
Field('attachment','upload',uploadfolder=os.path.join(request.folder, 
'attachments')) (DAL). 
if form.vars.attachment:
form.vars.attachment_name = request.vars.attachment.filename
id = 
thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
 
.(Controller) And this works great.

That with Edit page is not the same, as it is not about editing the current 
image, but uploading more attachments. So I tried doing something like this:

 (view)
if request.vars.attachment != '':
form.vars.attachment = request.vars.attachment.file
filename = request.vars.attachment.filename
form.vars.attachment_name = filename
id = 
thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
This follows the very similar procedure of saving the encrypted version of 
attachment name in the attachment field, but it changes the extension to 
.txt for all the attachments. It saves the attachment as 
service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.txt 
where as the orginal attachment is photo.JPG. So ideall it should save it 
as  service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.JPG. 

Can anyone please help me with this?





-- 





[web2py] Re: upload from Edit page

2012-12-28 Thread ArNew
Hi Massimo,

I am using upload attachments. I have Create and Edit pages with number of 
fields. Upload is one of the fields. Now in create page, it was pretty 
straight forward using, Upload field in model. 

Table name is service_attachments
Field('attachment','upload',uploadfolder=os.path.join(request.folder, 
'attachments')) (Model)

if form.vars.attachment:
form.vars.attachment_name = request.vars.attachment.filename

>   id = 
> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>  
> .(Controller) 

And this works great.It inserts the record into the table and also saves 
the attachment into the folder as -  
service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.jpg
 
Now for edit functionality page, I want users to be able to add more 
images. Just calling the form.custom.widget.attachment again is not serving 
the purpose. So I tried doing, manual upload for this particular page. Eg, 

 (view)

I recreated this HTML statement with taking reference of what the Create 
upload field creates in HTML.. 

In Controller,

> if request.vars.attachment != '':
> form.vars.attachment = request.vars.attachment.file
> filename = request.vars.attachment.filename
> form.vars.attachment_name = filename
> id = 
> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>
Just Assigning this manual field to the already existing upload field. 

This saves the file, the same way as upload field does. It does save the 
file in the folder specified and also inserts the record in the 
service_attachments table.But, it saves the extension of that field as 
.txt, regardless of what the file type is. It saves the file as .txt in the 
folder and the db record.
Let me now if this is giving you the clear picture. 

Arti 


On Thursday, December 20, 2012 7:10:47 AM UTC-8, Massimo Di Pierro wrote:
>
> Can you explain what you are trying to accomplish and what your models 
> are? I do not understand from the code.
>
> On Tuesday, 18 December 2012 13:51:12 UTC-6, ArNew wrote:
>>
>> Hi Everyone,
>>
>> I need help urgently.
>>
>> In my application, I am have included upload fields in Create and edit 
>> page. Through create page, it was very straight forward with:
>> {{=form.custom.widget.attachment}} (View)
>> Field('attachment','upload',uploadfolder=os.path.join(request.folder, 
>> 'attachments')) (DAL). 
>> if form.vars.attachment:
>> form.vars.attachment_name = 
>> request.vars.attachment.filename
>> id = 
>> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>>  
>> .(Controller) And this works great.
>>
>> That with Edit page is not the same, as it is not about editing the 
>> current image, but uploading more attachments. So I tried doing something 
>> like this:
>>
>> > name="attachment" type="file" /> (view)
>> if request.vars.attachment != '':
>> form.vars.attachment = request.vars.attachment.file
>> filename = request.vars.attachment.filename
>> form.vars.attachment_name = filename
>> id = 
>> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>> This follows the very similar procedure of saving the encrypted version 
>> of attachment name in the attachment field, but it changes the extension to 
>> .txt for all the attachments. It saves the attachment as 
>> service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.txt 
>> where as the orginal attachment is photo.JPG. So ideall it should save it 
>> as  service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.JPG. 
>>
>> Can anyone please help me with this?
>>
>>
>>
>>
>>
>>

-- 





[web2py] Re: upload from Edit page

2013-01-04 Thread ArNew

Thanks for the link for multiple attachments. But I am not trying to 
implement multiple attachments here. Just single attachment from the edit 
page.
On Sunday, December 30, 2012 1:09:59 PM UTC-8, Alan Etkin wrote:
>
> I suspect you're trying to give a multi-file upload in-the-same-page 
> solution as Google and other brands do: AFAIK the standard upload widget 
> cannot handle multiple submissions in one form, but you could implement 
> your own widget with the help of this thread:
>
> https://groups.google.com/d/topic/web2py/XpnUb2_MaRc/discussion
>
>

--