I've caused some confusion with my typos. Here's the code.

model
db.define_table('sessions',
                Field('program_name', 'string', requires=IS_IN_DB(db, 
db.programs.program_name)),
                Field('session_type', 'string', 
requires=IS_IN_SET(['practice', 'evaluation'], zero=None)),
                Field('session_number', 'integer', default=1), # this is 
the session number by program, using 0 for evaluations
                Field('coach', 'string'),
                Field('assistant', 'string'),
                Field('session_date_time', 'datetime'),
                Field('session_name', compute = lambda row: 
row.program_name + ', ' + row.session_type + ' ' + str(row.session_number))
               )

db.sessions.session_name.represent = lambda session_name, row: 
A(row.session_name, _href=URL('demo', 'tests_for_this_eval', args=1))
#  works, but is hard coded, therefore is not useful in this case
#db.sessions.session_name.represent = lambda session_name, row: 
A(row.session_name, _href=URL('demo', 'tests_for_this_eval', 
args=sessions.id))
#  global name 'sessions' is not defined
#db.sessions.session_name.represent = lambda session_name, row: 
A(row.session_name, _href=URL('demo', 'tests_for_this_eval', 
args=db.sessions.id))
#  does not pass sessions.id as arg
#db.sessions.session_name.represent = lambda session_name, row: 
A(row.session_name, _href=URL('demo', 'tests_for_this_eval', args=row.id))
#  'Row' object has no attribute 'id'
#db.sessions.session_name.represent = lambda session_name, row: 
A(row.session_name, _href=URL('demo', 'tests_for_this_eval', 
args=row.sessions.id))
#  'Row' object has no attribute 'sessions'

query_sessions = (
  (db.auth_user.id == db.auth_membership.user_id) &
  (db.auth_membership.group_id == db.auth_group.id) &
  (db.auth_group.role.like('coach'))
)

db.sessions.coach.requires = IS_IN_DB(db(query_sessions), db.auth_user.id, 
 '%(first_name)s %(last_name)s')
db.sessions.assistant.requires = IS_IN_DB(db(query_sessions), 
db.auth_user.id,  '%(first_name)s %(last_name)s')


controller
@auth.requires_membership('coach')
def show_list_of_sessions():
  # get list of evaluations
  evaluations = 
SQLTABLE(db(db.sessions.session_type=='evaluation').select(db.sessions.id, 
db.sessions.session_name),
                         headers=None, truncate=128
                        )

  return dict(evaluations=evaluations)

view
{{extend 'layout.html'}}

<h3>evaluations</h3>
{{=evaluations}}



-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to