Exemplo n.º 1
0
 def get(self, id):
     comment = Comments.query.filter_by(answers_id = id).order_by('-id').all()
     comments_list = []
     for i in comment:
         comment_user = User.query.filter_by(id = i.author_id).first()
         replies = Replys.query.filter_by(comments_id = i.id).all()
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         comments_data = object_as_dict(i)
         comments_data['diff_time'] = diff_time
         comments_data['author'] = comment_user.username
         Avatar(comments_data, comment_user)
         comments_list.append(comments_data)
         replies_list = []
         for j in replies:
             diff_time = time_diff(j.updated_at)
             reply_user = User.query.filter_by(id = j.author_id).first()
             j.created_at = str(j.created_at)
             j.updated_at = str(j.updated_at)
             reply_data = object_as_dict(j)
             reply_data['author'] = reply_user.username
             reply_data['diff_time'] = diff_time
             replies_list.append(reply_data)
             Avatar(reply_data, reply_user)
         comments_data['replies'] = replies_list
     return get_json(1, '回答的评论列表', comments_list)
Exemplo n.º 2
0
 def post(self, id):
     qusetion = Questions.query.filter_by(id=id).first_or_404()
     post_data = request.data
     #user = request.user
     content = post_data.pop('content', None)
     bar_reply = Answers(content = content, questions_id = qusetion.id, is_reply = 1)
     bar_reply.author_id = 5
     bar_reply.save()
     diff_time = time_diff(bar_reply.updated_at)
     reply_user = User.query.filter_by(id = bar_reply.author_id).first()
     bar_reply.created_at = str(bar_reply.created_at)
     bar_reply.updated_at = str(bar_reply.updated_at)
     replies_data = object_as_dict(bar_reply)
     replies_data['author'] = reply_user.username
     replies_data['diff_time'] = diff_time
     Avatar(replies_data, reply_user)
     return get_json(1, '评论成功', object_as_dict(bar_reply))
Exemplo n.º 3
0
 def get(self, topicId, page):
     #form = ReplyForm()
     start = (page - 1) * 5
     query_dict = request.data
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     #page, number = self.page_info
     keys = ['title']
     order_by = gen_order_by(query_dict, keys)
     filter_dict = gen_filter_dict(query_dict, keys)
     reply = topic.replies.filter_by(topic_id=topicId, is_reply=1).order_by(
         ('-id')).limit(5).offset(start)
     reply_count = topic.replies.filter_by(topic_id=topicId,
                                           is_reply=1).count()
     page_count = int(math.ceil(reply_count / 5))
     replies = []
     diff_time = time_diff(topic.updated_at)
     topic.created_at = str(topic.created_at)
     topic.updated_at = str(topic.updated_at)
     for i in reply:
         user = User.query.filter_by(id=i.author_id).first()
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         replies_data = object_as_dict(i)
         replies_data['author'] = user.username
         replies_data['diff_time'] = diff_time
         Avatar(replies_data, user)
         replies.append(replies_data)
     #topic.read_count = 1
     topic_data = object_as_dict(topic)
     topic_user = User.query.filter_by(id=topic_data['author_id']).first()
     topic_data['author'] = topic_user.username
     topic_data['diff_time'] = diff_time
     Avatar(topic_data, topic_user)
     data = {
         #'title': topic['title'],
         #'form': object_as_dict(form),
         'topic': topic_data,
         'replies': replies,
         'replies_count': reply_count,
         'page_count': page_count
     }
     #topic.read_count = 1
     return get_json(1, '文章详情', data)
Exemplo n.º 4
0
 def get(self):
     barlists = Bar.query.all()
     bar_questions = Questions.query.filter_by(bar_id = 1, is_bar=1).first()
     user = User.query.filter_by(id = bar_questions.author_id).first()
     bar = Bar.query.filter_by(id = bar_questions.bar_id).first()
     question = object_as_dict(bar_questions)
     Avatar(question, user)
     question['author'] = user.username
     question['bar'] = bar.title
     barlist = []
     for i in barlists:
         user = User.query.filter_by(id = i.author_id).first()
         picture = current_app.config['SERVER_URL'] + '/' + i.picture
         bar_data = object_as_dict(i)
         bar_data['author'] = user.username  
         bar_data['picture'] = picture
         barlist.append(bar_data)
     data = {'barlist': barlist, 'barquestion': question}
     return get_json(1, 'bar列表', data)
Exemplo n.º 5
0
 def get(self, id):
     bar_replies = Answers.query.filter_by(questions_id = id, is_reply = 1).order_by('-id').all()
     replies = []
     for i in bar_replies: 
         user = User.query.filter_by(id = i.author_id).first()
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         replies_data = object_as_dict(i)
         replies_data['author'] = user.username
         replies_data['diff_time'] = diff_time
         Avatar(replies_data, user)
         replies.append(replies_data)
     return get_json(1, '评论信息', replies)
