47 lignes
1.5 KiB
Python
47 lignes
1.5 KiB
Python
from django.conf import settings
|
|
from django.utils.translation import gettext as _
|
|
|
|
import logging
|
|
import importlib
|
|
|
|
from mycreole import url_upload
|
|
from mycreole import parameter
|
|
from themes import color_icon_url
|
|
|
|
try:
|
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
|
except ImportError:
|
|
ROOT_LOGGER_NAME = 'root'
|
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
|
|
|
NEW_ATTACHMENT_UID = 'new_attachment'
|
|
|
|
|
|
def context_adaption(context, request, title, rel_path, **kwargs):
|
|
context.set_additional_title(title)
|
|
add_bar = parameter.get(parameter.MYCREOLE_BAR)
|
|
next = kwargs.get('next')
|
|
for key in add_bar:
|
|
method = add_bar[key]
|
|
if method is not None:
|
|
if next.find("/", 2) != -1:
|
|
rp = next[next.find("/", 2) + 1:]
|
|
else:
|
|
rp = None
|
|
method(context, request, caller_name="attachments", rel_path=rp)
|
|
add_new(request, context[context.ACTIONBAR], rel_path, kwargs.get('next'))
|
|
for key in kwargs:
|
|
context[key] = kwargs[key]
|
|
logger.debug("context adapted: %s", repr(context))
|
|
|
|
|
|
def add_new(request, bar, rel_path, nxt):
|
|
bar.append_entry(
|
|
NEW_ATTACHMENT_UID, # uid
|
|
_('New Attachment'), # name
|
|
color_icon_url(request, 'plus.png'), # icon
|
|
url_upload(request, rel_path, nxt), # url
|
|
True, # left
|
|
False # active
|
|
)
|