def ls_log(request): sys_id = request.GET.get('sys_id','') mod_id = request.GET.get('mod_id','') func_id = request.GET.get('func_id','') start = request.GET.get('start','') if start != '': start = datetime.strptime(start+':00','%Y-%m-%d %X') end = request.GET.get('end','') if end != '': end = datetime.strptime(end+':00','%Y-%m-%d %X') if sys_id !='' and mod_id == '': mods = ModuleModel.objects(sys_id = sys_id) if start == '' and end == '': log = LogModel.objects(mod_id__in = [mod.id for mod in mods]).order_by('-time') if start != '' and end == '': log = LogModel.objects(mod_id__in = [mod.id for mod in mods],time__gte=start).order_by('-time') if start == '' and end != '': log = LogModel.objects(mod_id__in = [mod.id for mod in mods],time__lte=end).order_by('-time') if start != '' and end != '': log = LogModel.objects(mod_id__in = [mod.id for mod in mods],time__gte=start,time__lte=end).order_by('-time') if mod_id != '' and func_id == '': if start == '' and end == '': log = LogModel.objects(mod_id = mod_id).order_by('-time') if start != '' and end == '': log = LogModel.objects(mod_id = mod_id,time__gte=start).order_by('-time') if start == '' and end != '': log = LogModel.objects(mod_id = mod_id,time__lte=end).order_by('-time') if start != '' and end != '': log = LogModel.objects(mod_id = mod_id,time__gte=start,time__lte=end).order_by('-time') #log = LogModel.objects(__raw__={'mod_id':mod_id}) if func_id != '': #log = LogModel.objects(mod_id = mod_id,time__gte=start+':00',time__lte=end+':00') if start == '' and end == '': log = LogModel.objects(func_id = func_id).order_by('-time') if start != '' and end == '': log = LogModel.objects(func_id = func_id ,time__gte=start).order_by('-time') if start == '' and end != '': log = LogModel.objects(func_id = func_id ,time__lte=end).order_by('-time') if start != '' and end != '': log = LogModel.objects(func_id = func_id ,time__gte=start,time__lte=end).order_by('-time') if log: mod = ModuleModel.objects(id = log[0].mod_id) sys_id = mod[0].sys_id kn = KeynameModel.objects(sys_id = sys_id) keyname = {} for k in kn: keyname[k.key] = k.name t = get_template('log/index.html') html = t.render(Context({'logs':log,'detail':'detail','sys_id':sys_id,'mod_id':mod_id,'start':start,'end':end,'keyname':keyname})) return HttpResponse(html)
def map_key_name(request): key = request.POST['key'] sys_id = request.POST['sys_id'] name = request.POST['name'] kn = KeynameModel.objects(key = key,sys_id = sys_id) if not kn: kn = KeynameModel(key = key,name = name,sys_id = sys_id) kn.save() else: kn = KeynameModel(id = kn[0].id,key = key,name = name) kn.save() return HttpResponse(request.POST['name'])