码迷,mamicode.com
首页 > 其他好文 > 详细

CRM-kingadmin开发设计

时间:2019-08-06 01:03:52      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:sites   rom   play   app   gad   led   字符   username   val   

通过字符串导入模块

importlib.import_module()

__import__() 

技术图片
from django.shortcuts import render,redirect
from django.contrib.auth import authenticate,login,logout
from django.contrib.auth.decorators import login_required
from django import conf
from kingadmin import app_setup
from crm import models
app_setup.kingadmin_auto_discover()


from kingadmin.sites import  site
print("sites.",site.enabled_admins)

# for k,v in site.enabled_admins.items():
#     for table_name,admin_class in v.items():
#         print(table_name,id(admin_class))
# # Create your views here.


def app_index(request):
    #enabled_admins =

    return render(request,kingadmin/app_index.html, {site:site})

def get_filter_result(request,querysets):
    filter_conditions = {}
    for key,val in request.GET.items():
        if val:
            filter_conditions[key] =  val


    print("filter_conditions",filter_conditions)
    return querysets.filter(**filter_conditions),filter_conditions

@login_required
def table_obj_list(request,app_name,model_name):
    """取出指定model里的数据返回给前端"""
    #print("app_name,model_name:",site.enabled_admins[app_name][model_name])
    admin_class = site.enabled_admins[app_name][model_name]
    querysets = admin_class.model.objects.all()

    querysets,filter_condtions  = get_filter_result(request,querysets)
    admin_class.filter_condtions = filter_condtions

    print(request.GET)
    #print("admin class",admin_class.model )

    return render(request,kingadmin/table_obj_list.html, {querysets:querysets,admin_class:admin_class})


def acc_login(request):
    error_msg = ‘‘
    if request.method == "POST":
        username = request.POST.get(username)
        password = request.POST.get(password)

        user = authenticate(username=username,password=password)
        if user:
            print("passed authencation",user)
            login(request,user)
            #request.user = user

            return  redirect( request.GET.get(next,/kingadmin/) )
        else:
            error_msg = "Wrong username or password!"
    return render(request, kingadmin/login.html, {error_msg:error_msg})


def acc_logout(request):
    logout(request)
    return redirect("/login/")
views

技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片技术图片        

CRM-kingadmin开发设计

标签:sites   rom   play   app   gad   led   字符   username   val   

原文地址:https://www.cnblogs.com/jintian/p/11306469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!