def create_topic_comment(tid): topic = Topic.cache.get_or_404(tid) form = CommentForm.create_api_form() comment = form.create_comment(current_user.id, topic.id) rv = dict(comment) rv['content'] = markup(rv['content']) rv['user'] = dict(current_user) return jsonify(rv), 201
def view_topic_comments(tid): topic = Topic.cache.get_or_404(tid) comments, cursor = cursor_query(Comment, lambda q: q.filter_by(topic_id=topic.id)) data = [] if current_user: statuses = Comment.get_multi_statuses([c['id'] for c in comments], current_user.id) else: statuses = {} for d in iter_items_with_users(comments): d['content'] = markup(d['content']) # update status d.update(statuses.get(str(d['id']), {})) data.append(d) return jsonify(data=data, cursor=cursor)
def view_topic_comments(tid): topic = Topic.cache.get_or_404(tid) comments, cursor = cursor_query( Comment, lambda q: q.filter_by(topic_id=topic.id) ) data = [] if current_user: statuses = Comment.get_multi_statuses( [c['id'] for c in comments], current_user.id ) else: statuses = {} for d in iter_items_with_users(comments): d['content'] = markup(d['content']) # update status d.update(statuses.get(str(d['id']), {})) data.append(d) return jsonify(data=data, cursor=cursor)
def html(self): return markup(self.content)
def preview_text(): data = request.get_json() text = data.get('text') if not text: return '' return markup(text)