Personal wiki notebook (not under development)

Forum_page.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import os.path
  2. import cherrypy
  3. from datetime import datetime
  4. from Product_page import Product_page
  5. from Page_navigation import Page_navigation
  6. from Tags import Div, H1, A, P, Span, Link, Img, B
  7. class Forum_page( Product_page ):
  8. def __init__(
  9. self, user, notebooks, first_notebook, login_url, logout_url, rate_plan, groups, forum_name,
  10. threads, total_thread_count, start = 0, count = None,
  11. ):
  12. base_path = cherrypy.request.path
  13. updates_path = "%s?rss" % base_path
  14. if forum_name == u"blog":
  15. full_forum_name = u"Luminotes %s" % forum_name
  16. else:
  17. full_forum_name = u"%s forum" % forum_name
  18. Product_page.__init__(
  19. self,
  20. user,
  21. first_notebook,
  22. login_url,
  23. logout_url,
  24. full_forum_name, # note title
  25. Link( rel = u"alternate", type = u"application/rss+xml", title = full_forum_name, href = updates_path ) or None,
  26. P(
  27. H1( full_forum_name ),
  28. ),
  29. Div(
  30. P(
  31. base_path.startswith( u"/forums/" ) and Span(
  32. B( A( u"start a new discussion", href = os.path.join( base_path, u"create_thread" ) ) ),
  33. u" | ",
  34. A( u"all forums", href = u"/forums/" ),
  35. u" | ",
  36. ) or None,
  37. A( u"subscribe to rss", href = updates_path ),
  38. A(
  39. Img( src = u"/static/images/rss.png", width = u"14", height = u"14", class_ = u"middle_image padding_left" ),
  40. href = updates_path,
  41. ),
  42. class_ = u"small_text",
  43. ) or None,
  44. [ Div(
  45. A(
  46. thread.name,
  47. href = ( forum_name == u"blog" ) and \
  48. os.path.join( base_path, thread.friendly_id ) or \
  49. "%s?posts=%s" % ( os.path.join( base_path, thread.object_id ), thread.note_count ),
  50. ),
  51. Span(
  52. self.post_count( thread, forum_name ),
  53. class_ = u"small_text",
  54. )
  55. ) for thread in threads ],
  56. class_ = u"forum_threads",
  57. ),
  58. Page_navigation( base_path, len( threads ), total_thread_count, start, count ),
  59. )
  60. @staticmethod
  61. def post_count( thread, forum_name ):
  62. if forum_name != u"blog":
  63. if thread.note_count > 1:
  64. return u"(%s posts)" % thread.note_count
  65. return None
  66. if thread.note_count == 2:
  67. return u"(1 comment)"
  68. elif thread.note_count > 2:
  69. return u"(%s comments)" % ( thread.note_count - 1 )
  70. return None