'Bookmark a Post
S3Method for interactive requests'

@staticmethod
def cms_add_bookmark(r, **attr):

    post_id = r.id
    user = current.auth.user
    user_id = (user and user.id)
    if ((not post_id) or (not user_id)):
        raise HTTP(405, current.ERROR.BAD_METHOD)
    db = current.db
    ltable = db.cms_post_user
    query = ((ltable.post_id == post_id) & (ltable.user_id == user_id))
    exists = db(query).select(ltable.id, ltable.deleted, ltable.deleted_fk, limitby=(0, 1)).first()
    if exists:
        link_id = exists.id
        if exists.deleted:
            if exists.deleted_fk:
                data = json.loads(exists.deleted_fk)
                data['deleted'] = False
            else:
                data = dict(deleted=False)
            db((ltable.id == link_id)).update(**data)
    else:
        link_id = ltable.insert(post_id=post_id, user_id=user_id)
    output = current.xml.json_message(True, 200, current.T('Bookmark    Added'))
    current.response.headers['Content-Type'] = 'application/json'
    return output
