Exemplo n.º 1
0
def render_wirecloud(request, view_type=None):

    if view_type is None:
        if 'mode' in request.GET:
            view_type = request.GET['mode']
        else:
            view_type = get_default_view(request)

    theme = request.GET.get('theme', get_active_theme_name())
    if theme not in get_available_themes():
        return remove_query_parameter(request, 'theme')

    try:

        template = get_template(theme + ':wirecloud/views/%s.html' % view_type)

    except TemplateDoesNotExist:

        if 'mode' in request.GET:
            return remove_query_parameter(request, 'mode')
        else:
            view_type = get_default_view(request)
            return render_wirecloud(request, view_type)

    context = {
        'THEME': theme,
        'VIEW_MODE': view_type,
        'WIRECLOUD_VERSION_HASH': get_version_hash()
    }
    content = template.render(RequestContext(request, context))
    return HttpResponse(content, content_type="application/xhtml+xml; charset=UTF-8")
Exemplo n.º 2
0
def render_wirecloud(request, view_type=None):

    if view_type is None:
        if 'mode' in request.GET:
            view_type = request.GET['mode']
        else:
            view_type = get_default_view(request)

    theme = request.GET.get('theme', get_active_theme_name())
    if theme not in get_available_themes():
        return remove_query_parameter(request, 'theme')

    context = {
        'THEME': theme,
        'VIEW_MODE': view_type,
        'WIRECLOUD_VERSION_HASH': get_version_hash()
    }

    try:

        return render(request,
                      theme + ':wirecloud/views/%s.html' % view_type,
                      context=context,
                      content_type="application/xhtml+xml; charset=UTF-8")

    except TemplateDoesNotExist:

        if 'mode' in request.GET:
            return remove_query_parameter(request, 'mode')
        else:
            view_type = get_default_view(request)
            return render_wirecloud(request, view_type)
Exemplo n.º 3
0
def wirecloud_bootstrap(context, view):

    current_theme = context.get('THEME', get_active_theme_name())
    available_themes = [{"value": theme.name, "label": theme.label} for theme in get_available_themes(metadata=True)]

    endpoints = get_wirecloud_ajax_endpoints(view)
    script = 'Wirecloud.URLs = {\n'
    for endpoint in endpoints:
        script += '    "' + endpoint['id'] + '": '
        if '%(' in endpoint['url']:
            script += "new Wirecloud.Utils.Template('" + endpoint['url'] + "'),\n"
        else:
            script += "'" + endpoint['url'] + "',\n"

    script += '};'

    constants_def = get_constants()
    constants = []
    for constant in constants_def:
        constants.append({'key': constant['key'], 'value': mark_safe(constant['value'])})
    constants.append({'key': 'CURRENT_MODE', 'value': mark_safe('"' + view + '"')})
    constants.append({'key': 'CURRENT_THEME', 'value': mark_safe('"' + current_theme + '"')})
    constants.append({'key': 'AVAILABLE_THEMES', 'value': mark_safe(json.dumps(available_themes, cls=LazyEncoder))})

    return {
        'script': mark_safe(script),
        'constants': constants,
    }
Exemplo n.º 4
0
def render_wirecloud(request, view_type=None, title=None, description=None):

    if view_type is None:
        if 'mode' in request.GET:
            view_type = request.GET['mode']
        else:
            view_type = get_default_view(request)

    theme = request.GET.get('theme', get_active_theme_name())
    if theme not in get_available_themes():
        return remove_query_parameter(request, 'theme')

    context = {
        'title': title,
        'description': description,
        'THEME': theme,
        'VIEW_MODE': view_type,
        'WIRECLOUD_VERSION_HASH': get_version_hash()
    }

    try:

        return render(request, theme + ':wirecloud/views/%s.html' % view_type, context=context, content_type="application/xhtml+xml; charset=UTF-8")

    except TemplateDoesNotExist:

        if 'mode' in request.GET:
            return remove_query_parameter(request, 'mode')
        else:
            view_type = get_default_view(request)
            return render_wirecloud(request, view_type, title, description)
Exemplo n.º 5
0
def cached_javascript_catalog(request):

    language = request.GET.get(LANGUAGE_QUERY_PARAMETER)
    if not (language and check_for_language(language)):
        language = get_language()
    locale = to_locale(language)

    packages = ['wirecloud.commons', 'wirecloud.catalogue', 'wirecloud.platform']

    for plugin in get_plugins():
        packages.append(plugin.__module__.rsplit('.', 1)[0])

    for theme in get_available_themes():
        packages.append(theme)

    catalog, plural = get_javascript_catalog(locale, 'djangojs', packages)
    return render_javascript_catalog(catalog, plural)
Exemplo n.º 6
0
def cached_javascript_catalog(request):

    language = request.GET.get(LANGUAGE_QUERY_PARAMETER)
    if not (language and check_for_language(language)):
        language = get_language()
    locale = to_locale(language)

    packages = ['wirecloud.commons', 'wirecloud.catalogue', 'wirecloud.platform']

    for plugin in get_plugins():
        packages.append(plugin.__module__.rsplit('.', 1)[0])

    for theme in get_available_themes():
        packages.append(theme)

    catalog, plural = get_javascript_catalog(locale, 'djangojs', packages)
    return render_javascript_catalog(catalog, plural)
Exemplo n.º 7
0
from wirecloud.platform.core.models import *
from wirecloud.platform.context.models import *
from wirecloud.platform.iwidget.models import *
from wirecloud.platform.markets.models import *
from wirecloud.platform.preferences.models import *
from wirecloud.platform.widget.models import *
from wirecloud.platform.wiring.models import *
from wirecloud.platform.workspace.models import *

# TODO search a better way of implementing this

# Currently, Django doesn't support using translation catalogues from external
# modules, so we have to add the theme translation paths to the LOCALE_PATHS
# setting

from django.conf import settings
from wirecloud.platform.themes import get_available_themes, get_theme_dir, get_theme_metadata

if type(settings.LOCALE_PATHS) != list:
    settings.LOCALE_PATHS = list(settings.LOCALE_PATHS)

for theme in get_available_themes():
    theme_dir = get_theme_dir(get_theme_metadata(theme), 'locale')
    if theme_dir not in settings.LOCALE_PATHS:
        settings.LOCALE_PATHS.insert(0, theme_dir)