示例#1
0
def dashboard(request, template_name="admin/dashboard.html"):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.
    """
    return render(request=request,
                  template_name=template_name,
                  context={
                      'widgets': primary_widgets + secondary_widgets,
                      'root_path': reverse('admin:index'),
                      'title': _('Admin Dashboard'),
                      'page_model_attrs': {
                          'supportData':
                          serialize_support_data(request, force_is_admin=True),
                      },
                  })
示例#2
0
def dashboard(request, template_name="admin/dashboard.html"):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.
    """
    profile = Profile.objects.get_or_create(user=request.user)[0]

    if profile.extra_data is None:
        profile.extra_data = {}
        profile.save(update_fields=('extra_data', ))

    profile_data = profile.extra_data

    selected_primary_widgets, unselected_primary_widgets = \
        _get_widget_selections(primary_widgets,
                               profile_data.get('primary_widget_selections'))

    selected_secondary_widgets, unselected_secondary_widgets = \
        _get_widget_selections(secondary_widgets,
                               profile_data.get('secondary_widget_selections'))

    sorted_primary_widgets = _sort_widgets(
        selected_primary_widgets, profile_data.get('primary_widget_positions'))

    sorted_secondary_widgets = _sort_widgets(
        selected_secondary_widgets,
        profile_data.get('secondary_widget_positions'))

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'primary_widgets': primary_widgets,
                'root_path': settings.SITE_ROOT + 'admin/db/',
                'secondary_widgets': secondary_widgets,
                'selected_primary_widgets': sorted_primary_widgets,
                'selected_secondary_widgets': sorted_secondary_widgets,
                'support_data': serialize_support_data(request, True),
                'title': _("Admin Dashboard"),
                'unselected_primary_widgets': unselected_primary_widgets,
                'unselected_secondary_widgets': unselected_secondary_widgets,
            }))
示例#3
0
def dashboard(request, template_name="admin/dashboard.html"):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.
    """
    profile = request.user.get_profile()
    profile_data = profile.extra_data

    selected_primary_widgets, unselected_primary_widgets = \
        _get_widget_selections(primary_widgets,
                               profile_data.get('primary_widget_selections'))

    selected_secondary_widgets, unselected_secondary_widgets = \
        _get_widget_selections(secondary_widgets,
                               profile_data.get('secondary_widget_selections'))

    sorted_primary_widgets = _sort_widgets(
        selected_primary_widgets,
        profile_data.get('primary_widget_positions')
    )

    sorted_secondary_widgets = _sort_widgets(
        selected_secondary_widgets,
        profile_data.get('secondary_widget_positions')
    )

    return render(
        request=request,
        template_name=template_name,
        context={
            'primary_widgets': primary_widgets,
            'root_path': reverse('admin:index'),
            'secondary_widgets': secondary_widgets,
            'selected_primary_widgets': sorted_primary_widgets,
            'selected_secondary_widgets': sorted_secondary_widgets,
            'support_data': serialize_support_data(request, True),
            'title': _('Admin Dashboard'),
            'unselected_primary_widgets': unselected_primary_widgets,
            'unselected_secondary_widgets': unselected_secondary_widgets,
        })
示例#4
0
def dashboard(request, template_name="admin/dashboard.html"):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.
    """
    profile = request.user.get_profile()
    profile_data = profile.extra_data

    selected_primary_widgets, unselected_primary_widgets = \
        _get_widget_selections(primary_widgets,
                               profile_data.get('primary_widget_selections'))

    selected_secondary_widgets, unselected_secondary_widgets = \
        _get_widget_selections(secondary_widgets,
                               profile_data.get('secondary_widget_selections'))

    sorted_primary_widgets = _sort_widgets(
        selected_primary_widgets,
        profile_data.get('primary_widget_positions')
    )

    sorted_secondary_widgets = _sort_widgets(
        selected_secondary_widgets,
        profile_data.get('secondary_widget_positions')
    )

    return render_to_response(template_name, RequestContext(request, {
        'primary_widgets': primary_widgets,
        'root_path': settings.SITE_ROOT + 'admin/db/',
        'secondary_widgets': secondary_widgets,
        'selected_primary_widgets': sorted_primary_widgets,
        'selected_secondary_widgets': sorted_secondary_widgets,
        'support_data': serialize_support_data(request, True),
        'title': _("Admin Dashboard"),
        'unselected_primary_widgets': unselected_primary_widgets,
        'unselected_secondary_widgets': unselected_secondary_widgets,
    }))
