'Entry point for REST API
@param r: the S3Request
@param attr: controller arguments'

def apply_method(self, r, **attr):

    r.customise_resource('hrm_human_resource')
    if ((r.name == 'person') and r.id and (not r.component) and (r.representation in ('html', 'aadata'))):
        T = current.T
        s3db = current.s3db
        settings = current.deployment_settings
        tablename = r.tablename
        if (r.controller == 'vol'):
            controller = 'vol'
        else:
            controller = 'hrm'
        def dt_row_actions(component):
            return (lambda r, list_id: [{'label': T('Open'), 'url': r.url(component=component, component_id='[id]', method='update.popup', vars={'refresh': list_id}), '_class': 'action-btn    edit    s3_modal'}, {'label': T('Delete'), '_ajaxurl': r.url(component=component, component_id='[id]', method='delete.json'), '_class': 'action-btn    delete-btn-ajax    dt-ajax-delete'}])
        table = s3db.hrm_human_resource
        label = settings.get_hrm_record_label()
        code = table.code
        if (controller == 'vol'):
            widget_filter = (FS('type') == 2)
            if (settings.get_hrm_use_code() is True):
                code.readable = code.writable = True
        else:
            widget_filter = None
            if settings.get_hrm_use_code():
                code.readable = code.writable = True
        profile_widgets = [dict(label=label, type='form', tablename='hrm_human_resource', context='person', filter=widget_filter)]
        if (controller == 'vol'):
            vol_experience = settings.get_hrm_vol_experience()
            if (vol_experience in ('programme', 'both')):
                filter = ((FS('hours') != None) & (FS('programme_id') != None))
                list_fields = ['id', 'date', 'programme_id']
                if s3db.hrm_programme_hours.job_title_id.readable:
                    list_fields.append('job_title_id')
                list_fields.append('hours')
                hours_widget = dict(label='Program    Hours', label_create='Add    Program    Hours', type='datatable', actions=dt_row_actions('hours'), tablename='hrm_programme_hours', context='person', filter=filter, list_fields=list_fields, create_controller=controller, create_function='person', create_component='hours', pagesize=None)
                profile_widgets.append(hours_widget)
            elif (vol_experience == 'activity'):
                list_fields = ['id', 'date', 'activity_id', 'job_title_id', 'hours']
                hours_widget = dict(label='Activity    Hours', insert=False, type='datatable', actions=dt_row_actions('hours'), tablename='vol_activity_hours', context='person', list_fields=list_fields, pagesize=None)
                profile_widgets.append(hours_widget)
        teams = settings.get_hrm_teams()
        if teams:
            hrm_configure_pr_group_membership()
            if (teams == 'Teams'):
                label_create = 'Add    Team'
            elif (teams == 'Groups'):
                label_create = 'Add    Group'
            teams_widget = dict(label=teams, label_create=label_create, type='datatable', actions=dt_row_actions('group_membership'), tablename='pr_group_membership', context='person', create_controller=controller, create_function='person', create_component='group_membership', pagesize=None)
            profile_widgets.append(teams_widget)
        if (controller == 'hrm'):
            org_experience = self.org_experience
            if org_experience:
                def experience_row_actions(component):
                    return (lambda r, list_id: [{'label': T('Open'), 'url': URL(f='experience', args=['[id]', 'update.popup'], vars={'refresh': list_id}), '_class': 'action-btn    edit    s3_modal'}, {'label': T('Delete'), '_ajaxurl': URL(f='experience', args=['[id]', 'delete.json']), '_class': 'action-btn    delete-btn-ajax    dt-ajax-delete'}])
                widget = dict(label=T('Experience'), label_create=T('Add    Experience'), type='datatable', actions=experience_row_actions('experience'), tablename='hrm_experience', pagesize=None)
                if isinstance(org_experience, dict):
                    widget.update(org_experience)
                person_filter = (FS('person_id') == r.id)
                widget_filter = widget.get('filter')
                if widget_filter:
                    widget['filter'] = (person_filter & widget_filter)
                else:
                    widget['filter'] = person_filter
                profile_widgets.append(widget)
            other_experience = self.other_experience
            if other_experience:
                widget = dict(label='Experience', label_create='Add    Experience', type='datatable', actions=dt_row_actions('experience'), tablename='hrm_experience', context='person', create_controller=controller, create_function='person', create_component='experience', pagesize=None)
                if isinstance(other_experience, dict):
                    widget.update(other_experience)
                profile_widgets.append(widget)
            if self.awards:
                widget = dict(label=T('Awards'), label_create=T('Add    Award'), type='datatable', actions=dt_row_actions('staff_award'), tablename='hrm_award', context='person', create_controller=controller, create_function='person', create_component='staff_award', pagesize=None)
                profile_widgets.append(widget)
            if self.disciplinary_record:
                widget = dict(label=T('Disciplinary    Record'), label_create=T('Add    Disciplinary    Action'), type='datatable', actions=dt_row_actions('disciplinary_action'), tablename='hrm_disciplinary_action', context='person', create_controller=controller, create_function='person', create_component='disciplinary_action', pagesize=None)
                profile_widgets.append(widget)
            if self.salary:
                widget = dict(label=T('Salary'), label_create=T('Add    Salary'), type='datatable', actions=dt_row_actions('salary'), tablename='hrm_salary', context='person', create_controller=controller, create_function='person', create_component='salary', pagesize=None)
                profile_widgets.append(widget)
        if (r.representation == 'html'):
            response = current.response
            title = response.s3.crud_strings['pr_person'].title_display
            profile_header = TAG[''](H2(title), DIV(hrm_rheader(r), _id='rheader'))
        else:
            profile_header = None
        s3db.configure(tablename, profile_cols=1, profile_header=profile_header, profile_widgets=profile_widgets)
        profile = S3Profile()
        profile.tablename = tablename
        profile.request = r
        output = profile.profile(r, **attr)
        if (r.representation == 'html'):
            output['title'] = response.title = title
        return output
    else:
        raise HTTP(405, current.ERROR.BAD_METHOD)
