I want to provide import/export CSV file from a specific table for
users. All I want is just like appadmin works. I'm referencing
appadmin code trying to write the code below but I get error
messages.  Does anyone can point out what's the problem ?

Example for auth_user table.

Model
---------------------
dba = DAL('sqlite://storage.sqlite')
auth = Auth(dba, hmac_key=Auth.get_or_create_key())

Controller
--------------------------------------
def import_csv(table, file):
    table.import_from_csv_file(file)

def index():
    if request.vars.csvfile != None:
        import_csv(db[request.vars.table],request.vars.csvfile.file)
        response.flash = T('data uploaded')
    return dict()

View - default/index
--------------------------------
{{left_sidebar_enabled=right_sidebar_enabled=False}}
{{extend 'layout.html'}}

{{=FORM(str(T('or import from csv file'))+"
",INPUT(_type='file',_name='csvfile'),INPUT(_type='hidden',_value='dba.auth_user',_name='table'),INPUT(_type='submit',_value='import'))}}

Traceback
-------------------------------
Traceback (most recent call last):
  File "C:\web2py\gluon\restricted.py", line 204, in restricted
    exec ccode in environment
  File "C:/web2py/applications/Inventory_Reserve_Admin/controllers/
default.py", line 73, in <module>
  File "C:\web2py\gluon\globals.py", line 172, in <lambda>
    self._caller = lambda f: f()
  File "C:/web2py/applications/Inventory_Reserve_Admin/controllers/
default.py", line 69, in index
    import_csv(db[request.vars.table],request.vars.csvfile.file)
  File "C:\web2py\gluon\dal.py", line 5113, in __getitem__
    return dict.__getitem__(self, str(key))
KeyError: 'dba.auth_user'


Reply via email to