Piki is a minimal wiki
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import inspect
  2. import logging
  3. import os
  4. from django.utils.translation import gettext as _
  5. from pages import access
  6. from .help import actionbar as actionbar_add_help
  7. import mycreole
  8. import pages
  9. from themes import empty_entry_parameters, gray_icon_url, color_icon_url
  10. from users.context import menubar as menubar_users
  11. try:
  12. from config import APP_NAME as ROOT_LOGGER_NAME
  13. except ImportError:
  14. ROOT_LOGGER_NAME = 'root'
  15. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  16. ATTACHMENT_UID = 'attachment'
  17. BACK_UID = 'back'
  18. EDIT_UID = 'edit'
  19. HELP_UID = 'help'
  20. NAVIGATION_ENTRY_UID = 'navigation-%s'
  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(context, request, caller_name, **kwargs)
  28. actionbar(context, request, caller_name, **kwargs)
  29. navigationbar(context, request, caller_name, **kwargs)
  30. for key in kwargs:
  31. context[key] = kwargs[key]
  32. logger.debug("context adapted: %s", repr(context))
  33. def navigationbar(context, request, caller_name, **kwargs):
  34. bar = context[context.NAVIGATIONBAR]
  35. if caller_name == "mycreole-attachments":
  36. next = kwargs.get("next")
  37. if next.count("/") >= 2:
  38. path = next[next.find("/", 2) + 1:]
  39. else:
  40. path = ""
  41. else:
  42. path = kwargs.get("rel_path", "")
  43. while len(path) > 0 and path != os.path.sep:
  44. bar.append_entry(*navigation_entry_parameters(request, path))
  45. path = os.path.dirname(path)
  46. add_back_menu(request, bar)
  47. finalise_bar(request, bar)
  48. def add_back_menu(request, bar):
  49. bar.append_entry(
  50. BACK_UID, # uid
  51. _('Back'), # name
  52. gray_icon_url(request, 'back.png'), # icon
  53. 'javascript:history.back()', # url
  54. True, # left
  55. False # active
  56. )
  57. def navigation_entry_parameters(request, path):
  58. return (
  59. NAVIGATION_ENTRY_UID % os.path.basename(path), # uid
  60. '/' + os.path.basename(path), # name
  61. None, # icon
  62. pages.url_page(request, path), # url
  63. False, # left
  64. False # active
  65. )
  66. def menubar(context, request, caller_name, **kwargs):
  67. bar = context[context.MENUBAR]
  68. menubar_users(bar, request)
  69. add_help_menu(request, bar)
  70. finalise_bar(request, bar)
  71. def add_help_menu(request, bar):
  72. bar.append_entry(
  73. HELP_UID, # uid
  74. _('Help'), # name
  75. color_icon_url(request, 'help.png'), # icon
  76. pages.url_helpview(request, 'main'), # url
  77. True, # left
  78. False # active
  79. )
  80. def actionbar(context, request, caller_name, **kwargs):
  81. bar = context[context.ACTIONBAR]
  82. if caller_name == 'page':
  83. if access.write_page(request, kwargs["rel_path"]):
  84. add_edit_menu(request, bar, kwargs["rel_path"])
  85. if access.modify_attachment(request, kwargs["rel_path"]):
  86. add_manageupload_menu(request, bar, kwargs['upload_path'])
  87. elif caller_name == 'helpview':
  88. actionbar_add_help(context, request, **kwargs)
  89. finalise_bar(request, bar)
  90. def add_edit_menu(request, bar, rel_path):
  91. bar.append_entry(
  92. EDIT_UID, # uid
  93. _('Edit'), # name
  94. color_icon_url(request, 'edit.png'), # icon
  95. pages.url_edit(request, rel_path), # url
  96. True, # left
  97. False # active
  98. )
  99. def add_manageupload_menu(request, bar, upload_path):
  100. bar.append_entry(
  101. ATTACHMENT_UID, # uid
  102. _("Attachments"), # name
  103. color_icon_url(request, 'upload.png'), # icon
  104. mycreole.url_manage_uploads(request, upload_path), # url
  105. True, # left
  106. False, # active
  107. )
  108. def finalise_bar(request, bar):
  109. if len(bar) == 0:
  110. bar.append_entry(*empty_entry_parameters(request))