コード例 #1
0
	def show_category(self, Request):
		""" Controller to show poss by category"""

		category = Request.param('id')

		posts = Post.where('category', category).where('is_live', 1).get()
		return view('blog/category', {'author': User, 'category': category, 'posts': posts})
コード例 #2
0
	def show_one(self, Request, RenderEngine):
		""" Controller to show single post"""

		# Get post via slug
		slug = Request.param('id')
		posts = Post.where('slug', slug).where('is_live', 1).get()
		post = posts[0]
		post.body = RenderEngine(post.body)

		# Get current author
		user = User.where('id', post.author_id).get()

		# Get recent posts
		recent_posts = Post.where('is_live', 1).order_by('updated_at', 'desc').take(5).get()

		return view('blog/post', {'user': user[0], 'post': post, 'recent': recent_posts })
コード例 #3
0
	def show_author(self, Request):
		""" Controller to show posts by author"""

		user_name = Request.param('id')

		author = User.where('user_name', user_name).get()

		posts = Post.where('author_id', author[0].id).where('is_live', 1).get()

		return view('blog/author', {'author': author[0], 'posts': posts})
コード例 #4
0
    def activate(self, Request):
        """ Activates post to be displayed """
        if not Auth(Request).user():
            Request.redirect('dashboard')

        slug = Request.param('id')
        posts = Post.where('slug', slug).get()
        post = posts[0]
        post.is_live = True
        post.save()
        return Request.redirect('dashboard/blog', {'Auth': Auth(Request)})
コード例 #5
0
    def delete(self, Request):
        """ Delete Post Controller """

        if not Auth(Request).user():
            Request.redirect('/dashboard')

        slug = Request.param('id')
        posts = Post.where('slug', slug).get()
        post = posts[0]
        post.delete()
        return Request.redirect('dashboard/blog', {'Auth': Auth(Request)})
コード例 #6
0
    def deactivate(self, Request):
        """ Removes post from active list """

        if not Auth(Request).user():
            Request.redirect('dashboard')

        slug = Request.param('id')
        posts = Post.where('slug', slug).get()
        post = posts[0]
        post.is_live = False
        post.save()
        return Request.redirect('dashboard/blog', {'Auth': Auth(Request)})
コード例 #7
0
    def show_delete(self, Request):
        """ Display Post Delete page """

        if not Auth(Request).user():
            Request.redirect('/dashboard')

        slug = Request.param('id')
        posts = Post.where('slug', slug).get()
        post = posts[0]

        return view('dashboard/post/delete', {
            'post': post,
            'Auth': Auth(Request)
        })
コード例 #8
0
    def preview(self, Request, RenderEngine):
        """ Display all posts in blog editor """

        if not Auth(Request).user():
            Request.redirect('dashboard')

        # Get post via slug
        slug = Request.param('id')
        posts = Post.where('slug', slug).get()
        post = posts[0]
        post.body = RenderEngine(post.body)

        return view('dashboard/post/preview', {
            'author': User,
            'Auth': Auth(Request),
            'posts': post
        })
コード例 #9
0
    def update(self, Request):
        """ Update Post Controller """

        if not Auth(Request).user():
            Request.redirect('/dashboard')

        slug = Request.param('id')
        posts = Post.where('slug', slug).get()
        post = posts[0]

        # Updates Post
        post.title = remove_whitespaces(Request.input('title'))
        post.slug = slugify(post.title)
        post.body = remove_whitespaces(Request.input('body'))
        post.category = remove_whitespaces(Request.input('category'))

        post.save()

        return Request.redirect('dashboard/post/{}/update'.format(post.slug),
                                {'Auth': Auth(Request)})
コード例 #10
0
	def show_all(self):
		""" Controller to show all posts"""

		posts = Post.where('is_live', 1).get()
		return view('blog', {'author': User, 'posts': posts})