Model:
db = DAL('sqlite://webform.sqlite')
db.define_table('excelform',
    Field('last_name', 'string'),
    Field('first_name', 'string'),
    Field('age', 'string'),
    Field('location', 'string')
)


That is one of my models, I have another that contains: 


auth.settings.extra_fields['auth_user']= [
    Field('nickname', 'string'),
    Field('image', 'upload')
]

But I have not done anything with that yet in regards to the web form.

Controller(the sections that apply to my question):

def user():
    return dict(form=auth())


def excelform():
    update = db.excelform(request.args(0))
    form = SQLFORM(db.excelform, update)
    if form.accepts(request,session):
        response.flash = 'Thanks! The form has been submitted.'
        session.vars=form.vars
        redirect(URL('about'))
    elif form.errors:
       response.flash = 'Please correct the error(s).'
    else:
       response.flash = 'Try again - no fields can be empty.'
    return dict(form=form)

def about():
    import sys
    form = SQLFORM(db.excelform)
    from openpyxl import load_workbook
    wb = 
load_workbook(filename='/home/../Documents/web2py/applications/../static/excel.xlsx')
    sheet_ranges = wb['Sheet1']
    sheet_ranges['C4'] = session.vars.last_name
    sheet_ranges['C6'] = session.vars.first_name
    sheet_ranges['C8'] = session.vars.age
    sheet_ranges['C10'] = session.vars.location
    
wb.save(filename='/home/../Documents/web2py/applications/../static/excel2.xlsx')
    message = session.vars.last_name , " ", session.vars.first_name + " "
    return dict()


def aboutlist():
    grid = SQLFORM.grid(db.excelform,user_signature=False)
    return locals()




I'm just trying to have a working model before I add error checking and 
more options into it.
>From the web2py book, there is this section that I believe applies to what 
I want to do:

*"Uploading files in database*

*By default, all uploaded files handled by SQLFORMs are safely renamed and 
stored in the filesystem under the "uploads" folder. It is possible to 
instruct web2py to store uploaded files in the database instead.*

*Now, consider the following table:*

*db.define_table('dog',
    Field('name')
    Field('image', 'upload'))*

*where dog.image is of type upload. To make the uploaded image go in the 
same record as the name of the dog, you must modify the table definition by 
adding a blob field and link it to the upload field:*

*db.define_table('dog',
    Field('name')
    Field('image', 'upload', uploadfield='image_data'),
    Field('image_data', 'blob'))*

*Here "image_data" is just an arbitrary name for the new blob field.*

*Line 3 instructs web2py to safely rename uploaded images as usual, store 
the new name in the image field, and store the data in the uploadfield 
called "image_data" instead of storing the data on the filesystem. All of 
this is be done automatically by SQLFORMs and no other code needs to be 
changed.*

*With this tweak, the "uploads" folder is no longer needed."*

However I am confused by it, maybe because the example being used is an 
image file. I also am confused because this makes me think I need two 
separate databases instead of one where I can just link the session to the 
user that is logged in.. Maybe I am understanding it wrong.





On Tuesday, November 24, 2015 at 11:18:51 AM UTC-5, Richard wrote:
>
> Sure all this can be done. What have you done so far? Can you show us some 
> piece of code?
>
> Richard
>
> On Tue, Nov 24, 2015 at 11:15 AM, <[email protected] <javascript:>> 
> wrote:
>
>> Hello, 
>> I am very new to web2py. I was hoping for some insight as to whether what 
>> I am trying to do is possible, and maybe if I can be redirected as to what 
>> I should read up on to help me figure this out. Any advice or insight will 
>> help.
>>
>> I have web forms, which are linked to an excel file template. Once a web 
>> form is filled out and submitted, it is saved into the same folder that the 
>> excel template file is located in, under a new name where the original 
>> excel file template is untouched. 
>>
>> I want to make it so that, a user registers an account and when they fill 
>> out the webform it saves to that specific user in the database. If they 
>> fill out the same webform again, it saves without erasing their previous 
>> forms.
>>
>> I am very certain that this is possible to do within web2py. I think to 
>> accomplish this, I need to use SQLForm. Will I need two seperate databases 
>> to accomplish this? One database that registers users, and another database 
>> that has an upload field defined that links to the other database?
>>
>> Thank you.
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to