Exemplo n.º 1
0
def advance_query_index(request, app_label, model_name):
    enq = Enquiry(model_name)
    x = enq.findAllRelationTables(None)
    #print enq.parentProperty
    b = enq.getAllFields(*x)
    condition = {
        "=": _(u"等于"),
        ">=": _(u"大于等于"),
        ">": _(u"大于"),
        "<=": _(u"小于等于"),
        "<": _(u"小于"),
        "in": _(u"满足任意一个"),
        "contains": _(u"含有"),
        "isnull": _(u"等于空值"),
    }
    #print condition
    html = writeDiv(enq.alltables, enq.allfields, enq.relatetable,
                    enq.parentProperty, b, enq.subTableProperty)
    form = gen_form_fields(enq.alltables, enq.allfields)
    #print form.as_table()
    t = loader.get_template("advenquiry.html")
    #return t.render(RequestContext(request,{'tablesName':"enq_" +model_name,"div": html,"cond":condition}))
    return render_to_response(
        "advenquiry.html", {
            'tablesName': "enq_" + model_name,
            "div": html,
            "cond": condition,
            'form': form
        })
Exemplo n.º 2
0
def advance_query_index(request,app_label,model_name):
    enq=Enquiry(model_name)
    x=enq.findAllRelationTables(None) 
    #print enq.parentProperty
    b=enq.getAllFields(*x)
    condition={
    "=":_(u"等于"),
    ">=":_(u"大于等于"),
    ">":_(u"大于"),
    "<=":_(u"小于等于"),
    "<":_(u"小于"),
    "in":_(u"满足任意一个"),
    "contains":_(u"含有"),
    "isnull":_(u"等于空值"),
  
    }
    #print condition
    html= writeDiv(enq.alltables,enq.allfields,enq.relatetable,enq.parentProperty,b,enq.subTableProperty)
    form=gen_form_fields(enq.alltables,enq.allfields)
    #print form.as_table()
    t=loader.get_template("advenquiry.html")
    #return t.render(RequestContext(request,{'tablesName':"enq_" +model_name,"div": html,"cond":condition}))
    return render_to_response("advenquiry.html",{'tablesName':"enq_" +model_name,"div": html,"cond":condition,'form':form})
Exemplo n.º 3
0
def setview(request,app_label,model_name):
    try:
        actions={}
        dataModel=""
        enq=Enquiry(model_name)
        x=enq.findAllRelationTables(None) 
        dataModel=x[0]
        x=[x[0]]
        fields=enq.getAllFields(*x)
        #视图类型
        from dbapp.models import VIEWTYPE_CHOICES
        viewtype=("%s"%n for n,v in VIEWTYPE_CHOICES)
        
        #操作权限
        if hasattr(dataModel,"get_all_operations"):
            action=dataModel.get_all_operations()
        else:
            action=[]
        for act in action:
            if hasattr(dataModel,act):
                pr=getattr(dataModel,act)
                actions[act]=u"%s"%pr.operation_name
        t=loader.get_template("view.html")
        
        relfield={}
        for name,value in enq.relatetable.items():
            relfield[value]=name
        #print relfield
       
       
        tfs={}
        #当前模型字段
        modelfields={}
        for fld in enq.allfields:
            if fld.split(".")[0]==dataModel.__name__:
                modelfields[fld.split(".")[1]]=fields[fld][3]
                tfs[fld]=fields[fld][3]
        
      
        #关联表字段
        for fld in enq.allfields:
            if fld.split(".")[0].lower()!=dataModel.__name__.lower():
                tfs[fld]=fields[relfield[fld.split(".")[0]]][3]+"." +fields[fld][3]

        #当前模型过滤器字段列表
        #print modelfields

        viewfilter={}
        try:
            if hasattr(dataModel.Admin,"list_filter"):
                for fld in dataModel.Admin.list_filter:
                    viewfilter[dataModel.__name__+"." +fld]=fields[dataModel.__name__+"."+fld][3]

        except:
            import traceback; traceback.print_exc()
            pass
        if viewfilter:
            has_filter=True
        else:
            has_filter=False
        if actions:
            hasaction=True
        else:
            hasaction=False
        
#        return t.render(RequestContext(request,{
#        'has_action':hasaction,'actions':actions,'fields':tfs,'modelfields':modelfields,
#                    'has_filter':has_filter,'viewfilter':viewfilter,
#                    'viewtype':viewtype,'all_fields':fields
#                    }))
#        
        return render_to_response("view.html",{
                            'has_action':hasaction,
                            'actions':actions,
                            'fields':tfs,
                            'modelfields':modelfields,
                            'has_filter':has_filter,
                            'viewfilter':viewfilter,
                            'viewtype':viewtype,
                            'all_fields':fields,
                    }
)
    except:
        
        import traceback; traceback.print_exc()
Exemplo n.º 4
0
def setview(request, app_label, model_name):
    try:
        actions = {}
        dataModel = ""
        enq = Enquiry(model_name)
        x = enq.findAllRelationTables(None)
        dataModel = x[0]
        x = [x[0]]
        fields = enq.getAllFields(*x)
        #视图类型
        from dbapp.models import VIEWTYPE_CHOICES
        viewtype = ("%s" % n for n, v in VIEWTYPE_CHOICES)

        #操作权限
        if hasattr(dataModel, "get_all_operations"):
            action = dataModel.get_all_operations()
        else:
            action = []
        for act in action:
            if hasattr(dataModel, act):
                pr = getattr(dataModel, act)
                actions[act] = u"%s" % pr.operation_name
        t = loader.get_template("view.html")

        relfield = {}
        for name, value in enq.relatetable.items():
            relfield[value] = name
        #print relfield

        tfs = {}
        #当前模型字段
        modelfields = {}
        for fld in enq.allfields:
            if fld.split(".")[0] == dataModel.__name__:
                modelfields[fld.split(".")[1]] = fields[fld][3]
                tfs[fld] = fields[fld][3]

        #关联表字段
        for fld in enq.allfields:
            if fld.split(".")[0].lower() != dataModel.__name__.lower():
                tfs[fld] = fields[relfield[fld.split(".")
                                           [0]]][3] + "." + fields[fld][3]

        #当前模型过滤器字段列表
        #print modelfields

        viewfilter = {}
        try:
            if hasattr(dataModel.Admin, "list_filter"):
                for fld in dataModel.Admin.list_filter:
                    viewfilter[dataModel.__name__ + "." +
                               fld] = fields[dataModel.__name__ + "." + fld][3]

        except:
            import traceback
            traceback.print_exc()
            pass
        if viewfilter:
            has_filter = True
        else:
            has_filter = False
        if actions:
            hasaction = True
        else:
            hasaction = False

#        return t.render(RequestContext(request,{
#        'has_action':hasaction,'actions':actions,'fields':tfs,'modelfields':modelfields,
#                    'has_filter':has_filter,'viewfilter':viewfilter,
#                    'viewtype':viewtype,'all_fields':fields
#                    }))
#
        return render_to_response(
            "view.html", {
                'has_action': hasaction,
                'actions': actions,
                'fields': tfs,
                'modelfields': modelfields,
                'has_filter': has_filter,
                'viewfilter': viewfilter,
                'viewtype': viewtype,
                'all_fields': fields,
            })
    except:

        import traceback
        traceback.print_exc()