I have three tables:

- invoices
- invoice summaries
- invoice bundles

The website I am working on provides such a functionality, that user 
uploads a file, from which invoices and invoice summaries are generated and 
after being generated they are zipped and put into a bundle.

For each upload I create following structure for storing these files:

invoices/
     /<bundle_id>/<list of invoices of bundle <bundle_id>>/
summaries/
     /<bundle_id>/<list of invoices of bundle <bundle_id>>/
bundles/
     /<bundle_id>/<list of invoices of bundle <bundle_id>>/



So I end up having something that looks like this

invoices/
     /1/<list of invoices of bundle_1>/
            /invoice1.pdf
            /invoice2.pdf
     /2/<list of invoices of bundle_2>/
            /invoice1.pdf
            /invoice2.pdf
     /3/<list of invoices of bundle_3>/
            /invoice1.pdf
            /invoice2.pdf
summaries/
     /1/<list of summaries of bundle_1>/
            /summary1.pdf
     /2/<list of summaries of bundle_2>/
            /summary1.pdf
     /3/<list of summaries of bundle_3>/
            /summary1.pdf
bundles/
     /1/<bundle_1>/
            /bundle.zip
     /2/<bundle_2>/
            /bundle.zip
     /3/<bundle_3>/
            /bundle.zip




where inner folder name is ID of recently created bundle.

Now to provide CRUD functionality I am using SMART GRID and I want to be 
able to display the file of invoice, summary, bundle entries ( by 
displaying I mean I want to display file's name and allow downloading it ), 
when a user either chooses VIEW in the SMART GRID or when he looks at the 
list of entries. Since I've chosen my own folder structure for storing 
these invoices, summaries and bundles I can't do it in a simple way, 
because Web2py uses its own mechanism to store and retrieve files and 
changse file's name. So in each of these tables I store the following 
fields:
Field('f_invoice_file_path', type='string')
Field('f_invoice_file', 'upload')



what I wanted to do is something like this:

def on_before_insert_invoice(fields, id):
    db(db.t_invoice.id == id).update(
        f_invoice_file=fields['f_invoice_file_path']
    )
db.t_invoice._before_insert.append(
    on_before_insert_invoice
)

, here actually *fields* contains a list of tuples in following format 
(field, value) so I had to iterate over it to find fields[
'f_invoice_file_path'], I just omitted this part for brevity.

, but I get following error and most likely it is not the proper way to do 
that:

*** RuntimeError: Unable to handle upload

Note that the field:

Field('f_invoice_file_path', type='string')

is saved correctly, I just need somehow to make upload field point to that 
location. The next weird thing is that variable *fields* doesn't contain 
field Field('f_invoice_file', 'upload')
, even though I added it to the model, settings.migrate is set to True, and 
server has been restarted.

How can I do it?







-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to