Esempio n. 1
0
def render_theming_css():
    """
    Template tag that renders the needed css files for the theming app.
    """
    css = getattr(settings, 'ADMIN_TOOLS_THEMING_CSS', False)
    if css:
        css = '/'.join([get_media_url(), css])
    else:
        css = '/'.join([get_media_url(), 'admin_tools', 'css', 'theming.css'])
    return '<link rel="stylesheet" type="text/css" media="screen" href="%s" />' % css
Esempio n. 2
0
def render_theming_css():
    """
    Template tag that renders the needed css files for the theming app.
    """
    css = getattr(settings, 'ADMIN_TOOLS_THEMING_CSS', False)
    if css:
        css = '/'.join([get_media_url(), css])
    else:
        css = '/'.join([get_media_url(), 'admin_tools', 'css', 'theming.css'])
    return '<link rel="stylesheet" type="text/css" media="screen" href="%s" />' % css
def admin_tools_render_dashboard_css(context,
                                     location='index',
                                     dashboard=None):
    """
    Template tag that renders the dashboard css files, it takes two optional
    arguments:

    ``location``
        The location of the dashboard, it can be 'index' (for the admin index
        dashboard) or 'app_index' (for the app index dashboard), the default
        value is 'index'.

    ``dashboard``
        An instance of ``Dashboard``, if not given, the dashboard is retrieved
        with the ``get_index_dashboard`` or ``get_app_index_dashboard``
        functions, depending on the ``location`` argument.
    """
    if dashboard is None:
        dashboard = get_dashboard(context, location)

    context.update({
        'template': 'admin_tools/dashboard/css.html',
        'css_files': dashboard.Media.css,
        'media_url': get_media_url(),
    })
    return context
Esempio n. 4
0
def admin_tools_render_menu(context, menu=None):
    """
    Template tag that renders the menu, it takes an optional ``Menu`` instance
    as unique argument, if not given, the menu will be retrieved with the
    ``get_admin_menu`` function.
    """
    if menu is None:
        menu = get_admin_menu()

    menu.init_with_context(context)
    has_bookmark_item = False
    bookmark = None
    if len([c for c in menu.children if isinstance(c, items.Bookmarks)]) > 0:
        has_bookmark_item = True
        url = context['request'].get_full_path()
        try:
            bookmark = Bookmark.objects.filter(user=context['request'].user, url=url)[0]
        except:
            pass

    context.update({
        'template': menu.template,
        'menu': menu,
        'media_url': get_media_url(),
        'has_bookmark_item': has_bookmark_item,
        'bookmark': bookmark,
        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
    })
    return context
Esempio n. 5
0
def admin_tools_render_menu(context, menu=None):
    """
    Template tag that renders the menu, it takes an optional ``Menu`` instance
    as unique argument, if not given, the menu will be retrieved with the
    ``get_admin_menu`` function.
    """
    if menu is None:
        menu = get_admin_menu()

    menu.init_with_context(context)
    has_bookmark_item = False
    bookmark = None
    if len([c for c in menu.children if isinstance(c, items.Bookmarks)]) > 0:
        has_bookmark_item = True
        url = context['request'].get_full_path()
        try:
            bookmark = Bookmark.objects.filter(user=context['request'].user, url=url)[0]
        except:
            pass

    context.update({
        'template': menu.template,
        'menu': menu,
        'media_url': get_media_url(),
        'has_bookmark_item': has_bookmark_item,
        'bookmark': bookmark,
    })
    return context
Esempio n. 6
0
def admin_tools_render_dashboard(context, location='index', dashboard=None):
    """
    Template tag that renders the dashboard, it takes two optional arguments:
    
    ``location``
        The location of the dashboard, it can be 'index' (for the admin index
        dashboard) or 'app_index' (for the app index dashboard), the default
        value is 'index'.

    ``dashboard``
        An instance of ``Dashboard``, if not given, the dashboard is retrieved
        with the ``get_index_dashboard`` or ``get_app_index_dashboard``
        functions, depending on the ``location`` argument.
    """
    if dashboard is None:
        dashboard = get_dashboard(context, location)

    dashboard.init_with_context(context)

    try:
        preferences = DashboardPreferences.objects.get(
            user=context['request'].user).data
    except DashboardPreferences.DoesNotExist:
        preferences = '{}'

    context.update({
        'template': dashboard.template,
        'dashboard': dashboard,
        'dashboard_preferences': preferences,
        'split_at': math.ceil(float(len(dashboard.children))/float(dashboard.columns)),
        'media_url': get_media_url(),
        'has_disabled_modules': len([m for m in dashboard.children \
                                if not m.enabled]) > 0,
    })
    return context
