def api_delete_pageview(page_id):
    check_admin()
    pageview = Pageviews.get(page_id)
    if pageview is None:
        raise APIResourceNotFoundError('Pageview')
    pageview.delete()
    return dict(id=page_id)
def pageviews(page_id):
    pageview = Pageviews.get(page_id)
    if pageview is None:
        raise notfound()
    pageview.html_content = markdown2.markdown(pageview.page_value)
    #comments = Comment.find_by('where blog_id=? order by created_at desc limit 1000', blog_id)
    return dict(pageview=pageview, user=ctx.request.user)
def api_create_pageview():
    check_admin()
    i = ctx.request.input(page_name='', element='', byway='', page_value='')
    page_name = i.page_name.strip()
    element = i.element.strip()
    byway = i.byway.strip()
    page_value = i.page_value.strip()
    if not page_name:
        raise APIValueError('page_name', 'name cannot be empty.')
    if not element:
        raise APIValueError('element', 'summary cannot be empty.')
    if not byway:
        raise APIValueError('byway', 'content cannot be empty.')
    if not page_value:
        raise APIValueError('page_value', 'content cannot be empty.')
    user = ctx.request.user
    pageview = Pageviews(user_id=user.id, user_name=user.name, page_name=page_name, element=element, byway=byway, page_value=page_value)
    pageview.insert()
    return pageview
def api_update_pageview(page_id):
    check_admin()
    i = ctx.request.input(page_name='', element='', byway='', page_value='')
    page_name = i.page_name.strip()
    element = i.element.strip()
    byway = i.byway.strip()
    page_value = i.page_value.strip()
    if not page_name:
        raise APIValueError('page_name', 'name cannot be empty.')
    if not element:
        raise APIValueError('element', 'summary cannot be empty.')
    if not byway:
        raise APIValueError('byway', 'content cannot be empty.')
    if not page_value:
        raise APIValueError('page_value', 'content cannot be empty.')
    pageview = Pageviews.get(page_id)
    if pageview is None:
        raise APIResourceNotFoundError('Page')
    pageview.page_name = page_name
    pageview.element = element
    pageview.byway = byway
    pageview.page_value = page_value
    pageview.update()
    return pageview
def api_get_pageview(page_id):
    pageview = Pageviews.get(page_id)
    if pageview:
        return pageview
    raise APIResourceNotFoundError('Pageview')
def manage_pagevies_edit(page_id):
    pageview = Pageviews.get(page_id)
    if pageview is None:
        raise notfound()
    return dict(id=pageview.id, page_name=pageview.page_name, element=pageview.element, byway=pageview.byway, page_value=pageview.page_value, action='/api/pageviews/%s' % page_id, redirect='/manage/pageviews', user=ctx.request.user)
def _get_pageviews_by_page():
    total = Pageviews.count_all()
    page = Page(total, _get_page_index())
    pageviews = Pageviews.find_by('order by created_at desc limit ?,?', page.offset, page.limit)
    return pageviews, page