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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. from .access import create_project_possible, create_task_possible, acc_task
  2. from django.conf import settings
  3. from django.db.models.functions import Lower
  4. from django.utils.translation import gettext as _
  5. from .help import actionbar as actionbar_add_help
  6. import inspect
  7. import logging
  8. import mycreole
  9. import patt
  10. from .search import common_searches
  11. from themes import empty_entry_parameters, color_icon_url, gray_icon_url
  12. from users.context import menubar as menubar_users
  13. from users.context import PROFILE_ENTRY_UID
  14. logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
  15. ATTACHMENT_UID = 'attachment'
  16. BACK_UID = 'back'
  17. COMMENTNEW_UID = 'commentnew'
  18. CREATE_PROJECT_UID = 'create-project'
  19. CREATE_TASK_UID = 'create-task'
  20. HELP_UID = 'help'
  21. PRINTVIEW_UID = 'printview'
  22. TASKEDIT_UID = 'taskedit'
  23. VIEW_PROJECTLIST_UID = 'view-projectlist'
  24. VIEW_TASKLIST_UID = 'view-tasklist'
  25. def context_adaption(context, request, **kwargs):
  26. caller_name = inspect.currentframe().f_back.f_code.co_name
  27. try:
  28. context.set_additional_title(kwargs.pop('title'))
  29. except KeyError:
  30. pass # no title in kwargs
  31. menubar(context, request, caller_name, **kwargs)
  32. actionbar(context, request, caller_name, **kwargs)
  33. navigationbar(context, request, caller_name, **kwargs)
  34. for key in kwargs:
  35. context[key] = kwargs[key]
  36. logger.debug("context adapted: %s", repr(context))
  37. def navigationbar(context, request, caller_name, **kwargs):
  38. bar = context[context.NAVIGATIONBAR]
  39. add_back_menu(request, bar)
  40. finalise_bar(request, bar)
  41. def menubar(context, request, caller_name, **kwargs):
  42. bar = context[context.MENUBAR]
  43. menubar_users(bar, request)
  44. replace_profile(request, bar)
  45. add_help_menu(request, bar)
  46. add_tasklist_menu(request, bar)
  47. add_filter_submenu(request, bar, VIEW_TASKLIST_UID)
  48. add_projectlist_menu(request, bar)
  49. add_printview_menu(request, bar)
  50. finalise_bar(request, bar)
  51. def actionbar(context, request, caller_name, **kwargs):
  52. bar = context[context.ACTIONBAR]
  53. if caller_name == 'patt_tasklist':
  54. if create_task_possible(request.user):
  55. add_newtask_menu(request, bar, kwargs.get('project_id'))
  56. elif caller_name == 'patt_projectlist':
  57. if create_project_possible(request.user):
  58. add_newproject_menu(request, bar)
  59. elif caller_name == 'patt_taskview':
  60. acc = acc_task(kwargs['task'], request.user)
  61. if acc.modify or acc.modify_limited:
  62. add_edittask_menu(request, bar, kwargs['task'].id)
  63. if acc.add_comments:
  64. add_newcomment_menu(request, bar, kwargs['task'].id)
  65. add_manageupload_menu(request, bar, kwargs['task'])
  66. elif caller_name == 'patt_helpview':
  67. actionbar_add_help(context, request, **kwargs)
  68. finalise_bar(request, bar)
  69. def finalise_bar(request, bar):
  70. if len(bar) == 0:
  71. bar.append_entry(*empty_entry_parameters(request))
  72. def replace_profile(request, bar):
  73. try:
  74. bar.replace_entry(
  75. PROFILE_ENTRY_UID,
  76. PROFILE_ENTRY_UID, # uid
  77. request.user.username, # name
  78. color_icon_url(request, 'user.png'), # icon
  79. patt.url_profile(request), # url
  80. False, # left
  81. False # active
  82. )
  83. except ValueError:
  84. pass # Profile entry does not exist, so exchange is not needed (e.g. no user is logged in)
  85. def add_help_menu(request, bar):
  86. bar.append_entry(
  87. HELP_UID, # uid
  88. _('Help'), # name
  89. color_icon_url(request, 'help.png'), # icon
  90. patt.url_helpview(request, 'main'), # url
  91. True, # left
  92. False # active
  93. )
  94. def add_tasklist_menu(request, bar):
  95. bar.append_entry(
  96. VIEW_TASKLIST_UID, # uid
  97. _('Tasklist'), # name
  98. color_icon_url(request, 'task.png'), # icon
  99. patt.url_tasklist(request), # url
  100. True, # left
  101. patt.is_tasklistview(request) # active
  102. )
  103. def add_projectlist_menu(request, bar):
  104. bar.append_entry(
  105. VIEW_PROJECTLIST_UID, # uid
  106. _('Projectlist'), # name
  107. color_icon_url(request, 'folder.png'), # icon
  108. patt.url_projectlist(request), # url
  109. True, # left
  110. patt.is_projectlistview(request) # active
  111. )
  112. def add_printview_menu(request, bar):
  113. bar.append_entry(
  114. PRINTVIEW_UID, # uid
  115. _('Printview'), # name
  116. color_icon_url(request, 'print.png'), # icon
  117. patt.url_printview(request), # url
  118. True, # left
  119. patt.is_printview(request) # active
  120. )
  121. def add_newtask_menu(request, bar, project_id):
  122. bar.append_entry(
  123. CREATE_TASK_UID, # uid
  124. _('New Task'), # name
  125. color_icon_url(request, 'plus.png'), # icon
  126. patt.url_tasknew(request, project_id), # url
  127. True, # left
  128. False # active
  129. )
  130. def add_edittask_menu(request, bar, task_id):
  131. bar.append_entry(
  132. TASKEDIT_UID, # uid
  133. _('Edit'), # name
  134. color_icon_url(request, 'edit.png'), # icon
  135. patt.url_taskedit(request, task_id), # url
  136. True, # left
  137. False # active
  138. )
  139. def add_newcomment_menu(request, bar, task_id):
  140. bar.append_entry(
  141. COMMENTNEW_UID, # uid
  142. _('Add Comment'), # name
  143. color_icon_url(request, 'edit2.png'), # icon
  144. patt.url_commentnew(request, task_id), # url
  145. True, # left
  146. False # active
  147. )
  148. def add_newproject_menu(request, bar):
  149. bar.append_entry(
  150. CREATE_PROJECT_UID, # uid
  151. _('New Project'), # name
  152. color_icon_url(request, 'plus.png'), # icon
  153. patt.url_projectnew(request), # url
  154. True, # left
  155. False # active
  156. )
  157. def add_manageupload_menu(request, bar, task):
  158. bar.append_entry(
  159. ATTACHMENT_UID, # uid
  160. _("Attachments"), # name
  161. color_icon_url(request, 'upload.png'), # icon
  162. mycreole.url_manage_uploads(request, task.attachment_target_path), # url
  163. True, # left
  164. False, # active
  165. )
  166. def add_back_menu(request, bar):
  167. bar.append_entry(
  168. BACK_UID, # uid
  169. _('Back'), # name
  170. gray_icon_url(request, 'back.png'), # icon
  171. 'javascript:history.back()', # 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. )