コード例 #1
0
    def store(self, request: Request):
        title = request.input('title')
        body = request.input('body')

        Post.create(title=title, body=body, author_id=1)

        return request.redirect('/blog')
コード例 #2
0
    def create(self, Request, Upload):
        """ Create new post """

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

        # Make slug
        slug = slugify(Request.input('title'))

        # Save image
        try:
            image = Upload.driver('s3').store_prepend(
                Request.input('file_upload'), 'blog/img/')
        except AttributeError:
            # If user did not pick image, set image to none. (Load default)
            image = "nightlife1.jpg"

        Post.create(title=remove_whitespaces(Request.input('title')),
                    slug=slug,
                    category=remove_whitespaces(Request.input('category')),
                    body=remove_whitespaces(Request.input('body')),
                    image=image,
                    author_id=Request.user().id,
                    is_live=1)

        return Request.redirect('dashboard/blog', {'Auth': Auth(Request)})
コード例 #3
0
    def store(self, request: Request):
        # New store Method
        Post.create(title=request.input('title'),
                    image='no img',
                    body=request.input('body'),
                    author_id=request.user().id)

        return 'post created'
コード例 #4
0
    def store(self):
        Post.create(
            title=request().input('title'),
            body=request().input('body'),
            author_id=request().user().id
        )

        return 'Post created'
コード例 #5
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})
コード例 #6
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 })
コード例 #7
0
    def store(self, view: View, request: Request):
        # сохранение обновленого содержимого поста в бд
        post = Post.find(request.param('id'))

        post.title = request.input('title')
        post.body = request.input('body')
        post.save()

        return 'post updated'
コード例 #8
0
    def store(self):
        post = Post.find(request().param('id'))

        post.title = request().input('title')
        post.body = request().input('body')

        post.save()

        return 'post updated'
コード例 #9
0
    def update(self, view: View, request: Request):
        post = Post.find(request.param('id'))

        post.title = request.input('title')
        post.body = request.input('body')

        post.save()

        return 'post updated'
コード例 #10
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})
コード例 #11
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)})
コード例 #12
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)})
コード例 #13
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)})
コード例 #14
0
    def show_all(self, Request):
        """ Display all posts in blog editor """

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

        posts = Post.all()

        return view('dashboard/blog', {
            'author': User,
            'Auth': Auth(Request),
            'posts': posts
        })
コード例 #15
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)
        })
コード例 #16
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
        })
コード例 #17
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)})
コード例 #18
0
    def show(self, view: View):
        posts = Post.all()

        return view.render('posts', {'posts': posts})
コード例 #19
0
    def delete(self, request: Request):
        post = Post.find(request.param('id'))

        post.delete()

        return 'post deleted'
コード例 #20
0
    def single(self):
        post = Post.find(request().param('id'))

        return view('single',{'post': post})
コード例 #21
0
    def update(self):
        post = Post.find(request().param('id'))

        return view('update',{'post': post})
コード例 #22
0
    def delete(self):
        post = Post.find(request().param('id'))
        post.delete()

        return 'post deleted'
コード例 #23
0
    def show(self):
        posts = Post.all()

        return view('posts',{'posts': posts})
コード例 #24
0
    def delete(self, request: Request):
        # удаление поста
        post = Post.find(request.param('id'))
        post.delete()

        return 'post deleted'
コード例 #25
0
 def index(self, view: View):
     return view.render('blog.post.index', {
         'posts': Post.all()
     })
コード例 #26
0
 def update(self, view: View, request: Request):
     # обновленеи контента поста
     post = Post.find(request.param('id'))
     return view.render('update', {'post': post})
コード例 #27
0
    def edit(self, view: View, request: Request):
        post = Post.find(request.param('id'))

        return view.render('edit', {'post': post})
コード例 #28
0
    def show(self, view: View, request: Request):
        post = Post.find(request.param('id'))

        return view.render('blog.post.show', {
            'post': post
        })
コード例 #29
0
 def show(self, view: View):
     # открытие всех постов
     posts = Post.all()
     return view.render('posts', {'posts': posts})
コード例 #30
0
    def store(self, request: Request):
        Post.create(title=request.input('title'),
                    body=request.input('body'),
                    author_id=request.user().id)

        return 'post created'
コード例 #31
0
 def single(self, view: View, request: Request):
     # открытие одного поста
     post = Post.find(request.param('id'))
     return view.render('single', {'post': post})