def admin_tools_render_dashboard(context, location="index", dashboard=None):
    """
    Template tag that renders the dashboard, it takes two optional arguments:
    
    ``location``
        The location of the dashboard, it can be 'index' (for the admin index
        dashboard) or 'app_index' (for the app index dashboard), the default
        value is 'index'.

    ``dashboard``
        An instance of ``Dashboard``, if not given, the dashboard is retrieved
        with the ``get_index_dashboard`` or ``get_app_index_dashboard``
        functions, depending on the ``location`` argument.
    """
    if dashboard is None:
        dashboard = get_dashboard(context, location)

    dashboard.init_with_context(context)

    try:
        preferences = DashboardPreferences.objects.get(user=context["request"].user).data
    except DashboardPreferences.DoesNotExist:
        preferences = "{}"

    context.update(
        {
            "template": dashboard.template,
            "dashboard": dashboard,
            "dashboard_preferences": preferences,
            "split_at": math.ceil(float(len(dashboard.children)) / float(dashboard.columns)),
            "media_url": get_media_url(),
            "has_disabled_modules": len([m for m in dashboard.children if not m.enabled]) > 0,
        }
    )
    return context
Esempio n. 8
0
def admin_tools_render_dashboard(context, location='index', dashboard=None):
    """render Admin Tools dashboard with Chats
    """
    from admin_tools.dashboard.models import DashboardPreferences
    from admin_tools.utils import get_media_url, get_admin_site_name
    from django.core.urlresolvers import reverse

    if dashboard is None:
        from settings.admin.dashboard import MonitorIndexDashboard
        dashboard = MonitorIndexDashboard()

    dashboard.init_with_context(context)
    dashboard._prepare_children()

    try:
        preferences = DashboardPreferences.objects.get(
            user=context['request'].user, dashboard_id=dashboard.get_id()).data
    except DashboardPreferences.DoesNotExist:
        preferences = '{}'
        DashboardPreferences(user=context['request'].user,
                             dashboard_id=dashboard.get_id(),
                             data=preferences).save()

    context.update({
        'template': dashboard.template,
        'dashboard': dashboard,
        'dashboard_preferences': preferences,
        'split_at': math.ceil(float(len(dashboard.children))/float(dashboard.columns)),
        'media_url': get_media_url(),
        'has_disabled_modules': len([m for m in dashboard.children \
                                if not m.enabled]) > 0,
        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
    })
    return context
def admin_tools_render_leftnav_css(context, leftnav=None):
    """
    Template tag that renders the leftnav css files,, it takes an optional
    ``LeftNav`` instance as unique argument, if not given, the leftnav will be
    retrieved with the ``get_admin_leftnav`` function.
    """
    if leftnav is None:
        leftnav = DefaultLeftNav()

    context.update({
        'template': 'admin_tools/leftnav/css.html',
        'css_files': leftnav.Media.css,
        'media_url': get_media_url(),
    })
    return context
Esempio n. 10
0
def admin_tools_render_menu_css(context, menu=None):
    """
    Template tag that renders the menu css files,, it takes an optional 
    ``Menu`` instance as unique argument, if not given, the menu will be
    retrieved with the ``get_admin_menu`` function.
    """
    if menu is None:
        menu = get_admin_menu()

    context.update({
        'template': 'admin_tools/menu/css.html',
        'css_files': menu.Media.css,
        'media_url': get_media_url(),
    })
    return context
Esempio n. 11
0
def admin_tools_render_menu_css(context, menu=None):
    """
    Template tag that renders the menu css files,, it takes an optional 
    ``Menu`` instance as unique argument, if not given, the menu will be
    retrieved with the ``get_admin_menu`` function.
    """
    if menu is None:
        menu = get_admin_menu()

    context.update({
        'template': 'admin_tools/menu/css.html',
        'css_files': menu.Media.css,
        'media_url': get_media_url(),
    })
    return context
