Django Library Mycreole
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

context.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.conf import settings
  2. from django.utils.translation import gettext as _
  3. import logging
  4. import importlib
  5. from mycreole import url_upload
  6. from mycreole import parameter
  7. from themes import color_icon_url
  8. try:
  9. from config import APP_NAME as ROOT_LOGGER_NAME
  10. except ImportError:
  11. ROOT_LOGGER_NAME = 'root'
  12. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  13. NEW_ATTACHMENT_UID = 'new_attachment'
  14. def context_adaption(context, request, title, rel_path, **kwargs):
  15. context.set_additional_title(title)
  16. add_bar = parameter.get(parameter.MYCREOLE_BAR)
  17. next = kwargs.get('next')
  18. for key in add_bar:
  19. method = add_bar[key]
  20. if method is not None:
  21. if next.find("/", 2) != -1:
  22. rp = next[next.find("/", 2) + 1:]
  23. else:
  24. rp = None
  25. method(context, request, caller_name="attachments", rel_path=rp)
  26. add_new(request, context[context.ACTIONBAR], rel_path, kwargs.get('next'))
  27. for key in kwargs:
  28. context[key] = kwargs[key]
  29. logger.debug("context adapted: %s", repr(context))
  30. def add_new(request, bar, rel_path, nxt):
  31. bar.append_entry(
  32. NEW_ATTACHMENT_UID, # uid
  33. _('New Attachment'), # name
  34. color_icon_url(request, 'plus.png'), # icon
  35. url_upload(request, rel_path, nxt), # url
  36. True, # left
  37. False # active
  38. )