示例#5
0
def dashboard(request, template_name="admin/dashboard.html"):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.
    """
    profile = Profile.objects.get_or_create(user=request.user)[0]

    if profile.extra_data is None:
        profile.extra_data = {}
        profile.save(update_fields=('extra_data',))

    profile_data = profile.extra_data

    selected_primary_widgets = []
    unselected_primary_widgets = []
    primary_widget_selections = profile_data.get('primary_widget_selections')
    if primary_widget_selections:
        for p in primary_widgets:
            if primary_widget_selections[p.widget_id] == "1":
                selected_primary_widgets.append(p)
            else:
                unselected_primary_widgets.append(p)
    else:
        selected_primary_widgets = primary_widgets
        unselected_primary_widgets = None

    selected_secondary_widgets = []
    unselected_secondary_widgets = []
    secondary_widget_selections = profile_data.get(
        'secondary_widget_selections')
    if secondary_widget_selections:
        for s in secondary_widgets:
            if secondary_widget_selections[s.widget_id] == "1":
                selected_secondary_widgets.append(s)
            else:
                unselected_secondary_widgets.append(s)
    else:
        selected_secondary_widgets = secondary_widgets
        unselected_secondary_widgets = None

    primary_widget_positions = profile_data.get('primary_widget_positions')
    if primary_widget_positions:
        sorted_primary_widgets = sorted(
            selected_primary_widgets,
            key=(lambda y: primary_widget_positions[y.widget_id] or
                 len(primary_widget_positions)))
    else:
        sorted_primary_widgets = selected_primary_widgets

    secondary_widget_positions = profile_data.get('secondary_widget_positions')
    if secondary_widget_positions:
        sorted_secondary_widgets = sorted(
            selected_secondary_widgets,
            key=(lambda y: secondary_widget_positions[y.widget_id] or
                 len(secondary_widget_positions)))
    else:
        sorted_secondary_widgets = selected_secondary_widgets

    return render_to_response(template_name, RequestContext(request, {
        'primary_widgets': primary_widgets,
        'root_path': settings.SITE_ROOT + 'admin/db/',
        'secondary_widgets': secondary_widgets,
        'selected_primary_widgets': sorted_primary_widgets,
        'selected_secondary_widgets': sorted_secondary_widgets,
        'support_data': serialize_support_data(request, True),
        'title': _("Admin Dashboard"),
        'unselected_primary_widgets': unselected_primary_widgets,
        'unselected_secondary_widgets': unselected_secondary_widgets,
    }))
示例#6
0
def dashboard(request, template_name="admin/dashboard.html"):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.
    """
    profile = Profile.objects.get_or_create(user=request.user)[0]

    if profile.extra_data is None:
        profile.extra_data = {}
        profile.save(update_fields=('extra_data', ))

    profile_data = profile.extra_data

    selected_primary_widgets = []
    unselected_primary_widgets = []
    primary_widget_selections = profile_data.get('primary_widget_selections')
    if primary_widget_selections:
        for p in primary_widgets:
            if primary_widget_selections[p.widget_id] == "1":
                selected_primary_widgets.append(p)
            else:
                unselected_primary_widgets.append(p)
    else:
        selected_primary_widgets = primary_widgets
        unselected_primary_widgets = None

    selected_secondary_widgets = []
    unselected_secondary_widgets = []
    secondary_widget_selections = profile_data.get(
        'secondary_widget_selections')
    if secondary_widget_selections:
        for s in secondary_widgets:
            if secondary_widget_selections[s.widget_id] == "1":
                selected_secondary_widgets.append(s)
            else:
                unselected_secondary_widgets.append(s)
    else:
        selected_secondary_widgets = secondary_widgets
        unselected_secondary_widgets = None

    primary_widget_positions = profile_data.get('primary_widget_positions')
    if primary_widget_positions:
        sorted_primary_widgets = sorted(
            selected_primary_widgets,
            key=(lambda y: primary_widget_positions[y.widget_id] or len(
                primary_widget_positions)))
    else:
        sorted_primary_widgets = selected_primary_widgets

    secondary_widget_positions = profile_data.get('secondary_widget_positions')
    if secondary_widget_positions:
        sorted_secondary_widgets = sorted(
            selected_secondary_widgets,
            key=(lambda y: secondary_widget_positions[y.widget_id] or len(
                secondary_widget_positions)))
    else:
        sorted_secondary_widgets = selected_secondary_widgets

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'primary_widgets': primary_widgets,
                'root_path': settings.SITE_ROOT + 'admin/db/',
                'secondary_widgets': secondary_widgets,
                'selected_primary_widgets': sorted_primary_widgets,
                'selected_secondary_widgets': sorted_secondary_widgets,
                'support_data': serialize_support_data(request, True),
                'title': _("Admin Dashboard"),
                'unselected_primary_widgets': unselected_primary_widgets,
                'unselected_secondary_widgets': unselected_secondary_widgets,
            }))
示例#7
0
def admin_dashboard_view(request):
    """Display the administration dashboard.

    This is the entry point to the admin site, containing news updates and
    useful administration tasks.

    Args:
        request (django.http.HttpRequest):
            The HTTP request from the client.

    Returns:
        django.http.HttpResponse:
        The resulting HTTP response for the view.
    """
    widgets_info = []
    widgets_html = []

    for widget_cls in admin_widgets_registry:
        try:
            widget = widget_cls()

            if not widget.can_render(request):
                continue

            if widget.dom_id is None:
                widget.dom_id = 'admin-widget-%s' % widget.widget_id

            widget_info = {
                'id': widget.widget_id,
                'domID': widget.dom_id,
                'viewClass': widget.js_view_class,
                'modelClass': widget.js_model_class,
            }

            js_view_options = widget.get_js_view_options(request)
            js_model_attrs = widget.get_js_model_attrs(request)
            js_model_options = widget.get_js_model_options(request)

            if js_view_options:
                widget_info['viewOptions'] = js_view_options

            if js_model_attrs:
                widget_info['modelAttrs'] = js_model_attrs

            if js_model_options:
                widget_info['modelOptions'] = js_model_options

            widget_html = widget.render(request)
        except Exception as e:
            logger.exception('Error setting up administration widget %r: %s',
                             widget_cls, e)
            continue

        widgets_info.append(widget_info)
        widgets_html.append((widget_html, ))

    return render(request=request,
                  template_name='admin/dashboard.html',
                  context={
                      'page_model_attrs': {
                          'supportData':
                          serialize_support_data(request, force_is_admin=True),
                          'widgetsData':
                          widgets_info,
                      },
                      'title': _('Admin Dashboard'),
                      'widgets_html': format_html_join('', '{0}',
                                                       widgets_html),
                  })