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())
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)
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), )
def post(self): post = Post(**request.json) post.user_id = get_jwt_identity() post.add() return jsonify(post.to_dict())