def organisation():
 def prep(r):
  query = (FS('organisation_id:po_referral_organisation.id') != None)
  r.resource.add_filter(query)
  onaccept = s3db.get_config('org_organisation', 'onaccept')
  s3db.configure('org_organisation', onaccept=(onaccept, s3db.po_organisation_onaccept))
  if (r.record and (r.component_name == 'organisation_household')):
   atable = s3db.po_organisation_area
   query = ((atable.organisation_id == r.id) & (atable.deleted != True))
   rows = db(query).select(atable.area_id)
   if rows:
    area_ids = [row.area_id for row in rows]
    area_ids.append(None)
    table = r.component.table
    table.household_id.requires.set_filter(filterby='area_id', filter_opts=area_ids)
  elif (not r.component):
   list_fields = ['name', 'name', (T('Type'), 'organisation_organisation_type.organisation_type_id'), (T('Areas'), 'organisation_area.area_id'), 'website']
   s3db.configure('org_organisation', list_fields=list_fields)
  if r.interactive:
   s3.crud_strings['org_organisation'].update({'label_create': T('Create Agency'), 'title_list': T('Referral Agencies'), 'title_display': T('Agency Details'), 'title_update': T('Edit Agency Details'), 'label_delete_button': T('Delete Agency')})
   if (r.component_name == 'area'):
    s3.crud_strings['po_organisation_area'].update({'label_create': T('Add Area')})
  return True
 s3.prep = prep
 return s3_rest_controller('org', 'organisation', rheader=s3db.po_rheader)

def organisation ( ) : def prep ( r ) : query = ( FS ( 'organisation_id:po_referral_organisation.id' ) != None ) r . resource . add_filter ( query ) onaccept = s3db . get_config ( 'org_organisation' , 'onaccept' ) s3db . configure ( 'org_organisation' , onaccept = ( onaccept , s3db . po_organisation_onaccept ) ) if ( r . record and ( r . component_name == 'organisation_household' ) ) : atable = s3db . po_organisation_area query = ( ( atable . organisation_id == r . id ) & ( atable . deleted != True ) ) rows = db ( query ) . select ( atable . area_id ) if rows : area_ids = [ row . area_id for row in rows ] area_ids . append ( None ) table = r . component . table table . household_id . requires . set_filter ( filterby = 'area_id' , filter_opts = area_ids ) elif ( not r . component ) : list_fields = [ 'name' , 'name' , ( T ( 'Type' ) , 'organisation_organisation_type.organisation_type_id' ) , ( T ( 'Areas' ) , 'organisation_area.area_id' ) , 'website' ] s3db . configure ( 'org_organisation' , list_fields = list_fields ) if r . interactive : s3 . crud_strings [ 'org_organisation' ] . update ( { 'label_create' : T ( 'Create Agency' ) , 'title_list' : T ( 'Referral Agencies' ) , 'title_display' : T ( 'Agency Details' ) , 'title_update' : T ( 'Edit Agency Details' ) , 'label_delete_button' : T ( 'Delete Agency' ) } ) if ( r . component_name == 'area' ) : s3 . crud_strings [ 'po_organisation_area' ] . update ( { 'label_create' : T ( 'Add Area' ) } ) return True s3 . prep = prep return s3_rest_controller ( 'org' , 'organisation' , rheader = s3db . po_rheader )
restful crud controller .