예제 #1
0
파일: views.py 프로젝트: daymien/pymyblog
 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),
         )
예제 #2
0
파일: views.py 프로젝트: daymien/pymyblog
 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),
         )