Exemple #1
0
 def edit(self):
     year, month, day, route = self._get_route_args()
     post = Post.by_route(route)
     if post is None:
         return HTTPNotFound('No such post')
     form = BlogView.Form(self.request.POST, post)
     if self.request.method == 'POST' and form.validate():
         post.title = form.title.data
         post.created = form.created.data
         post.body = form.body.data
         post.is_published = form.is_published.data
         # edit tags
         del post.tags
         for tag in Tag.from_list(form.tags.data):
             nt = NodeTag()
             nt.tag = tag
             post.tags.append(nt)
         return HTTPFound(
             location=self.request.route_url('post_view',
                 year=year,
                 month=month,
                 day=day,
                 route=RouteAbleMixin.url_quote(post.title))
             )
     return dict(
         post=post,
         form=form,
         pages=Page.all(),
         logged_in=authenticated_userid(self.request),
         )
Exemple #2
0
 def view(self):
     year, month, day, route = self._get_route_args()
     post = Post.by_route(route)
     if post is None:
         return HTTPNotFound("No such post")
     form = BlogView.CommentForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         if form.parent.data == '':
             post_comment = PostComment()
             post_comment.comment = Comment(form.name.data, form.email.data, form.body.data)
             post.comments.append(post_comment)
         else:
             parent_id = int(form.parent.data)
             parent_comment = Comment.by_id(parent_id)
             parent_comment.childs.append(
                 Comment(
                     form.name.data,
                     form.email.data,
                     form.body.data,
                     parent_id,
                     )
                 )
         return HTTPFound(
             location=self.request.route_url('post_view',
                 year=year,
                 month=month,
                 day=day,
                 route=RouteAbleMixin.url_quote(post.title))
             )
     return dict(
         form=form,
         post=post,
         pages=Page.all(),
         logged_in=authenticated_userid(self.request),
         )
Exemple #3
0
 def add(self):
     form = BlogView.Form(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         # create post
         post = Post.add(
             form.title.data,
             form.body.data,
             form.created.data,
             form.is_published.data
             )
         # add tags
         for tag in Tag.from_list(form.tags.data):
             nt = NodeTag()
             nt.tag = tag
             post.tags.append(nt)
         return HTTPFound(location=self.request.route_url('post_view',
                 year=post.created.strftime('%Y'),
                 month=post.created.strftime('%m'),
                 day=post.created.strftime('%d'),
                 route=RouteAbleMixin.url_quote(post.title)
                 )
             )
     return dict(
         form=form,
         url=self.request.route_url('post_add'),
         pages=Page.all(),
         logged_in=authenticated_userid(self.request),
         )
Exemple #4
0
 def delete_comment(self):
     log.debug(self.request)
     request = self.request
     year, month, day, route = self._get_route_args()
     post = Post.by_route(route)
     if post is None:
         return HTTPNotFound('No such post')
     cid = int(request.matchdict['id'])
     comment = Comment.by_id(cid)
     post.delete_comment(comment)
     return HTTPFound(
             location=self.request.route_url('post_view',
                 year=year,
                 month=month,
                 day=day,
                 route=RouteAbleMixin.url_quote(post.title))
             )