Exemplo n.º 6
0
 def get(self, id):
     bar_question = Questions.query.filter_by(id = id).first()
     bar_answers = Answers.query.filter_by(questions_id = id, is_reply = 0).order_by('-id').all()
     question_user = User.query.filter_by(id = bar_question.author_id).first()
     diff_time = time_diff(bar_question.updated_at)
     bar_question.created_at = str(bar_question.created_at)
     bar_question.updated_at = str(bar_question.updated_at)
     questions_data = object_as_dict(bar_question)
     questions_data['diff_time'] = diff_time
     questions_data['author'] = question_user.username
     Avatar(questions_data, question_user)
     answers_list = []
     for i in bar_answers:
         answer_user = User.query.filter_by(id = i.author_id).first()
         #comment = Comments.query.filter_by(answers_id = i.id, is_reply = 0).all()
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         answers_data = object_as_dict(i)
         answers_data['author'] = answer_user.username
         answers_data['diff_time'] = diff_time
         #comment_list = []
         #for j in comment:
         #    diff_time = time_diff(j.updated_at)
         #    comment_user = User.query.filter_by(id = j.author_id).first()
         #    j.created_at = str(j.created_at)
         #    j.updated_at = str(j.updated_at)
         #    comment_data = object_as_dict(j)
         #    comment_data['author'] = comment_user.username
         #    comment_data['diff_time'] = diff_time
         #    comment_list.append(comment_data)
         #answers_data['comments'] = comment_list
         Avatar(answers_data, answer_user)
         answers_list.append(answers_data)
     data = {'question':questions_data, 'answers':answers_list}
     return get_json(1, 'bar问题详情页', data)
Exemplo n.º 7
0
 def get(self, username):
     query_dict = request.data
     user = User.query.filter_by(username=username).first_or_404()
     #page, number = self.page_info
     keys = ['title']
     order_by = gen_order_by(query_dict, keys)
     filter_dict = gen_filter_dict(query_dict, keys)
     filter_dict.update(author_id=user.id)
     topics = Topic.query.filter_by(
         **filter_dict).order_by(*order_by).all()#.paginate(page, number, True)
     setting = user.setting
     #topic_is_allowed = False
     #if setting.topic_list == 1 or (setting.topic_list == 2 and
     #                               current_user.is_authenticated):
     #    topic_is_allowed = True
     #if current_user.is_authenticated and current_user.id == user.id:
     #    topic_is_allowed = True
     print(topics,1111111111111111111111,user)
     data = {
         'topics': [object_as_dict(i) for i in topics],
         'user': object_as_dict(user)
     #    'topic_is_allowed': topic_is_allowed
     }
     return get_json(1, '个人中心', data)
Exemplo n.º 8
0
 def get(self, topicId, page):
     start = (page - 1) * 5
     reply = Reply.query.filter_by(topic_id=topicId, is_reply=1).order_by(
         ('-id')).limit(5).offset(start)
     replies = []
     for i in reply:
         user = User.query.filter_by(id=i.author_id).first()
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         replies_data = object_as_dict(i)
         replies_data['author'] = user.username
         replies_data['diff_time'] = diff_time
         Avatar(replies_data, user)
         replies.append(replies_data)
     return get_json(1, '评论信息', replies)
Exemplo n.º 9
0
 def post(self, id):
     qusetion = Questions.query.filter_by(id = id).first_or_404()
     post_data = request.data
     #user = request.user
     content = post_data.pop('content', None)
     bar_answer = Answers(content = content, questions_id = id, is_reply = 0)
     bar_answer.author_id = 6
     bar_answer.save()
     diff_time = time_diff(bar_answer.updated_at)
     answer_user = User.query.filter_by(id = bar_answer.author_id).first()
     bar_answer.created_at = str(bar_answer.created_at)
     bar_answer.updated_at = str(bar_answer.updated_at)
     answers_data = object_as_dict(bar_answer)
     answers_data['author'] = answer_user.username
     answers_data['diff_time'] = diff_time
     Avatar(answers_data, answer_user)
     return get_json(1, '回答成功', answers_data)
Exemplo n.º 10
0
 def post(self, id):
     #Comment = Answers.query.filter_by(id = id).first_or_404()
     post_data = request.data
     #user = request.user
     content = post_data.pop('content', None)
     answer_comment = Comments(content = content, answers_id = id)
     answer_comment.author_id = 7
     answer_comment.save()
     diff_time = time_diff(answer_comment.updated_at)
     answer_user = User.query.filter_by(id = answer_comment.author_id).first()
     answer_comment.created_at = str(answer_comment.created_at)
     answer_comment.updated_at = str(answer_comment.updated_at)
     comments_data = object_as_dict(answer_comment)
     comments_data['author'] = answer_user.username
     comments_data['diff_time'] = diff_time
     Avatar(comments_data, answer_user)
     return get_json(1, '评论成功', comments_data)
