'Render the card body
@param list_id: the HTML ID of the list
@param item_id: the HTML ID of the item
@param resource: the S3Resource to render
@param rfields: the S3ResourceFields to render
@param record: the record as dict'

def render_body(self, list_id, item_id, resource, rfields, record):

    db = current.db
    s3db = current.s3db
    has_permission = current.auth.s3_has_permission
    table = resource.table
    tablename = resource.tablename
    T = current.T
    pkey = str(resource._id)
    raw = record['_row']
    record_id = raw[pkey]
    contents = workflow = None
    if (tablename == 'deploy_alert'):
        subject = record['deploy_alert.subject']
        total_recipients = 0
        rows = self.recipient_numbers.get(record_id)
        if rows:
            hr_label = current.deployment_settings.get_deploy_hr_label()
            HR_LABEL = T(hr_label)
            if (hr_label == 'Member'):
                HRS_LABEL = T('Members')
            elif (hr_label == 'Staff'):
                HRS_LABEL = HR_LABEL
            elif (hr_label == 'Volunteer'):
                HRS_LABEL = T('Volunteers')
            htable = s3db.hrm_human_resource
            rcount = htable.id.count()
            if (not self.use_regions):
                total_recipients = rows[0][rcount]
                label = (HR_LABEL if (total_recipients == 1) else HRS_LABEL)
                link = URL(f='alert', args=[record_id, 'recipient'])
                recipients = SPAN(A(('%s    %s' % (total_recipients, label)), _href=link))
            else:
                region = s3db.org_organisation.region_id
                region_names = self.region_names
                UNKNOWN_OPT = current.messages.UNKNOWN_OPT
                recipients = []
                no_region = None
                for row in rows:
                    region_id = row[region]
                    region_name = region_names.get(region_id, UNKNOWN_OPT)
                    region_filter = {'recipient.human_resource_id$organisation_id$region_id__belongs': region_id}
                    num = row[rcount]
                    total_recipients += num
                    label = (HR_LABEL if (num == 1) else HRS_LABEL)
                    link = URL(f='alert', args=[record_id, 'recipient'], vars=region_filter)
                    recipient = SPAN(('%s    (' % region_name), A(('%s    %s' % (num, label)), _href=link), ')')
                    if region_id:
                        recipients.extend([recipient, ',    '])
                    else:
                        no_region = [recipient, ',    ']
                if no_region:
                    recipients.extend(no_region)
                recipients = TAG[''](recipients[:(-1)])
        else:
            recipients = T('No    Recipients    Selected')
        modified_on = record['deploy_alert.modified_on']
        sent = (True if raw['deploy_alert.message_id'] else False)
        if sent:
            status = SPAN(ICON('sent'), T('sent'), _class='alert-status')
        else:
            status = SPAN(ICON('unsent'), T('not    sent'), _class='red    alert-status')
        message = record['deploy_alert.body']
        contents = DIV(DIV(DIV(subject, _class='card-title'), DIV(recipients, _class='card-category'), _class='media-heading'), DIV(modified_on, status, _class='card-subtitle'), DIV(message, _class='message-body    s3-truncate'), _class='media-body')
        if ((not sent) and total_recipients and has_permission('update', table, record_id=record_id)):
            send = A(ICON('mail'), SPAN(T('Send    this    Alert'), _class='card-action'), _onclick=("window.location.href='%s'" % URL(c='deploy', f='alert', args=[record_id, 'send'])), _class='action-lnk')
            workflow = [send]
    elif (tablename == 'deploy_response'):
        human_resource_id = raw['hrm_human_resource.id']
        if human_resource_id:
            person_id = record['hrm_human_resource.person_id']
            profile_url = URL(f='human_resource', args=[human_resource_id, 'profile'])
            profile_title = T('Open    Member    Profile    (in    a    new    tab)')
            person = A(person_id, _href=profile_url, _target='_blank', _title=profile_title)
        else:
            person = ('%s    (%s)' % (T('Unknown'), record['msg_message.from_address']))
        organisation = record['hrm_human_resource.organisation_id']
        created_on = record['deploy_response.created_on']
        message = record['msg_message.body']
        documents = raw['doc_document.file']
        if documents:
            if (not isinstance(documents, list)):
                documents = [documents]
            bootstrap = (current.response.s3.formstyle == 'bootstrap')
            if bootstrap:
                docs = UL(_class='dropdown-menu', _role='menu')
            else:
                docs = SPAN(_id='attachments', _class='profile-data-value')
            retrieve = db.doc_document.file.retrieve
            for doc in documents:
                try:
                    doc_name = retrieve(doc)[0]
                except (IOError, TypeError):
                    doc_name = current.messages['NONE']
                doc_url = URL(c='default', f='download', args=[doc])
                if bootstrap:
                    doc_item = LI(A(ICON('file'), '    ', doc_name, _href=doc_url), _role='menuitem')
                else:
                    doc_item = A(ICON('file'), '    ', doc_name, _href=doc_url)
                docs.append(doc_item)
                docs.append(',    ')
            if bootstrap:
                docs = DIV(A(ICON('attachment'), SPAN(_class='caret'), _class='btn    dropdown-toggle', _href='#', data={'toggle': 'dropdown'}), doc_list, _class='btn-group    attachments    dropdown    pull-right')
            else:
                docs.components.pop()
                docs = DIV(LABEL(('%s:' % T('Attachments')), _class='profile-data-label', _for='attachments'), docs, _class='profile-data')
        else:
            docs = ''
        if hasattr(self, 'dcount'):
            dcount = self.dcount.get(human_resource_id, 0)
        if hasattr(self, 'avgrat'):
            avgrat = self.avgrat.get(human_resource_id)
        dcount_id = ('profile-data-dcount-%s' % record_id)
        avgrat_id = ('profile-data-avgrat-%s' % record_id)
        dinfo = DIV(LABEL(('%s:' % T('Previous    Deployments')), _for=dcount_id, _class='profile-data-label'), SPAN(dcount, _id=dcount_id, _class='profile-data-value'), LABEL(('%s:' % T('Average    Rating')), _for=avgrat_id, _class='profile-data-label'), SPAN(avgrat, _id=avgrat_id, _class='profile-data-value'), _class='profile-data')
        comments_id = ('profile-data-comments-%s' % record_id)
        comments = DIV(LABEL(('%s:' % T('Comments')), _for=comments_id, _class='profile-data-label'), SPAN(record['deploy_response.comments'], _id=comments_id, _class='profile-data-value    s3-truncate'), _class='profile-data')
        contents = DIV(DIV(DIV(person, _class='card-title'), DIV(organisation, _class='card-category'), _class='media-heading'), DIV(created_on, _class='card-subtitle'), DIV(message, _class='message-body    s3-truncate'), docs, dinfo, comments, _class='media-body')
        if human_resource_id:
            if (hasattr(self, 'deployed') and (human_resource_id in self.deployed)):
                deploy = A(ICON('deployed'), SPAN(T('Member    Deployed'), _class='card-action'), _class='action-lnk')
            elif has_permission('create', 'deploy_assignment'):
                mission_id = raw['deploy_response.mission_id']
                url = URL(f='mission', args=[mission_id, 'assignment', 'create'], vars={'member_id': human_resource_id})
                deploy = A(ICON('deploy'), SPAN(T('Deploy    this    Member'), _class='card-action'), _href=url, _class='action-lnk')
            else:
                deploy = None
            if deploy:
                workflow = [deploy]
    elif (tablename == 'deploy_assignment'):
        human_resource_id = raw['hrm_human_resource.id']
        profile_url = URL(f='human_resource', args=[human_resource_id, 'profile'])
        profile_title = T('Open    Member    Profile    (in    a    new    tab)')
        person = A(record['hrm_human_resource.person_id'], _href=profile_url, _target='_blank', _title=profile_title)
        organisation = record['hrm_human_resource.organisation_id']
        fields = dict(((rfield.colname, rfield) for rfield in rfields))
        render = (lambda colname: self.render_column(item_id, fields[colname], record))
        contents = DIV(DIV(DIV(person, _class='card-title'), DIV(organisation, _class='card-category'), _class='media-heading'), render('deploy_assignment.start_date'), render('deploy_assignment.end_date'), render('deploy_assignment.job_title_id'), render('deploy_assignment.job_title'), render('hrm_appraisal.rating'), _class='media-body')
        appraisal = self.appraisals.get(record_id)
        person_id = raw['hrm_human_resource.person_id']
        if (appraisal and has_permission('update', 'hrm_appraisal', record_id=appraisal.id)):
            EDIT_APPRAISAL = T('Open    Appraisal')
            url = URL(c='deploy', f='person', args=[person_id, 'appraisal', appraisal.id, 'update.popup'], vars={'refresh': list_id, 'record': record_id})
            edit = A(ICON('attachment'), SPAN(EDIT_APPRAISAL, _class='card-action'), _href=url, _class='s3_modal    action-lnk', _title=EDIT_APPRAISAL)
            workflow = [edit]
        elif has_permission('update', table, record_id=record_id):
            _class = 'action-lnk'
            UPLOAD_APPRAISAL = T('Upload    Appraisal')
            mission_id = raw['deploy_assignment.mission_id']
            url = URL(c='deploy', f='person', args=[person_id, 'appraisal', 'create.popup'], vars={'mission_id': mission_id, 'refresh': list_id, 'record': record_id})
            upload = A(ICON('upload'), SPAN(UPLOAD_APPRAISAL, _class='card-action'), _href=url, _class='s3_modal    action-lnk', _title=UPLOAD_APPRAISAL)
            workflow = [upload]
    body = DIV(_class='media')
    icon = self.render_icon(list_id, resource)
    if icon:
        body.append(icon)
    toolbox = self.render_toolbox(list_id, resource, record)
    if toolbox:
        if workflow:
            toolbox.insert(0, DIV(workflow, _class='card-actions'))
        body.append(toolbox)
    if contents:
        body.append(contents)
    return body
