I am having a hard time ordering a dropdown in a SQLFORM alphabetically.
In my model:
db.define_table('departments',
Field('name', notnull=True, unique=True),
Field('college_id','reference college', label='College'),
Field('department_rep_user_id','reference auth_user', label='Department
Representative'),
auth.signature,
format='%(name)s')
db.define_table('mentors',
Field('auth_user_id', 'reference auth_user', unique=True),
Field('department_id', 'reference departments', label='Department'),
auth.signature,
format=repr_mentor_table)
db.define_table('abstracts',
Field('title', notnull=True, unique=True),
Field('college_id', 'reference college', label='College'),
Field('department_id', 'reference departments', label='Abstract
Department'),
Field('mentor_id', 'reference mentors', label='Mentor'),
Field('classes_id', 'reference classes', label='Class', comment="If
your abstract is connected to a specific class (perhaps as a class
project), select your class. Otherwise, select 'Does not apply'"),
Field('session_id', 'reference sessions', label='Session'),
Field('presentation_format_id', 'reference presentation_formats',
label='Presentation Format'),
Field('body','text'),
Field('attatchment', 'upload'),
Field('location_id', 'reference locations', label='Location'),
Field('conference_id', 'reference conferences', label='Conference'),
Field('presentation_time', 'time', notnull=False, requires=IS_TIME(),
label='Presentation Time'),
Field('booth_space', label='Booth Space'),
Field('initial_approval', 'boolean', label='Initial Approval',
default=None),
Field('final_approval', 'boolean', label='Final Approval',
default=None),
Field('competing_status', 'boolean', label='Competing Status',
default=None),
auth.signature,
format='%(title)s',
singular="Abstract",
plural="Abstracts",
)
In the controller
def abstracts():
response.title = "Abstracts"
def get_primary_author(abstract_row):
author_row = db(
(db.abstract_author.primary_author==True) &
(db.abstract_author.abstract_id==abstract_row.id) &
(db.abstract_author.auth_user_id==db.auth_user.id)
).select(
db.auth_user.first_name,
db.auth_user.last_name).first()
return author_row.first_name + ' ' + author_row.last_name
def abstracts_body_represent(body, row):
sanitized = str(rcwc_sanitizer(body))
# This is really fragile. For some reason the grid isn't enforcing
# maxtextlength if the represent is called.
if len(request.args) == 1: # not on the grid page
sanitized = "{0}...".format(sanitized[:100])
return XML(sanitized) # If this returns a string it isn't used
db.abstracts.body.represent = abstracts_body_represent
grid = SQLFORM.smartgrid(
db.abstracts,
user_signature=False,
searchable=True,
linked_tables=['abstract_author'],
links=[
{"header": "Primary Author", "body":get_primary_author},
],
links_placement="left",
paginate=75,
)
return locals()
When I go to create a new abstract in the abstracts table the dropdown for
Mentors (mentor_id field) is not alphabetically ordered. Can this be
accomplished in the model or would I need to work it out in the controller?
--
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.