views.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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-30 22:13:1 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask import g, render_template, request
  14. from maple.helpers import is_num
  15. from maple.topic.models import Topic
  16. from maple.forums.models import Board
  17. def board(child_b):
  18. page = is_num(request.args.get('page'))
  19. if child_b is None:
  20. boards = Board.query.filter_by(parent_board=g.parent_b).all()
  21. topic_base = Topic.query.join(Topic.board).filter(Board.parent_board ==
  22. g.parent_b)
  23. topics = topic_base.filter(Topic.is_top == False).paginate(page, 20,
  24. True)
  25. top_topics = topic_base.filter(Topic.is_top == True).limit(5).all()
  26. data = {'title': '%s - ' % g.parent_b,
  27. 'boards': boards,
  28. 'topics': topics,
  29. 'top_topics': top_topics}
  30. return render_template('board/board_list.html', **data)
  31. else:
  32. board = Board.query.filter_by(board=child_b).first_or_404()
  33. topic_base = board.topics
  34. topics = topic_base.filter(Topic.is_top == False).paginate(page, 20,
  35. True)
  36. top_topics = topic_base.filter(Topic.is_top == True).limit(5).all()
  37. data = {'title': '%s - ' % board.board,
  38. 'board': board,
  39. 'topics': topics,
  40. 'top_topics': top_topics}
  41. return render_template('board/board.html', **data)