示例#1
0
 def post(self):
     user = request.user
     form = form_board()
     post_data = form.data
     title = post_data.pop('title', None)
     content = post_data.pop('content', None)
     tags = post_data.pop('tags', None)
     content_type = post_data.pop('content_type', None)
     board = post_data.pop('category', None)
     topic = Topic(
         title=title,
         content=content,
         content_type=content_type,
         board_id=int(board))
     tags = tags.split(',')
     topic_tags = []
     for tag in tags:
         tag = tag.strip()
         topic_tag = Tags.query.filter_by(name=tag).first()
         if topic_tag is None:
             topic_tag = Tags(name=tag, description=tag)
             topic_tag.save()
         topic_tags.append(topic_tag)
     topic.tags = topic_tags
     topic.author = user
     topic.save()
     # count
     topic.board.topic_count = 1
     topic.board.post_count = 1
     topic.author.topic_count = 1
     topic.reply_count = 1
     return redirect(url_for('topic.topic', topicId=topic.id))
示例#2
0
 def get(self):
     boardId = request.args.get('boardId', type=int)
     form = form_board()
     if boardId is not None:
         form.category.data = boardId
     data = {'title': _('Ask - '), 'form': form}
     return render_template('topic/ask.html', **data)
示例#3
0
 def post(self):
     user = request.user
     form = form_board()
     post_data = form.data
     title = post_data.pop('title', None)
     content = post_data.pop('content', None)
     tags = post_data.pop('tags', None)
     content_type = post_data.pop('content_type', None)
     board = post_data.pop('category', None)
     topic = Topic(
         title=title,
         content=content,
         content_type=content_type,
         board_id=int(board))
     tags = tags.split(',')
     topic_tags = []
     for tag in tags:
         tag = tag.strip()
         topic_tag = Tags.query.filter_by(name=tag).first()
         if topic_tag is None:
             topic_tag = Tags(name=tag, description=tag)
             topic_tag.save()
         topic_tags.append(topic_tag)
     topic.tags = topic_tags
     topic.author = user
     topic.save()
     # count
     topic.board.topic_count = 1
     topic.board.post_count = 1
     topic.author.topic_count = 1
     topic.reply_count = 1
     return redirect(url_for('topic.topic', topicId=topic.id))
示例#4
0
 def get(self):
     boardId = request.args.get('boardId', type=int)
     form = form_board()
     if boardId is not None:
         form.category.data = boardId
     data = {'title': _('Ask - '), 'form': form}
     return render_template('topic/ask.html', **data)
示例#5
0
 def get(self, topicId):
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     form = form_board()
     form.title.data = topic.title
     form.category.data = topic.board_id
     form.tags.data = ','.join([tag.name for tag in topic.tags])
     form.content.data = topic.content
     data = {'title': _('Edit -'), 'form': form, 'topic': topic}
     return render_template('topic/edit.html', **data)
示例#6
0
 def get(self, topicId):
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     form = form_board()
     form.title.data = topic.title
     form.category.data = topic.board_id
     form.tags.data = ','.join([tag.name for tag in topic.tags])
     form.content.data = topic.content
     data = {'title': _('Edit -'), 'form': form, 'topic': topic}
     return render_template('topic/edit.html', **data)
示例#7
0
 def put(self, topicId):
     form = form_board()
     post_data = form.data
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     title = post_data.pop('title', None)
     content = post_data.pop('content', None)
     content_type = post_data.pop('content_type', None)
     category = post_data.pop('category', None)
     if title is not None:
         topic.title = title
     if content is not None:
         topic.content = content
     if content_type is not None:
         topic.content_type = content_type
     if category is not None:
         topic.board_id = int(category)
     topic.save()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
示例#8
0
 def put(self, topicId):
     form = form_board()
     post_data = form.data
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     title = post_data.pop('title', None)
     content = post_data.pop('content', None)
     content_type = post_data.pop('content_type', None)
     category = post_data.pop('category', None)
     if title is not None:
         topic.title = title
     if content is not None:
         topic.content = content
     if content_type is not None:
         topic.content_type = content_type
     if category is not None:
         topic.board_id = int(category)
     topic.save()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()