Piki is a minimal wiki
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

context.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import inspect
  2. import logging
  3. from django.utils.translation import gettext as _
  4. from .help import actionbar as actionbar_add_help
  5. import mycreole
  6. import pages
  7. from themes import empty_entry_parameters, gray_icon_url, color_icon_url
  8. from users.context import menubar as menubar_users
  9. try:
  10. from config import APP_NAME as ROOT_LOGGER_NAME
  11. except ImportError:
  12. ROOT_LOGGER_NAME = 'root'
  13. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  14. ATTACHMENT_UID = 'attachment'
  15. BACK_UID = 'back'
  16. HELP_UID = 'help'
  17. def context_adaption(context, request, **kwargs):
  18. caller_name = inspect.currentframe().f_back.f_code.co_name
  19. try:
  20. context.set_additional_title(kwargs.pop('title'))
  21. except KeyError:
  22. pass # no title in kwargs
  23. menubar_users(context[context.MENUBAR], request)
  24. menubar(context, request, caller_name, **kwargs)
  25. actionbar(context, request, caller_name, **kwargs)
  26. navigationbar(context, request, caller_name, **kwargs)
  27. for key in kwargs:
  28. context[key] = kwargs[key]
  29. logger.debug("context adapted: %s", repr(context))
  30. def navigationbar(context, request, caller_name, **kwargs):
  31. bar = context[context.NAVIGATIONBAR]
  32. add_back_menu(request, bar)
  33. # TODO: Add the pages navigation, if source is pages
  34. finalise_bar(request, bar)
  35. def add_back_menu(request, bar):
  36. bar.append_entry(
  37. BACK_UID, # uid
  38. _('Back'), # name
  39. gray_icon_url(request, 'back.png'), # icon
  40. 'javascript:history.back()', # url
  41. True, # left
  42. False # active
  43. )
  44. def menubar(context, request, caller_name, **kwargs):
  45. bar = context[context.MENUBAR]
  46. # replace_profile(request, bar)
  47. add_help_menu(request, bar)
  48. # add_tasklist_menu(request, bar)
  49. # add_filter_submenu(request, bar, VIEW_TASKLIST_UID)
  50. # add_projectlist_menu(request, bar)
  51. # add_printview_menu(request, bar)
  52. finalise_bar(request, bar)
  53. def add_help_menu(request, bar):
  54. bar.append_entry(
  55. HELP_UID, # uid
  56. _('Help'), # name
  57. color_icon_url(request, 'help.png'), # icon
  58. pages.url_helpview(request, 'main'), # url
  59. True, # left
  60. False # active
  61. )
  62. def actionbar(context, request, caller_name, **kwargs):
  63. bar = context[context.ACTIONBAR]
  64. if caller_name == 'pages':
  65. # acc = acc_task(kwargs['task'], request.user)
  66. # if acc.modify or acc.modify_limited:
  67. # add_edittask_menu(request, bar, kwargs['task'].id)
  68. # if acc.add_comments:
  69. # add_newcomment_menu(request, bar, kwargs['task'].id)
  70. add_manageupload_menu(request, bar, kwargs['upload_path'])
  71. elif caller_name == 'helpview':
  72. actionbar_add_help(context, request, **kwargs)
  73. finalise_bar(request, bar)
  74. def add_manageupload_menu(request, bar, upload_path):
  75. bar.append_entry(
  76. ATTACHMENT_UID, # uid
  77. _("Attachments"), # name
  78. color_icon_url(request, 'upload.png'), # icon
  79. mycreole.url_manage_uploads(request, upload_path), # url
  80. True, # left
  81. False, # active
  82. )
  83. def finalise_bar(request, bar):
  84. if len(bar) == 0:
  85. bar.append_entry(*empty_entry_parameters(request))
  86. """from .access import create_project_possible, create_task_possible, acc_task
  87. from django.db.models.functions import Lower
  88. import patt
  89. from .search import common_searches
  90. from themes import empty_entry_parameters, color_icon_url, gray_icon_url
  91. from users.context import PROFILE_ENTRY_UID
  92. COMMENTNEW_UID = 'commentnew'
  93. CREATE_PROJECT_UID = 'create-project'
  94. CREATE_TASK_UID = 'create-task'
  95. PRINTVIEW_UID = 'printview'
  96. TASKEDIT_UID = 'taskedit'
  97. VIEW_PROJECTLIST_UID = 'view-projectlist'
  98. VIEW_TASKLIST_UID = 'view-tasklist'
  99. def replace_profile(request, bar):
  100. try:
  101. bar.replace_entry(
  102. PROFILE_ENTRY_UID,
  103. PROFILE_ENTRY_UID, # uid
  104. request.user.username, # name
  105. color_icon_url(request, 'user.png'), # icon
  106. patt.url_profile(request), # url
  107. False, # left
  108. False # active
  109. )
  110. except ValueError:
  111. pass # Profile entry does not exist, so exchange is not needed (e.g. no user is logged in)
  112. def add_tasklist_menu(request, bar):
  113. bar.append_entry(
  114. VIEW_TASKLIST_UID, # uid
  115. _('Tasklist'), # name
  116. color_icon_url(request, 'task.png'), # icon
  117. patt.url_tasklist(request), # url
  118. True, # left
  119. patt.is_tasklistview(request) # active
  120. )
  121. def add_projectlist_menu(request, bar):
  122. bar.append_entry(
  123. VIEW_PROJECTLIST_UID, # uid
  124. _('Projectlist'), # name
  125. color_icon_url(request, 'folder.png'), # icon
  126. patt.url_projectlist(request), # url
  127. True, # left
  128. patt.is_projectlistview(request) # active
  129. )
  130. def add_printview_menu(request, bar):
  131. bar.append_entry(
  132. PRINTVIEW_UID, # uid
  133. _('Printview'), # name
  134. color_icon_url(request, 'print.png'), # icon
  135. patt.url_printview(request), # url
  136. True, # left
  137. patt.is_printview(request) # active
  138. )
  139. def add_newtask_menu(request, bar, project_id):
  140. bar.append_entry(
  141. CREATE_TASK_UID, # uid
  142. _('New Task'), # name
  143. color_icon_url(request, 'plus.png'), # icon
  144. patt.url_tasknew(request, project_id), # url
  145. True, # left
  146. False # active
  147. )
  148. def add_edittask_menu(request, bar, task_id):
  149. bar.append_entry(
  150. TASKEDIT_UID, # uid
  151. _('Edit'), # name
  152. color_icon_url(request, 'edit.png'), # icon
  153. patt.url_taskedit(request, task_id), # url
  154. True, # left
  155. False # active
  156. )
  157. def add_newcomment_menu(request, bar, task_id):
  158. bar.append_entry(
  159. COMMENTNEW_UID, # uid
  160. _('Add Comment'), # name
  161. color_icon_url(request, 'edit2.png'), # icon
  162. patt.url_commentnew(request, task_id), # url
  163. True, # left
  164. False # active
  165. )
  166. def add_newproject_menu(request, bar):
  167. bar.append_entry(
  168. CREATE_PROJECT_UID, # uid
  169. _('New Project'), # name
  170. color_icon_url(request, 'plus.png'), # icon
  171. patt.url_projectnew(request), # url
  172. True, # left
  173. False # active
  174. )
  175. def add_filter_submenu(request, bar, menu_uid):
  176. bar.append_entry_to_entry(
  177. menu_uid,
  178. menu_uid + '-easysearch', # uid
  179. _('Easysearch'), # name
  180. gray_icon_url(request, 'search.png'), # icon
  181. patt.url_easysearch(request), # url
  182. True, # left
  183. False # active
  184. )
  185. if patt.get_search_query(request) is not None:
  186. bar.append_entry_to_entry(
  187. menu_uid,
  188. menu_uid + '-save', # uid
  189. _('Save Search as Filter'), # name
  190. gray_icon_url(request, 'save.png'), # icon
  191. patt.url_filteredit(request), # url
  192. True, # left
  193. False # active
  194. )
  195. bar.append_entry_to_entry(
  196. menu_uid,
  197. menu_uid + '-all', # uid
  198. _('All Tasks'), # name
  199. gray_icon_url(request, 'task.png'), # icon
  200. patt.url_tasklist(request), # url
  201. True, # left
  202. False # active
  203. )
  204. cs = common_searches(request)
  205. for common_filter_id in cs:
  206. bar.append_entry_to_entry(
  207. menu_uid,
  208. menu_uid + '-common', # uid
  209. _(cs[common_filter_id][0]), # name
  210. gray_icon_url(request, 'filter.png'), # icon
  211. patt.url_tasklist(request, common_filter_id=common_filter_id), # url
  212. True, # left
  213. False # active
  214. )
  215. for s in request.user.search_set.order_by(Lower('name')):
  216. active = patt.is_tasklistview(request, s.id)
  217. if active is True:
  218. url = patt.url_filteredit(request, s.id)
  219. else:
  220. url = patt.url_tasklist(request, user_filter_id=s.id)
  221. if active:
  222. icon = 'settings.png'
  223. else:
  224. icon = 'favourite.png'
  225. bar.append_entry_to_entry(
  226. menu_uid,
  227. menu_uid + '-sub', # uid
  228. s.name, # name
  229. gray_icon_url(request, icon), # icon
  230. url, # url
  231. True, # left
  232. active # active
  233. )
  234. """