Piki is a minimal wiki
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

context.py 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import inspect
  2. import logging
  3. from django.utils.translation import gettext as _
  4. from pages import access
  5. from .help import actionbar as actionbar_add_help
  6. import mycreole
  7. import pages
  8. from themes import empty_entry_parameters, gray_icon_url, color_icon_url
  9. from users.context import menubar as menubar_users
  10. try:
  11. from config import APP_NAME as ROOT_LOGGER_NAME
  12. except ImportError:
  13. ROOT_LOGGER_NAME = 'root'
  14. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  15. ATTACHMENT_UID = 'attachment'
  16. BACK_UID = 'back'
  17. EDIT_UID = 'edit'
  18. HELP_UID = 'help'
  19. def context_adaption(context, request, **kwargs):
  20. caller_name = inspect.currentframe().f_back.f_code.co_name
  21. try:
  22. context.set_additional_title(kwargs.pop('title'))
  23. except KeyError:
  24. pass # no title in kwargs
  25. menubar_users(context[context.MENUBAR], request)
  26. menubar(context, request, caller_name, **kwargs)
  27. actionbar(context, request, caller_name, **kwargs)
  28. navigationbar(context, request, caller_name, **kwargs)
  29. for key in kwargs:
  30. context[key] = kwargs[key]
  31. logger.debug("context adapted: %s", repr(context))
  32. def navigationbar(context, request, caller_name, **kwargs):
  33. bar = context[context.NAVIGATIONBAR]
  34. add_back_menu(request, bar)
  35. # TODO: Add the pages navigation, if source is pages
  36. finalise_bar(request, bar)
  37. def add_back_menu(request, bar):
  38. bar.append_entry(
  39. BACK_UID, # uid
  40. _('Back'), # name
  41. gray_icon_url(request, 'back.png'), # icon
  42. 'javascript:history.back()', # url
  43. True, # left
  44. False # active
  45. )
  46. def menubar(context, request, caller_name, **kwargs):
  47. bar = context[context.MENUBAR]
  48. add_help_menu(request, bar)
  49. finalise_bar(request, bar)
  50. def add_help_menu(request, bar):
  51. bar.append_entry(
  52. HELP_UID, # uid
  53. _('Help'), # name
  54. color_icon_url(request, 'help.png'), # icon
  55. pages.url_helpview(request, 'main'), # url
  56. True, # left
  57. False # active
  58. )
  59. def actionbar(context, request, caller_name, **kwargs):
  60. bar = context[context.ACTIONBAR]
  61. if caller_name == 'page':
  62. if access.write_page(request, kwargs["rel_path"]):
  63. add_edit_menu(request, bar, kwargs["rel_path"])
  64. if access.modify_attachment(request, kwargs["rel_path"]):
  65. add_manageupload_menu(request, bar, kwargs['upload_path'])
  66. elif caller_name == 'helpview':
  67. actionbar_add_help(context, request, **kwargs)
  68. finalise_bar(request, bar)
  69. def add_edit_menu(request, bar, rel_path):
  70. bar.append_entry(
  71. EDIT_UID, # uid
  72. _('Edit'), # name
  73. color_icon_url(request, 'edit.png'), # icon
  74. pages.url_edit(request, rel_path), # url
  75. True, # left
  76. False # active
  77. )
  78. def add_manageupload_menu(request, bar, upload_path):
  79. bar.append_entry(
  80. ATTACHMENT_UID, # uid
  81. _("Attachments"), # name
  82. color_icon_url(request, 'upload.png'), # icon
  83. mycreole.url_manage_uploads(request, upload_path), # url
  84. True, # left
  85. False, # active
  86. )
  87. def finalise_bar(request, bar):
  88. if len(bar) == 0:
  89. bar.append_entry(*empty_entry_parameters(request))