Exemple #1
0
 def topics(self, tag):
     query_dict = request.data
     page, number = self.pageinfo
     keys = ['name']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     order_by = gen_topic_orderby(query_dict, keys)
     filter_dict = gen_topic_filter(query_dict, keys)
     filter_dict.update(tags__id=tag.id)
     return Topic.query.filter_by(
         **filter_dict).order_by(*order_by).paginate(page, number, True)
Exemple #2
0
 def topics(self, tag):
     query_dict = request.data
     page, number = self.page_info
     keys = ['name']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     order_by = gen_topic_orderby(query_dict, keys)
     filter_dict = gen_topic_filter(query_dict, keys)
     filter_dict.update(tags__id=tag.id)
     return Topic.query.filter_by(**filter_dict).order_by(
         *order_by).paginate(page, number, True)
Exemple #3
0
 def topics(self, boardId, has_children):
     query_dict = request.data
     page, number = self.page_info
     keys = ['title']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     order_by = gen_topic_orderby(query_dict, keys)
     filter_dict = gen_topic_filter(query_dict, keys)
     if has_children:
         topics = Topic.query.outerjoin(Board).filter_by(**filter_dict).or_(
             Board.parent_id == boardId,
             Board.id == boardId).order_by(*order_by).paginate(
                 page, number, True)
     else:
         filter_dict.update(board_id=boardId)
         topics = Topic.query.filter_by(**filter_dict).order_by(
             *order_by).paginate(page, number, True)
     return topics
Exemple #4
0
 def get(self):
     query_dict = request.data
     page, number = self.page_info
     keys = ['title']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     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_top=True)
         title = _('Top Topics')
     topics = Topic.query.filter_by(
         **filter_dict).order_by(*order_by).paginate(page, number, True)
     data = {'title': title, 'topics': topics}
     return render_template('topic/topic_list.html', **data)
Exemple #5
0
 def get(self):
     query_dict = request.data
     page, number = self.pageinfo
     keys = ['title']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     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_top=True)
         title = _('Top Topics')
     topics = Topic.query.filter_by(
         **filter_dict).order_by(*order_by).paginate(page, number, True)
     data = {'title': title, 'topics': topics}
     return render_template('topic/topic_list.html', **data)
Exemple #6
0
 def topics(self, boardId, has_children):
     query_dict = request.data
     page, number = self.pageinfo
     keys = ['title']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     order_by = gen_topic_orderby(query_dict, keys)
     filter_dict = gen_topic_filter(query_dict, keys)
     if has_children:
         o = []
         for i in order_by:
             if i.startswith('-'):
                 o.append(getattr(Topic, i.split('-')[1]).desc())
             else:
                 o.append(getattr(Topic, i))
         topics = Topic.query.filter_by(**filter_dict).outerjoin(Board).or_(
             Board.parent_id == boardId,
             Board.id == boardId).order_by(*o).paginate(page, number, True)
         return topics
     filter_dict.update(board_id=boardId)
     topics = Topic.query.filter_by(
         **filter_dict).order_by(*order_by).paginate(page, number, True)
     return topics
Exemple #7
0
 def topics(self, boardId, has_children):
     query_dict = request.data
     page, number = self.page_info
     keys = ['title']
     # order_by = gen_order_by(query_dict, keys)
     # filter_dict = gen_filter_dict(query_dict, keys)
     order_by = gen_topic_orderby(query_dict, keys)
     filter_dict = gen_topic_filter(query_dict, keys)
     if has_children:
         o = []
         for i in order_by:
             if i.startswith('-'):
                 o.append(getattr(Topic, i.split('-')[1]).desc())
             else:
                 o.append(getattr(Topic, i))
         topics = Topic.query.filter_by(**filter_dict).outerjoin(Board).or_(
             Board.parent_id == boardId,
             Board.id == boardId).order_by(*o).paginate(page, number, True)
         return topics
     filter_dict.update(board_id=boardId)
     topics = Topic.query.filter_by(**filter_dict).order_by(
         *order_by).paginate(page, number, True)
     return topics
Exemple #8
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)