'Create the HTML for the Alerts section'

@staticmethod
def _alerts_html():

    T = current.T
    db = current.db
    s3db = current.s3db
    tablename = 'cms_post'
    resource = s3db.resource(tablename)
    resource.add_filter((FS('~.series_id$name') == 'Public    Alert'))
    list_fields = ['id', 'status_id', 'date', 'title', 'body', 'created_by', 'location_id$path', 'location_id$L3', 'location_id$lat', 'location_id$lon']
    rows = resource.select(fields=list_fields, start=None, limit=4, orderby='date    desc', represent=True, raw_data=True).rows
    if (len(rows) == 0):
        alerts = ''
    else:
        alerts = DIV(H3('Alerts    ', TAG['small'](A(T('See    all    alerts'), _href=URL(c='cms', f='post', args='summary'))), _class='well-title'), _class='row    well    blue')
        gttable = s3db.gis_location_tag
        auth = current.auth
        if auth.is_logged_in():
            logged_in = True
            user_id = auth.user.id
            btable = s3db.cms_post_user
            bquery = (btable.post_id.belongs([row['cms_post.id'] for row in rows]) & (btable.deleted == False))
            bookmarks = db(bquery).select(btable.post_id)
            bookmarks = [b.post_id for b in bookmarks]
        else:
            logged_in = False
        for row in rows:
            record_id = row['cms_post.id']
            status = row['cms_post.status_id']
            post_dt = row._row['cms_post.date']
            post_date = post_dt.date().strftime('%b    %d,    %Y')
            post_time = post_dt.time().strftime('%H:%M')
            if logged_in:
                if (record_id in bookmarks):
                    bookmark = LI(ICON('bookmark'), _title=T('Remove    Bookmark'), _class='item    bookmark')
                else:
                    bookmark = LI(ICON('bookmark-empty'), _title=T('Add    Bookmark'), _class='item    bookmark')
                bookmark['_data-c'] = 'cms'
                bookmark['_data-f'] = 'post'
                bookmark['_data-i'] = record_id
            else:
                bookmark = ''
            path = row._row['gis_location.path']
            if (path and ('/' in path)):
                L1 = path.split('/')[1]
                query = ((gttable.location_id == L1) & (gttable.tag == 'state'))
                L1_abrv = db(query).select(gttable.value, limitby=(0, 1)).first().value
                L3 = row['gis_location.L3']
                lat = row['gis_location.lat']
                lon = row['gis_location.lon']
            else:
                L1_abrv = ''
                L3 = ''
                lat = ''
                lon = ''
            alerts.append(DIV(TAG['aside'](TAG['header'](UL(LI(_class='item    icon'), LI(status, _class='item    secondary    status'), _class='status-bar-left'), UL(bookmark, _class='controls'), _class=('status-bar    %s' % status)), DIV(H1(row['cms_post.title'], _class='title'), P(SPAN(('%s    @    %s    by    %s' % (post_date, post_time, row['cms_post.created_by'])), _class='meta'), BR(), SPAN(('%s,    %s;    %s,    %s' % (L3, L1_abrv, lat, lon)), _class='meta-location')), DIV(row['cms_post.body'], _class='desc'), _class='body'), TAG['footer'](P(A(T('Read    More'), _href=URL(c='cms', f='post', args=[record_id, 'profile']), _class='more')), _class='footer'), _class='card-alert'), _class='medium-6    large-3    columns'))
        while (len(alerts) < 4):
            alerts.append(DIV(_class='medium-6    large-3    columns'))
    return alerts
