views.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # -*- coding=UTF-8 -*-
  3. # **************************************************************************
  4. # Copyright © 2016 jianglin
  5. # File Name: views.py
  6. # Author: jianglin
  7. # Email: xiyang0807@gmail.com
  8. # Created: 2016-06-03 14:32:06 (CST)
  9. # Last Update:星期日 2016-7-24 15:0:46 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask import g, render_template, request
  14. from maple import cache
  15. from maple.helpers import is_num
  16. from maple.topic.models import Topic
  17. from maple.forums.models import Board
  18. @cache.cached(timeout=60)
  19. def board(child_b):
  20. page = is_num(request.args.get('page'))
  21. if child_b is None:
  22. boards = Board.query.filter_by(parent_board=g.parent_b).all()
  23. topic_base = Topic.query.join(Topic.board).filter(Board.parent_board ==
  24. g.parent_b)
  25. topics = topic_base.filter(Topic.is_top == False).paginate(page, 20,
  26. True)
  27. top_topics = topic_base.filter(Topic.is_top == True).limit(5).all()
  28. data = {'title': '%s - ' % g.parent_b,
  29. 'boards': boards,
  30. 'topics': topics,
  31. 'top_topics': top_topics}
  32. return render_template('board/board_list.html', **data)
  33. else:
  34. board = Board.query.filter_by(board=child_b).first_or_404()
  35. topic_base = board.topics
  36. topics = topic_base.filter(Topic.is_top == False).paginate(page, 20,
  37. True)
  38. top_topics = topic_base.filter(Topic.is_top == True).limit(5).all()
  39. data = {'title': '%s - ' % board.board,
  40. 'board': board,
  41. 'topics': topics,
  42. 'top_topics': top_topics}
  43. return render_template('board/board.html', **data)