Discussion:
[web2py] Auth_user dynamic cascading registration fields
Wabbajack
2015-07-28 20:31:44 UTC
Permalink
I have created a *factory,department,section and team* table in the
database
and a *factory* is on a *one to many* relationship with *department*
a *department* is on a *one to many* relationship with* section*
a *section* is on a *one to many* relationship with* team*

*Table names*
factory = portal_factory
department = portal_department
section = portal_section
team = portal_team

*db.py codes*
## *Factory*
db.define_table('portal_factory',
Field('name', notnull=True , required=True,unique=True)
)
## *Department*
db.define_table('portal_department',
Field('factory_id',db.portal_factory,notnull=True,required=True,requires=IS_IN_DB(db,db.portal_factory.id,'%(name)s')),
Field('name',notnull=True,required=True,unique=True)
)
## *Section*
db.define_table('portal_section',
Field('department_id',db.portal_department,notnull=True,required=True,requires=IS_IN_DB(db,db.portal_department.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## *Team*
db.define_table('portal_team',
Field('section_id',db.portal_section,notnull=True,required=True,requires=IS_IN_DB(db,db.portal_section.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)

## This is the tricky part
##i want to dynamically make an option list in the *t_department based on
the selected t_factory*
##i want to dynamically make an option list in the* t_section based on the
selected t_department*
##i want to dynamically make an option list in the* t_team based on the
selected t_section*

## Extra fields on auth_user for registration
auth.settings.extra_fields['auth_user']=[
Field('t_factory','reference portal_factory',label='Factory',notnull =
True,required = True,requires=IS_IN_DB(db,
db.portal_factory.id,'%(name)s')),
Field('t_department','reference
portal_department',label='Department',notnull = True,required =
True,requires=IS_IN_DB(db, db.portal_department.id,'%(name)s')),
Field('t_section','reference portal_section',label='Section',notnull =
True,required = True,requires=IS_IN_DB(db,
db.portal_section.id,'%(name)s')),
Field('t_team','reference portal_team',label='Team',notnull = True,required
= True,requires=IS_IN_DB(db, db.portal_team.id,'%(name)s')),
]

i have an attached file where this what i want to happen upon registration

Upon registration if i select *factory* *A *there are different *department
*selections in the dropdown (dropdown.png)
same as if i select *factory B *there are different *department *selections
in the dropdown (dropdown2.png)
this setup will just follow for *department *to *section *and *section *to
*team*

Thank you in advance for your help...More power to web2py
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Massimo Di Pierro
2015-07-30 04:32:45 UTC
Permalink
The problem is that what you want to do cannot be resolved server side. You
want the team dropdown to depend on the section, the section dropdown to
depend on the department, and the department dropdown to depend on the
factory.

There is no web2py syntax to do this because there is no way to get it done
without some client-side JS. In fact the way I would do it is create a JSON
object with all the dependencies, cache it, serve is static file, and use
it to populate the dropdown on change of the previous dropdown using JS.

Massimo
Post by Wabbajack
I have created a *factory,department,section and team* table in the
database
and a *factory* is on a *one to many* relationship with *department*
a *department* is on a *one to many* relationship with* section*
a *section* is on a *one to many* relationship with* team*
*Table names*
factory = portal_factory
department = portal_department
section = portal_section
team = portal_team
*db.py codes*
## *Factory*
db.define_table('portal_factory',
Field('name', notnull=True , required=True,unique=True)
)
## *Department*
db.define_table('portal_department',
Field('factory_id',db.portal_factory,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_factory.id,'%(name)s')),
Field('name',notnull=True,required=True,unique=True)
)
## *Section*
db.define_table('portal_section',
Field('department_id',db.portal_department,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_department.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## *Team*
db.define_table('portal_team',
Field('section_id',db.portal_section,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_section.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## This is the tricky part
##i want to dynamically make an option list in the *t_department based on
the selected t_factory*
##i want to dynamically make an option list in the* t_section based on
the selected t_department*
##i want to dynamically make an option list in the* t_team based on the
selected t_section*
## Extra fields on auth_user for registration
auth.settings.extra_fields['auth_user']=[
Field('t_factory','reference portal_factory',label='Factory',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_factory.id
,'%(name)s')),
Field('t_department','reference
portal_department',label='Department',notnull = True,required =
True,requires=IS_IN_DB(db, db.portal_department.id,'%(name)s')),
Field('t_section','reference portal_section',label='Section',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_section.id
,'%(name)s')),
Field('t_team','reference portal_team',label='Team',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_team.id,'%(name)s')),
]
i have an attached file where this what i want to happen upon registration
Upon registration if i select *factory* *A *there are different *department
*selections in the dropdown (dropdown.png)
same as if i select *factory B *there are different *department *selections
in the dropdown (dropdown2.png)
this setup will just follow for *department *to *section *and *section *to
*team*
Thank you in advance for your help...More power to web2py
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Derek
2015-07-31 06:30:56 UTC
Permalink
You will want to take a look at my example here:

http://www.web2pyslices.com/slice/show/1724/cascading-dropdowns-simplified

let me know if you have questions. You should be able to easily extend it
to do multi level cascading.
Post by Wabbajack
I have created a *factory,department,section and team* table in the
database
and a *factory* is on a *one to many* relationship with *department*
a *department* is on a *one to many* relationship with* section*
a *section* is on a *one to many* relationship with* team*
*Table names*
factory = portal_factory
department = portal_department
section = portal_section
team = portal_team
*db.py codes*
## *Factory*
db.define_table('portal_factory',
Field('name', notnull=True , required=True,unique=True)
)
## *Department*
db.define_table('portal_department',
Field('factory_id',db.portal_factory,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_factory.id,'%(name)s')),
Field('name',notnull=True,required=True,unique=True)
)
## *Section*
db.define_table('portal_section',
Field('department_id',db.portal_department,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_department.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## *Team*
db.define_table('portal_team',
Field('section_id',db.portal_section,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_section.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## This is the tricky part
##i want to dynamically make an option list in the *t_department based on
the selected t_factory*
##i want to dynamically make an option list in the* t_section based on
the selected t_department*
##i want to dynamically make an option list in the* t_team based on the
selected t_section*
## Extra fields on auth_user for registration
auth.settings.extra_fields['auth_user']=[
Field('t_factory','reference portal_factory',label='Factory',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_factory.id
,'%(name)s')),
Field('t_department','reference
portal_department',label='Department',notnull = True,required =
True,requires=IS_IN_DB(db, db.portal_department.id,'%(name)s')),
Field('t_section','reference portal_section',label='Section',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_section.id
,'%(name)s')),
Field('t_team','reference portal_team',label='Team',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_team.id,'%(name)s')),
]
i have an attached file where this what i want to happen upon registration
Upon registration if i select *factory* *A *there are different *department
*selections in the dropdown (dropdown.png)
same as if i select *factory B *there are different *department *selections
in the dropdown (dropdown2.png)
this setup will just follow for *department *to *section *and *section *to
*team*
Thank you in advance for your help...More power to web2py
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wabbajack
2015-07-31 15:13:45 UTC
Permalink
Hi Derek,

Ive tried and its working...
Thanks (see attached)

i will just have to create a separate user registration view and not use
the default 'user/register' to have this function in my auth_user
registration

Thanks...
Post by Derek
http://www.web2pyslices.com/slice/show/1724/cascading-dropdowns-simplified
let me know if you have questions. You should be able to easily extend it
to do multi level cascading.
Post by Wabbajack
I have created a *factory,department,section and team* table in the
database
and a *factory* is on a *one to many* relationship with *department*
a *department* is on a *one to many* relationship with* section*
a *section* is on a *one to many* relationship with* team*
*Table names*
factory = portal_factory
department = portal_department
section = portal_section
team = portal_team
*db.py codes*
## *Factory*
db.define_table('portal_factory',
Field('name', notnull=True , required=True,unique=True)
)
## *Department*
db.define_table('portal_department',
Field('factory_id',db.portal_factory,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_factory.id,'%(name)s')),
Field('name',notnull=True,required=True,unique=True)
)
## *Section*
db.define_table('portal_section',
Field('department_id',db.portal_department,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_department.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## *Team*
db.define_table('portal_team',
Field('section_id',db.portal_section,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_section.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## This is the tricky part
##i want to dynamically make an option list in the *t_department based
on the selected t_factory*
##i want to dynamically make an option list in the* t_section based on
the selected t_department*
##i want to dynamically make an option list in the* t_team based on the
selected t_section*
## Extra fields on auth_user for registration
auth.settings.extra_fields['auth_user']=[
Field('t_factory','reference portal_factory',label='Factory',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_factory.id
,'%(name)s')),
Field('t_department','reference
portal_department',label='Department',notnull = True,required =
True,requires=IS_IN_DB(db, db.portal_department.id,'%(name)s')),
Field('t_section','reference portal_section',label='Section',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_section.id
,'%(name)s')),
Field('t_team','reference portal_team',label='Team',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_team.id
,'%(name)s')),
]
i have an attached file where this what i want to happen upon registration
Upon registration if i select *factory* *A *there are different *department
*selections in the dropdown (dropdown.png)
same as if i select *factory B *there are different *department *selections
in the dropdown (dropdown2.png)
this setup will just follow for *department *to *section *and *section *to
*team*
Thank you in advance for your help...More power to web2py
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wabbajack
2015-07-31 13:27:31 UTC
Permalink
Hi Massimo
Post by Wabbajack
I have created a *factory,department,section and team* table in the
database
and a *factory* is on a *one to many* relationship with *department*
a *department* is on a *one to many* relationship with* section*
a *section* is on a *one to many* relationship with* team*
*Table names*
factory = portal_factory
department = portal_department
section = portal_section
team = portal_team
*db.py codes*
## *Factory*
db.define_table('portal_factory',
Field('name', notnull=True , required=True,unique=True)
)
## *Department*
db.define_table('portal_department',
Field('factory_id',db.portal_factory,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_factory.id,'%(name)s')),
Field('name',notnull=True,required=True,unique=True)
)
## *Section*
db.define_table('portal_section',
Field('department_id',db.portal_department,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_department.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## *Team*
db.define_table('portal_team',
Field('section_id',db.portal_section,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_section.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## This is the tricky part
##i want to dynamically make an option list in the *t_department based on
the selected t_factory*
##i want to dynamically make an option list in the* t_section based on
the selected t_department*
##i want to dynamically make an option list in the* t_team based on the
selected t_section*
## Extra fields on auth_user for registration
auth.settings.extra_fields['auth_user']=[
Field('t_factory','reference portal_factory',label='Factory',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_factory.id
,'%(name)s')),
Field('t_department','reference
portal_department',label='Department',notnull = True,required =
True,requires=IS_IN_DB(db, db.portal_department.id,'%(name)s')),
Field('t_section','reference portal_section',label='Section',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_section.id
,'%(name)s')),
Field('t_team','reference portal_team',label='Team',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_team.id,'%(name)s')),
]
i have an attached file where this what i want to happen upon registration
Upon registration if i select *factory* *A *there are different *department
*selections in the dropdown (dropdown.png)
same as if i select *factory B *there are different *department *selections
in the dropdown (dropdown2.png)
this setup will just follow for *department *to *section *and *section *to
*team*
Thank you in advance for your help...More power to web2py
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Massimo Di Pierro
2015-07-31 17:22:43 UTC
Permalink
You do not need another controller in my opinion. You can simply do:

def user():
if request.args(0)=='register':
response.files.append(URL('static','js/deal-with-fields.js'))
return dict(form=auth())

and then you put what you need in the deal-with-fields.js
Post by Wabbajack
Hi Massimo
Ive read your reply...thats what we have been working on today...
We tried using static dictionaries with sub groups...to a registration
form
with our factories , department, section and teams... :)
But if we do that i think we cannot use the 'user/register' page?
It is still possible if we can manipulate the 'user/register' page?
Right now we are making a new_registration controller and view...with
static dictionaries i will just post the code once its done...
Im sorry im just a 2 months old in python and a month old in web2py..and
a new comer in web development
Its just our boss really...
But the web2py community is very good....rapid development using web2py is
very impressing
ive never expect a reply actually...but also i have never expect it
coming from you...
Thank you very much..
Post by Wabbajack
I have created a *factory,department,section and team* table in the
database
and a *factory* is on a *one to many* relationship with *department*
a *department* is on a *one to many* relationship with* section*
a *section* is on a *one to many* relationship with* team*
*Table names*
factory = portal_factory
department = portal_department
section = portal_section
team = portal_team
*db.py codes*
## *Factory*
db.define_table('portal_factory',
Field('name', notnull=True , required=True,unique=True)
)
## *Department*
db.define_table('portal_department',
Field('factory_id',db.portal_factory,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_factory.id,'%(name)s')),
Field('name',notnull=True,required=True,unique=True)
)
## *Section*
db.define_table('portal_section',
Field('department_id',db.portal_department,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_department.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## *Team*
db.define_table('portal_team',
Field('section_id',db.portal_section,notnull=True,required=True,requires=IS_IN_DB(db,
db.portal_section.id,'%(name)s')),
Field('name', notnull=True, required=True, unique=True),
)
## This is the tricky part
##i want to dynamically make an option list in the *t_department based
on the selected t_factory*
##i want to dynamically make an option list in the* t_section based on
the selected t_department*
##i want to dynamically make an option list in the* t_team based on the
selected t_section*
## Extra fields on auth_user for registration
auth.settings.extra_fields['auth_user']=[
Field('t_factory','reference portal_factory',label='Factory',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_factory.id
,'%(name)s')),
Field('t_department','reference
portal_department',label='Department',notnull = True,required =
True,requires=IS_IN_DB(db, db.portal_department.id,'%(name)s')),
Field('t_section','reference portal_section',label='Section',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_section.id
,'%(name)s')),
Field('t_team','reference portal_team',label='Team',notnull =
True,required = True,requires=IS_IN_DB(db, db.portal_team.id
,'%(name)s')),
]
i have an attached file where this what i want to happen upon registration
Upon registration if i select *factory* *A *there are different *department
*selections in the dropdown (dropdown.png)
same as if i select *factory B *there are different *department *selections
in the dropdown (dropdown2.png)
this setup will just follow for *department *to *section *and *section *to
*team*
Thank you in advance for your help...More power to web2py
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...