示例#1
0
 def post(self):
     post_positions = [POSTS_SCHEMA["properties"].keys()]
     if request.json.keys() not in post_positions:
         raise errors.BadLuck
     post = Post(**request.json)
     post.add()
     return jsonify(post.to_dict())
示例#2
0
 def send_message():
     if not auth.is_authorized():
         return redirect('/login')
     form = WriteMessageForm()
     if form.validate_on_submit():
         receiver_id = request.args.get('sel')
         user = User.query.filter_by(id=receiver_id).first()
         message = form.message.data
         Post.add(from_who=auth.get_user().username,
                  to=user.username,
                  message=message,
                  user=auth.get_user())
         return redirect('/main')
     return render_template('message-write.html',
                            title='Написать сообщение',
                            form=form)
示例#3
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),
         )
示例#4
0
 def post(self):
     post = Post(**request.json)
     post.user_id = get_jwt_identity()
     post.add()
     return jsonify(post.to_dict())