Django Library Mycreole
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.utils.translation import gettext as _
  2. import logging
  3. from mycreole import url_upload
  4. from users.context import menubar as user_menubar
  5. from patt.context import navigationbar
  6. from themes import color_icon_url
  7. try:
  8. from config import APP_NAME as ROOT_LOGGER_NAME
  9. except ImportError:
  10. ROOT_LOGGER_NAME = 'root'
  11. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  12. NEW_ATTACHMENT_UID = 'new_attachment'
  13. def context_adaption(context, request, title, rel_path, **kwargs):
  14. context.set_additional_title(title)
  15. user_menubar(context[context.MENUBAR], request)
  16. navigationbar(context, request)
  17. add_new(request, context[context.ACTIONBAR], rel_path, kwargs.get('next'))
  18. for key in kwargs:
  19. context[key] = kwargs[key]
  20. logger.debug("context adapted: %s", repr(context))
  21. def add_new(request, bar, rel_path, nxt):
  22. bar.append_entry(
  23. NEW_ATTACHMENT_UID, # uid
  24. _('New Attachment'), # name
  25. color_icon_url(request, 'plus.png'), # icon
  26. url_upload(request, rel_path, nxt), # url
  27. True, # left
  28. False # active
  29. )