Personal wiki notebook (not under development)

Link_area.py 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. from Tags import Div, P, Span, H4, A, Strong, Img, Br, Input
  2. from Rounded_div import Rounded_div
  3. from model.Notebook import Notebook
  4. class Link_area( Div ):
  5. def __init__( self, toolbar, notebooks, notebook, parent_id, notebook_path, updates_path, user, rate_plan ):
  6. linked_notebooks = [ nb for nb in notebooks if
  7. (
  8. nb.read_write == Notebook.READ_WRITE or
  9. ( nb.read_write == Notebook.READ_ONLY and not nb.name.startswith( u"Luminotes" ) )
  10. ) and
  11. nb.name not in ( u"trash" ) and
  12. nb.deleted is False
  13. ]
  14. if [ tag for tag in notebook.tags if tag.name == u"forum" ]:
  15. forum_tag = True
  16. forum_name = tag.value
  17. notebook_word = u"discussion"
  18. note_word = u"post"
  19. else:
  20. forum_tag = False
  21. forum_name = None
  22. notebook_word = u"notebook"
  23. note_word = u"note"
  24. Div.__init__(
  25. self,
  26. toolbar,
  27. ( user.username == u"anonymous" ) and self.forum_link( forum_tag, forum_name ) or None,
  28. ( user.username != u"anonymous" ) and Div(
  29. ( notebook_path != u"/" ) and Div(
  30. H4(
  31. u"this %s" % notebook_word,
  32. id = u"this_notebook_area_title",
  33. ),
  34. self.forum_link( forum_tag, forum_name ),
  35. ( rate_plan.get( u"notebook_sharing" ) and notebook.name == u"Luminotes blog" ) and Div(
  36. A(
  37. u"follow",
  38. href = u"%s?rss" % notebook_path,
  39. id = u"blog_rss_link",
  40. title = u"Subscribe to the RSS feed for the Luminotes blog.",
  41. ),
  42. A(
  43. Img( src = u"/static/images/rss.png", width = u"14", height = u"14", class_ = u"middle_image padding_left" ),
  44. href = u"%s?rss" % notebook_path,
  45. title = u"Subscribe to the RSS feed for the Luminotes blog.",
  46. ),
  47. class_ = u"link_area_item",
  48. ) or ( updates_path and rate_plan.get( u"notebook_sharing" ) and ( not forum_tag ) and Div(
  49. A(
  50. u"follow",
  51. href = updates_path,
  52. id = u"notebook_rss_link",
  53. title = u"Subscribe to the RSS feed for this %s." % notebook_word,
  54. ),
  55. A(
  56. Img( src = u"/static/images/rss.png", width = u"14", height = u"14", class_ = u"middle_image padding_left" ),
  57. href = updates_path,
  58. title = u"Subscribe to the RSS feed for this %s." % notebook_word,
  59. ),
  60. class_ = u"link_area_item",
  61. ) or None ),
  62. ( notebook.read_write != Notebook.READ_ONLY ) and Div(
  63. A(
  64. u"nothing but %ss" % note_word,
  65. href = u"#",
  66. id = u"declutter_link",
  67. title = u"Focus on just your %ss without any distractions." % note_word,
  68. ),
  69. class_ = u"link_area_item",
  70. ) or None,
  71. ( notebook.read_write != Notebook.READ_WRITE and notebook.name != u"Luminotes" ) and Div(
  72. A(
  73. u"export",
  74. href = u"#",
  75. id = u"export_link",
  76. title = u"Download a stand-alone copy of the entire %s." % notebook_word,
  77. ),
  78. class_ = u"link_area_item",
  79. ) or None,
  80. ( notebook.read_write != Notebook.READ_WRITE ) and Div(
  81. A(
  82. u"print",
  83. href = u"/notebooks/export?notebook_id=%s&format=print" % notebook.object_id,
  84. id = u"print_notebook_link",
  85. target = u"_new",
  86. title = u"Print this %s." % notebook_word,
  87. ),
  88. class_ = u"link_area_item",
  89. ) or None,
  90. ( notebook.read_write == Notebook.READ_WRITE ) and Span(
  91. Div(
  92. ( notebook.name != u"trash" ) and A(
  93. u"import",
  94. href = u"#",
  95. id = u"import_link",
  96. title = u"Import %ss from other software into Luminotes." % note_word,
  97. ) or None,
  98. ( notebook.name != u"trash" ) and u"|" or None,
  99. A(
  100. u"export",
  101. href = u"#",
  102. id = u"export_link",
  103. title = u"Download a stand-alone copy of the entire %s." % notebook_word,
  104. ),
  105. class_ = u"link_area_item",
  106. ) or None,
  107. ( notebook.name != u"trash" ) and Div(
  108. notebook.trash_id and A(
  109. u"trash",
  110. href = u"/notebooks/%s?parent_id=%s" % ( notebook.trash_id, notebook.object_id ),
  111. id = u"trash_link",
  112. title = u"Look here for %ss you've deleted." % note_word,
  113. ) or None,
  114. ( notebook.owner and notebook.name != u"trash" and notebook.trash_id ) and u"|" or None,
  115. ( notebook.owner and notebook.name != u"trash" ) and A(
  116. u"delete",
  117. href = u"#",
  118. id = u"delete_notebook_link",
  119. title = u"Move this %s to the trash." % notebook_word,
  120. ) or None,
  121. class_ = u"link_area_item",
  122. ) or None,
  123. ( notebook.owner and notebook.name != u"trash" ) and Div(
  124. A(
  125. u"rename",
  126. href = u"#",
  127. id = u"rename_notebook_link",
  128. title = u"Change the name of this %s." % notebook_word,
  129. ),
  130. class_ = u"link_area_item",
  131. ) or None,
  132. ( notebook.owner and notebook.name != u"trash" and
  133. user.username and rate_plan.get( u"notebook_sharing" ) ) and Div(
  134. A(
  135. u"share",
  136. href = u"#",
  137. id = u"share_notebook_link",
  138. title = u"Share this %s with others." % notebook_word,
  139. ),
  140. class_ = u"link_area_item",
  141. ) or None,
  142. Div(
  143. A(
  144. u"print",
  145. href = u"/notebooks/export?notebook_id=%s&format=print" % notebook.object_id,
  146. id = u"print_notebook_link",
  147. target = u"_new",
  148. title = u"Print this %s." % notebook_word,
  149. ),
  150. class_ = u"link_area_item",
  151. ) or None,
  152. ( notebook.name == u"trash" ) and Rounded_div(
  153. u"trash_notebook",
  154. A(
  155. u"trash",
  156. href = u"#",
  157. id = u"trash_link",
  158. title = u"Look here for %ss you've deleted." % note_word,
  159. ),
  160. class_ = u"link_area_item",
  161. ) or None,
  162. ) or None,
  163. id = u"this_notebook_area",
  164. ) or None,
  165. ( not forum_tag ) and Div(
  166. ( len( linked_notebooks ) > 0 ) and H4(
  167. u"notebooks",
  168. id = u"notebooks_area_title",
  169. ) or None,
  170. [ ( nb.object_id == notebook.object_id ) and Rounded_div(
  171. u"current_notebook",
  172. A(
  173. nb.name,
  174. href = u"/notebooks/%s" % nb.object_id,
  175. id = u"notebook_%s" % nb.object_id,
  176. ),
  177. ( len( linked_notebooks ) > 1 ) and Span(
  178. Img( src = u"/static/images/up_arrow.png", width = u"20", height = u"17", id = u"current_notebook_up" ),
  179. Img( src = u"/static/images/down_arrow.png", width = u"20", height = u"17", id = u"current_notebook_down" ),
  180. Span( id = "current_notebook_up_hover_preload" ),
  181. Span( id = "current_notebook_down_hover_preload" ),
  182. ) or None,
  183. class_ = u"link_area_item",
  184. ) or
  185. Div(
  186. A(
  187. nb.name,
  188. href = u"/notebooks/%s" % nb.object_id,
  189. id = u"notebook_%s" % nb.object_id,
  190. ),
  191. class_ = u"link_area_item",
  192. ) for nb in linked_notebooks ],
  193. id = u"notebooks_area"
  194. ) or None,
  195. ( not forum_tag ) and Div(
  196. Input(
  197. type = u"button",
  198. class_ = u"note_button",
  199. id = u"new_notebook_button",
  200. value = u"+ notebook",
  201. title = u"Create a new wiki notebook.",
  202. ),
  203. class_ = u"link_area_item",
  204. ) or None,
  205. Div(
  206. id = u"storage_usage_area",
  207. ),
  208. id = u"link_area_holder",
  209. ) or None,
  210. id = u"link_area",
  211. )
  212. @staticmethod
  213. def forum_link( forum_tag, forum_name ):
  214. if not forum_tag:
  215. return None
  216. if forum_name == u"blog":
  217. return Div(
  218. A( u"Luminotes %s" % forum_name, href = "/blog/" ),
  219. class_ = u"link_area_item",
  220. )
  221. return Div(
  222. A( u"%s forum" % forum_name, href = "/forums/%s" % forum_name ),
  223. class_ = u"link_area_item",
  224. )