Exemplo n.º 11
0
 def post(self, topicId):
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     post_data = request.data
     user = request.user
     print(user, 88888888888888888888888888888888888888888888888888888)
     content = post_data.pop('content', None)
     reply = Reply(content=content, topic_id=topic.id, is_reply=1)
     #user = User.query.filter_by(id=1).first()
     reply.author_id = user.id
     reply.save()
     replies_data = object_as_dict(reply)
     replies_data['author'] = user.username
     # notice
     #MessageClient.topic(reply)
     # count
     #topic.board.post_count = 1
     #reply.author.reply_count = 1
     return get_json(1, '评论成功', replies_data)
Exemplo n.º 12
0
 def post(self, id):
     comment = Comments.query.filter_by(id=id).first_or_404()
     post_data = request.data
     #user = request.user
     content = post_data.pop('content', None)
     comment_reply = Replys(content = content, comments_id = id)
     comment_reply.author_id = 5
     comment_reply.save()
     diff_time = time_diff(comment_reply.updated_at)
     reply_user = User.query.filter_by(id = comment_reply.author_id).first()
     comment_reply.created_at = str(comment_reply.created_at)
     comment_reply.updated_at = str(comment_reply.updated_at)
     replies_data = object_as_dict(comment_reply)
     replies_data['author'] = reply_user.username
     replies_data['diff_time'] = diff_time
     Avatar(replies_data, reply_user)
     data = {'comment_content':comment.content,'replies':replies_data}
     return get_json(1, '评论成功', data)
Exemplo n.º 13
0
 def get(self, id):
     bar_questions = Questions.query.filter_by(bar_id = id, is_bar=1).all()
     question_list = []
     for i in bar_questions:
         user = User.query.filter_by(id = i.author_id).first()
         try:
             bar_reply = Answers.query.filter_by(bar_topic_id = i.id).count()
         except:
             bar_reply = 0
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         questions_data = object_as_dict(i)
         questions_data['author'] = user.username
         questions_data['diff_time'] = diff_time
         questions_data['replies_count'] = bar_reply
         Avatar(questions_data, user)
         question_list.append(questions_data)
     return get_json(1, 'bar问题列表', question_list)
Exemplo n.º 14
0
 def post(self):
     file_dict = request.files.to_dict()
     for filename in file_dict:
         Files = file_dict[filename]
         if Files and check_file(Files.filename):
             filename = secure_filename(Files.filename)
             n_filename = filename.rsplit('.', 1)[0]
             fix = filename.rsplit('.', 1)[1]
             newfilename = "%s%s%s%s%s%s"%(n_filename, '_', str(int(time())), str(
                     randint(1000, 9999)), '.', fix)
             file_path = current_app.config['PICTURE_FOLDER']
             file = os.path.join(file_path, newfilename)
             if not os.path.exists(file_path):
                 os.makedirs(file_path)
             files = File(
                 front_file = filename,
                 file_path = file_path + '/' + newfilename)
             files.save()
             files.file_path = current_app.config['SERVER_URL'] + '/' + file_path + '/' + newfilename
             Files.save(file)
         else:
             return get_json(0, '格式错误', {})
     return get_json(1, '上传成功', object_as_dict(files))
Exemplo n.º 15
0
 def get(self, page):
     start = (page - 1) * 5
     query_dict = request.data
     keys = ['title']
     order_by = gen_topic_orderby(query_dict, keys)
     filter_dict = gen_topic_filter(query_dict, keys)
     title = _('All Topics')
     if request.path.endswith('good'):
         filter_dict.update(is_good=True)
         title = _('Good Topics')
     elif request.path.endswith('top'):
         filter_dict.update(is_bad=True)
         title = _('bad Topics')
     topics = Topic.query.filter_by(**filter_dict).order_by(
         *order_by).limit(5).offset(start)
     topic_count = FindAndCount(Topic)
     page_count = int(math.ceil(topic_count / 5))
     topic = []
     for i in topics:
         user = User.query.filter_by(id=i.author_id).first()
         reply_count = FindAndCount(Reply, topic_id=i.id, is_reply=1)
         diff_time = time_diff(i.updated_at)
         i.created_at = str(i.created_at)
         i.updated_at = str(i.updated_at)
         topics_data = object_as_dict(i)
         topics_data['author'] = user.username
         topics_data['diff_time'] = diff_time
         topics_data['replies_count'] = reply_count
         Avatar(topics_data, user)
         topic.append(topics_data)
     data = {
         'classification': title,
         'topics': topic,
         'topic_count': topic_count,
         'page_count': page_count
     }
     return get_json(1, '文章列表', data)
Exemplo n.º 16
0
 def post(self):
     user = request.user
     print(user, 88888888888888888888888888888888888888888888888888888)
     form = TopicForm()
     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', 0)
     token = post_data.pop('token', None)
     #board = post_data.pop('category', None)
     topic = Topic(title=title,
                   content=content,
                   content_type=content_type,
                   token=token)
     #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
     #user = User.query.filter_by(id=1).first()
     topic.author = user
     topic.save()
     topic = object_as_dict(topic)
     Avatar(topic, user)
     topic['author'] = user.username
     #topic.board.topic_count = 1
     #topic.board.post_count = 1
     #topic.author.topic_count = 1
     #topic.reply_count = 1
     return get_json(1, '发表成功', topic)