def case():
 def prep(r):
  if (r.method == 'update'):
   person_id = r.table.person_id
   person_id.writable = False
   person_id.comment = None
  else:
   dtable = s3db.disease_disease
   diseases = db((dtable.deleted == False)).select(dtable.id, limitby=(0, 2))
   if (len(diseases) == 1):
    field = r.table.disease_id
    field.default = diseases.first().id
    field.writable = False
  if ((r.component_name == 'contact') or (r.component_name == 'exposure')):
   field = r.component.table.tracing_id
   field.readable = field.writable = False
  if r.interactive:
   field = r.table.person_id
   field.requires = IS_ADD_PERSON_WIDGET2()
   field.widget = S3AddPersonWidget2(controller='pr')
  return True
 s3.prep = prep
 def postp(r, output):
  if (isinstance(output, dict) and ('buttons' in output)):
   buttons = output['buttons']
   if (('list_btn' in buttons) and ('summary_btn' in buttons)):
    buttons['list_btn'] = buttons['summary_btn']
  return output
 s3.postp = postp
 return s3_rest_controller(rheader=s3db.disease_rheader)

def case ( ) : def prep ( r ) : if ( r . method == 'update' ) : person_id = r . table . person_id person_id . writable = False person_id . comment = None else : dtable = s3db . disease_disease diseases = db ( ( dtable . deleted == False ) ) . select ( dtable . id , limitby = ( 0 , 2 ) ) if ( len ( diseases ) == 1 ) : field = r . table . disease_id field . default = diseases . first ( ) . id field . writable = False if ( ( r . component_name == 'contact' ) or ( r . component_name == 'exposure' ) ) : field = r . component . table . tracing_id field . readable = field . writable = False if r . interactive : field = r . table . person_id field . requires = IS_ADD_PERSON_WIDGET2 ( ) field . widget = S3AddPersonWidget2 ( controller = 'pr' ) return True s3 . prep = prep def postp ( r , output ) : if ( isinstance ( output , dict ) and ( 'buttons' in output ) ) : buttons = output [ 'buttons' ] if ( ( 'list_btn' in buttons ) and ( 'summary_btn' in buttons ) ) : buttons [ 'list_btn' ] = buttons [ 'summary_btn' ] return output s3 . postp = postp return s3_rest_controller ( rheader = s3db . disease_rheader )
cases: restful crud controller .