Exemplo n.º 1
0
def configure_url_dispatch(request, url):
    print('---url dispatch', url)
    print(enabled_admins)
    if url in enabled_admins:
        print(enabled_admins[url])

        querysets = tables.table_filter(request, enabled_admins[url],
                                        enabled_admins[url].model)
        order_res = tables.get_orderby(request, querysets, enabled_admins[url])

        paginator = Paginator(order_res[0], enabled_admins[url].list_per_page)

        page = request.GET.get('page')
        try:
            table_obj_list = paginator.page(page)
        except PageNotAnInteger:
            table_obj_list = paginator.page(1)
        except EmptyPage:
            table_obj_list = paginator.page(paginator.num_pages)

        table_obj = tables.TableHandler(request, enabled_admins[url].model,
                                        enabled_admins[url], table_obj_list,
                                        order_res)

        return render(
            request, 'king_admin/model_obj_list.html', {
                'table_obj': table_obj,
                'active_node': '/configure/index/',
                'paginator': paginator
            })
    else:
        raise Http404("url %s not found" % url)
Exemplo n.º 2
0
def configure_url_dispatch(request, url):
    #print('---url dispatch',url)
    #print(enabled_admins)
    if url in enabled_admins:
        #print(enabled_admins[url])

        if request.method == "POST":
            print('post-->', request.POST)

            delete_tag = request.POST.get("_delete_confirm")
            if delete_tag == "yes":
                del_ids = request.POST.getlist("deleted_objs")

                enabled_admins[url].model.objects.filter(
                    id__in=del_ids).delete()

            else:

                admin_action = request.POST.get('admin_action')

                admin_obj = enabled_admins[url]
                if hasattr(admin_obj, admin_action):
                    admin_action_func = getattr(admin_obj, admin_action)
                    return admin_action_func(request)
                else:
                    raise NotImplementedError("admin_action %s cannot find" %
                                              admin_action)

        querysets = tables.table_filter(request, enabled_admins[url],
                                        enabled_admins[url].model)
        searched_querysets = tables.search_by(request, querysets,
                                              enabled_admins[url])
        order_res = tables.get_orderby(request, searched_querysets,
                                       enabled_admins[url])

        paginator = Paginator(order_res[0], enabled_admins[url].list_per_page)

        page = request.GET.get('page')
        try:
            table_obj_list = paginator.page(page)
        except PageNotAnInteger:
            table_obj_list = paginator.page(1)
        except EmptyPage:
            table_obj_list = paginator.page(paginator.num_pages)

        table_obj = tables.TableHandler(request, enabled_admins[url].model,
                                        enabled_admins[url], table_obj_list,
                                        order_res)

        return render(
            request, 'king_admin/model_obj_list.html', {
                'table_obj': table_obj,
                'active_node': '/configure/index/',
                'paginator': paginator
            })

    else:
        raise Http404("url %s not found" % url)
Exemplo n.º 3
0
def audit(request):

    audit_log_list = tables.table_filter(request,admin.AuditLogAdmin,models.AuditLog)
    order_res = tables.get_orderby(request, audit_log_list, admin.AuditLogAdmin)
    paginator = Paginator(order_res[0], admin.AuditLogAdmin.list_per_page)

    page = request.GET.get('page')
    try:
        audit_log_objs = paginator.page(page)
    except PageNotAnInteger:
        audit_log_objs = paginator.page(1)
    except EmptyPage:
        audit_log_objs = paginator.page(paginator.num_pages)

    table_obj = tables.TableHandler(request,
                                    models.AuditLog,
                                    admin.AuditLogAdmin,
                                    audit_log_objs,
                                    order_res)

    return render(request,"audit.html",{'table_obj':table_obj,
                                        'paginator':paginator})