示例#1
0
文件: admin.py 项目: ScenK/Dev_Blog2
def cmspage_edit(page_url):
    """CMS page edit or create.

    Methods:
        GET and POST

    Args:
        POST:
            title: page title
            html: content html
            url: page url
        GET:
            page_url: string

    """
    if request.method == 'POST':

        title = request.form["title"]
        html = request.form["content"]
        url = request.form["url"]

        PageDispatcher().edit_or_create_page(title, html, url)

        return redirect(url_for('admin.cmspage_list'))

    else:
        page = PageDispatcher().get_static_page(page_url=page_url)

        return render_template('admin/page/edit.html', page=page)
示例#2
0
def page(page_url):
    """CMS page.
    show page for page_name.

    Methods:
        POST

    Args:
        page_url: string

    Return:
        categories: used for sidebar
        page object
        pages: used for top-nav
        profile: user object
    """
    profile = UserDispatcher().get_profile()
    categories = CategoryDispatcher().get_all_categories('-publish_time')
    pages = PageDispatcher().get_all_pages('-publish_time')
    page = PageDispatcher().get_page(page_url=page_url)

    return render_template(templates['page'],
                           page=page,
                           categories=categories,
                           pages=pages,
                           profile=profile)
示例#3
0
def home():
    """ HomePage.

     list newest 5 diaries.

    Args:
        none

    Return:
        diaries: 5 diaries list
        categories: used for sidebar
        pages: used for top-nav
        profile: user object
        next_page: boolen
    """
    page_size = 5

    profile = UserDispatcher().get_profile()
    categories = CategoryDispatcher().get_all_categories()
    pages = PageDispatcher().get_all_pages()
    prev, next, diaries = DiaryDispatcher().get_diary_list(0, page_size)

    return render_template(templates['home'],
                           diaries=diaries,
                           categories=categories,
                           pages=pages,
                           profile=profile,
                           next_page=next)
示例#4
0
def diary_detail(diary_id, diary_title=None):
    """ Diary Detail Page.

    show diary details.

    Args:
        diary_id: ObjectedId
        diary_title: string used for SEO Only

    Return:
        diary_detail: diary_object
        categories: used for sidebar
        guest_name: string cookie for guest comment auto complete filed
        guest_email: string cookie for guest comment auto complete filed
        pages: used for top-nav
        profile: user object
        prev: if has previous diary
        next: if has next diary
    """
    profile = UserDispatcher().get_profile()

    prev, next, diary = DiaryDispatcher().get_diary_width_navi(diary_id=diary_id)

    categories = CategoryDispatcher().get_all_categories()

    pages = PageDispatcher().get_all_pages()

    guest_name = request.cookies.get('guest_name')
    guest_email = request.cookies.get('guest_email')

    return render_template(templates['diary_detail'],
                           diary=diary, categories=categories,
                           guest_name=guest_name, guest_email=guest_email,
                           pages=pages, profile=profile, prev=prev, next=next)
示例#5
0
def diary_list(page_num=None, cat_id=None, cat_name=None, tag_name=None):
    """Diary list page.

    listed 5 diaries each page.Adjusted for diary, category and tag pagging.

    Args:
        page_num: numberic and int
        cate_name: string, can be none
        tag_name: string, can be none

    Return:
        diaries: listed 5 diaries objects
        next: bool True or False
        prev: bool True or False
        categories: used for sidebar
        pages: used for top-nav
        page_num: current page_num
        profile: user object
    """
    page_size = 5

    profile = UserDispatcher().get_profile()
    categories = CategoryDispatcher().get_all_categories()
    pages = PageDispatcher().get_all_pages()

    if not page_num:
        page_num = 1

    start = (int(page_num) - 1) * page_size
    end = int(page_num) * page_size

    if tag_name:
        prev, next, diaries = TagDispatcher().get_diary_list_with_navi(
            tag_name, start, end)
        tpl = 'tag_list'
    elif cat_name:
        prev, next, diaries = CategoryDispatcher().get_diary_list_with_navi(
            cat_name, start, end)
        tpl = 'cat_list'
    else:
        prev, next, diaries = DiaryDispatcher().get_diary_list(start, end)
        tpl = 'diary_list'

    return render_template(templates[tpl],
                           diaries=diaries,
                           categories=categories,
                           next_page=next,
                           prev_page=prev,
                           page_num=page_num,
                           pages=pages,
                           profile=profile,
                           cat_name=cat_name,
                           tag_name=tag_name)
示例#6
0
文件: admin.py 项目: ScenK/Dev_Blog2
def cmspage_del(page_url):
    """Admin StaticPage Delete Action

    Used for delete Category.

    Methods:
        GET

    Args:
        page_url: string

    Returns:
        none
    """
    PageDispatcher().del_cmspage_by_url(page_url)
    return redirect(url_for("admin.cmspage_list"))
示例#7
0
文件: admin.py 项目: ScenK/Dev_Blog2
def cmspage_list():
    """Admin CmsPage lit page.

    show all staticPages.

    Methods:
        GET

    Args:
        none

    Returns:
        StaticPage object
    """
    pages = PageDispatcher().get_all_static_pages()
    return render_template(templates["page_list"], pages=pages)