Hi i am working to build a multi-tenant application which has a company
table which stores logo and other data. I defined a company table, added
extra fields in auth_user and created an action (simplified version) like
below. web2py uploaded the logo image file under
myapp/uploads/company.logo/af/company.logo.afxxxxxxxx.png, but according to
the document(applications/test/uploads/person.image.XXXXX.jpg), I should
not have had the company.log/af directories, could anyone explain why?
So when I created my invoice with an upload field called attachment, I only
used SQLFORM(db.invoice).process(), web2py put the attachment file under
myapp/uploads, there is no extra invoice.attachment/xx directories created,
and this matches what the documentation says. could anyone advise why they
have different folder structure?
Now if I want to add the company_id as part of the directory structure eg.
myapp/uploads/company_id/company.logo.XXXXX.jpg, how should i define the
table FIELD(... uploadfolder=???, ...)
Many thanks in advance!
############
db.define_table('company',
Field('company_name', requires=IS_NOT_EMPTY(),
unique=True),
Field('phone'),
Field('company_email', requires=IS_NOT_EMPTY()),
Field('website'),
Field('logo', 'upload', label='Company Logo',
uploadfolder=os.path.join(request.folder,'uploads'), uploadseparate=True),
# 23x23mm, 300K recommended
Field('status', requires=IS_IN_SET(COMPANY_STATUS),
default='Active', readable=False, writable=False),
format='%(company_name)s')
auth.settings.extra_fields['auth_user']= [
Field('mobile', requires=IS_NOT_EMPTY()),
Field('company_id', 'integer', writable=False),
]
def initialization():
db.auth_user.company_id.readable= False
init_form = SQLFORM.factory(db.company, db.auth_user,
formstyle='table3cols', table_name='company')
if init_form.process().accepted:
company_id =
db.company.insert(**db.company._filter_fields(init_form.vars))
user_id =
db.auth_user.insert(**db.auth_user._filter_fields(init_form.vars))
user_row = db.auth_user(user_id)
user_row.update_record(company_id=company_id)
session.flash='You have created your company profile, admin user.'
redirect(URL('index'))
elif init_form.errors:
response.flash='Error in initialization(), please make sure your
company has not been registered before or the data you entered meet the
form validation.'
else:
pass
return locals()
--
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.