Esempio n. 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')
    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)})
Esempio n. 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'
    def store(self):
        Post.create(
            title=request().input('title'),
            body=request().input('body'),
            author_id=request().user().id
        )

        return 'Post created'
Esempio n. 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})
Esempio n. 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 })
Esempio n. 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'
    def store(self):
        post = Post.find(request().param('id'))

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

        post.save()

        return 'post updated'
Esempio n. 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'
Esempio n. 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})
    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)})
    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)})
    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)})
    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
        })
    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)
        })
    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
        })
    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)})
Esempio n. 18
0
    def show(self, view: View):
        posts = Post.all()

        return view.render('posts', {'posts': posts})
Esempio n. 19
0
    def delete(self, request: Request):
        post = Post.find(request.param('id'))

        post.delete()

        return 'post deleted'
    def single(self):
        post = Post.find(request().param('id'))

        return view('single',{'post': post})
    def update(self):
        post = Post.find(request().param('id'))

        return view('update',{'post': post})
    def delete(self):
        post = Post.find(request().param('id'))
        post.delete()

        return 'post deleted'
    def show(self):
        posts = Post.all()

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

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

        return view.render('edit', {'post': post})
Esempio n. 28
0
    def show(self, view: View, request: Request):
        post = Post.find(request.param('id'))

        return view.render('blog.post.show', {
            'post': post
        })
Esempio n. 29
0
 def show(self, view: View):
     # открытие всех постов
     posts = Post.all()
     return view.render('posts', {'posts': posts})
Esempio n. 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'
Esempio n. 31
0
 def single(self, view: View, request: Request):
     # открытие одного поста
     post = Post.find(request.param('id'))
     return view.render('single', {'post': post})