Esempio n. 12
0
def admin_tools_render_leftnav_css(context, leftnav=None):
    """
    Template tag that renders the leftnav css files,, it takes an optional
    ``LeftNav`` instance as unique argument, if not given, the leftnav will be
    retrieved with the ``get_admin_leftnav`` function.
    """
    if leftnav is None:
        leftnav = DefaultLeftNav()

    context.update({
        'template': 'admin_tools/leftnav/css.html',
        'css_files': leftnav.Media.css,
        'media_url': get_media_url(),
    })
    return context
def admin_tools_render_dashboard(context, location='index', dashboard=None):
    """
    Template tag that renders the dashboard, it takes two optional arguments:

    ``location``
        The location of the dashboard, it can be 'index' (for the admin index
        dashboard) or 'app_index' (for the app index dashboard), the default
        value is 'index'.

    ``dashboard``
        An instance of ``Dashboard``, if not given, the dashboard is retrieved
        with the ``get_index_dashboard`` or ``get_app_index_dashboard``
        functions, depending on the ``location`` argument.
    """
    if dashboard is None:
        dashboard = get_dashboard(context, location)

    dashboard.init_with_context(context)
    dashboard._prepare_children()

    try:
        preferences = DashboardPreferences.objects.get(
            user=context['request'].user,
            dashboard_id=dashboard.get_id()
        ).data
    except DashboardPreferences.DoesNotExist:
        preferences = '{}'
        try:
            DashboardPreferences(
                user=context['request'].user,
                dashboard_id=dashboard.get_id(),
                data=preferences
            ).save()
        except IntegrityError:
            # dashboard already was saved for that (user, dashboard)
            pass

    context.update({
        'template': dashboard.template,
        'dashboard': dashboard,
        'dashboard_preferences': preferences,
        'split_at': math.ceil(float(len(dashboard.children))/float(dashboard.columns)),
        'media_url': get_media_url(),
        'has_disabled_modules': len([m for m in dashboard.children \
                                if not m.enabled]) > 0,
        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
    })
    return context
def render_theming_css():
    """
    Template tag that renders the needed css files for the theming app.

    If ADMIN_TOOLS_THEMING_CSS is explicitely defined to None, don't render
    anything.
    """
    rval = ''
    try:
        css_path = getattr(settings, 'ADMIN_TOOLS_THEMING_CSS')
    except AttributeError:
        css_path = 'admin_tools/css/theming.css'

    if css_path is not None:
        css_url = '%s/%s' % (get_media_url(), css_path)
        rval = '<link rel="stylesheet" type="text/css" media="screen" href="%s" />' % css_url

    return rval
Esempio n. 15
0
def render_theming_css():
    """
    Template tag that renders the needed css files for the theming app.

    If ADMIN_TOOLS_THEMING_CSS is explicitely defined to None, don't render
    anything.
    """
    rval = ''
    try:
        css_path = getattr(settings, 'ADMIN_TOOLS_THEMING_CSS')
    except AttributeError:
        css_path = 'admin_tools/css/theming.css'

    if css_path is not None:
        css_url = '%s/%s' % (get_media_url(), css_path)
        rval = '<link rel="stylesheet" type="text/css" media="screen" href="%s" />' % css_url

    return rval
def admin_tools_render_dashboard_css(context, location='index', dashboard=None):
    """
    Template tag that renders the dashboard css files, it takes two optional
    arguments:

    ``location``
        The location of the dashboard, it can be 'index' (for the admin index
        dashboard) or 'app_index' (for the app index dashboard), the default
        value is 'index'.

    ``dashboard``
        An instance of ``Dashboard``, if not given, the dashboard is retrieved
        with the ``get_index_dashboard`` or ``get_app_index_dashboard``
        functions, depending on the ``location`` argument.
    """
    if dashboard is None:
        dashboard = get_dashboard(context, location)

    context.update({
        'template' : 'admin_tools/dashboard/css.html',
        'css_files': dashboard.Media.css,
        'media_url': get_media_url(),
    })
    return context