Django Library PaTT
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

context.py 9.5KB

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