'Handle HTML representation
@param r: the S3Request
@param attr: controller arguments'

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

    event_id = r.id
    incident_id = None
    T = current.T
    auth = current.auth
    db = current.db
    s3db = current.s3db
    etable = s3db.event_event
    itable = s3db.event_incident
    ptable = s3db.cms_post
    gtable = s3db.gis_location
    ertable = s3db.event_team
    eptable = s3db.event_post
    ttable = s3db.cms_tag
    ittable = s3db.event_tag
    date_represent = (lambda dt: S3DateTime.date_represent(dt, format='%b    %d    %Y    %H:%M', utc=True))
    _map = self._map('Incidents', filter=('~.event_id=%s' % event_id))
    output = {'map': _map}
    updateable = auth.s3_has_permission('update', etable, record_id=event_id, c='event', f='event')
    output['updateable'] = updateable
    user = auth.user
    if user:
        user_id = user.id
        ltable = s3db.event_bookmark
        query = ((ltable.event_id == event_id) & (ltable.user_id == user_id))
        exists = db(query).select(ltable.id, limitby=(0, 1)).first()
        if exists:
            bookmark = A(ICON('bookmark'), _title=T('Remove    Bookmark'), _class='button    radius    small    bookmark')
        else:
            bookmark = A(ICON('bookmark-empty'), _title=T('Add    Bookmark'), _class='button    radius    small    bookmark')
        bookmark['_data-c'] = 'event'
        bookmark['_data-f'] = 'event'
        bookmark['_data-i'] = event_id
    else:
        bookmark = ''
    output['bookmark_btn'] = bookmark
    event = Storage()
    record = r.record
    event.name = record.name
    event.desc = record.comments
    event.start_date = date_represent(record.start_date)
    end_date = record.end_date
    if end_date:
        event.active = False
        event.end_date = date_represent(end_date)
    else:
        event.active = True
        event.end_date = 'n/a'
    eltable = s3db.event_event_location
    query = ((eltable.event_id == event_id) & (eltable.deleted == False))
    event_location = db(query).select(eltable.location_id, limitby=(0, 1)).first()
    if event_location:
        event.location = eltable.location_id.represent(event_location.location_id)
    else:
        event.location = ''
    query = ((itable.event_id == event_id) & (itable.deleted == False))
    incidents = db(query).count()
    event.incidents = A(('%s    %s' % (incidents, T('Incidents'))), _href=URL(c='event', f='event', args='incident.popup', vars={'view': 1}), _class='s3_modal', _title=T('Incidents'))
    query = ((ertable.event_id == event_id) & (ertable.deleted == False))
    resources = db(query).count()
    event.resources = A(('%s    %s' % (resources, T('Resources'))), _href=URL(c='event', f='event', args='group.popup', vars={'view': 1}), _class='s3_modal', _title=T('Resources'))
    query = ((eptable.event_id == event_id) & (eptable.deleted == False))
    updates = db(query).count()
    event.updates = A(('%s    %s' % (updates, T('Updates'))), _href=URL(c='event', f='event', args='post.popup', vars={'view': 1}), _class='s3_modal', _title=T('Updates'))
    if record.exercise:
        event.status = T('Testing')
    elif (not record.end_date):
        event.status = T('Open')
    else:
        event.status = T('Closed')
    output['event'] = event
    datatable = self._datatable
    dt_init = ["$('.dataTables_filter    label,.dataTables_length,.dataTables_info').hide();"]
    tablename = 'event_incident'
    customise = current.deployment_settings.customise_resource(tablename)
    if customise:
        customise(r, tablename)
    datatable(output=output, tablename=tablename, updateable=updateable, event_id=event_id, dt_init=dt_init)
    tablename = 'event_team'
    customise = current.deployment_settings.customise_resource(tablename)
    if customise:
        customise(r, tablename)
    datatable(output=output, tablename=tablename, updateable=updateable, event_id=event_id, dt_init=dt_init)
    tablename = 'project_task'
    customise = current.deployment_settings.customise_resource(tablename)
    if customise:
        customise(r, tablename)
    datatable(output=output, tablename=tablename, updateable=updateable, event_id=event_id, dt_init=dt_init)
    tablename = 'event_human_resource'
    customise = current.deployment_settings.customise_resource(tablename)
    if customise:
        customise(r, tablename)
    datatable(output=output, tablename=tablename, updateable=updateable, event_id=event_id, dt_init=dt_init)
    tablename = 'event_organisation'
    customise = current.deployment_settings.customise_resource(tablename)
    if customise:
        customise(r, tablename)
    datatable(output=output, tablename=tablename, updateable=updateable, event_id=event_id, dt_init=dt_init)
    self._updates_html(r, output, event_id, incident_id, updateable, **attr)
    self._view(output, 'event_profile.html')
    return output
