def module_td(request, id): ''' 模块的事务 :param request: :return: ''' account = request.session["now_account"] presentModule = ModuleInfo.objects.values('module_name').filter(id=id) projectlist = projectAndModule fav_opt = FavTd.objects tdinfo = TdInfo.objects.filter(belong_module__id=id).order_by("-run_count") kwargs = {} tdlist = [] for k in xrange(len(tdinfo)): td = {} flag = fav_opt.get_fav_by_tdAndUser(account, tdinfo[k].id) if flag == 1: td.setdefault('isFav', 'true') else: td.setdefault('isFav', 'false') if k % 2 == 0: td.setdefault('right', 'true') else: td.setdefault('right', 'false') td.setdefault('id', tdinfo[k].id) td.setdefault('title', tdinfo[k].title) td.setdefault('td_url', tdinfo[k].td_url) td.setdefault('author', tdinfo[k].author) td.setdefault('params', eval(tdinfo[k].params)) td.setdefault('instruction', tdinfo[k].instruction) td.setdefault('belong_project', tdinfo[k].belong_project) td.setdefault('belong_module', tdinfo[k].belong_module) tdlist.append(td) if request.session.get('login_status'): if request.is_ajax(): td_info = json.loads(request.body.decode('utf-8')) kwargs['user'] = request.session["now_account"] kwargs['id'] = td_info.pop('id') if td_info.get('model') == 'pv': msg = add_td_pv(kwargs['id']) else: if td_info.pop('type'): msg = add_fav_data(True, **kwargs) else: msg = add_fav_data(False, **kwargs) return HttpResponse(get_ajax_msg(msg, 'ok')) else: manage_info = { 'account': request.session["now_account"], 'presentModule': presentModule[0]['module_name'], 'tdList': tdlist, 'projects': projectlist } init_filter_session(request) return render_to_response('module_td.html', manage_info) else: return HttpResponseRedirect("/qacenter/login/")
def base(request): """ 导航 :param request: :return: """ projectlist = projectAndModule manage_info = { 'account': request.session["now_account"], 'projects': projectlist } init_filter_session(request) return render_to_response('data/base.html', manage_info)
def logout(request): """ 注销登录 :param request: :return: """ if request.method == 'GET': logger.info('{username}退出'.format(username=request.session['now_account'])) try: del request.session['now_account'] del request.session['login_status'] init_filter_session(request, type=False) except KeyError: logger.error('session invalid') return HttpResponseRedirect("/qacenter/login")
def base(request): """ 导航 :param request: :return: """ projectlist = projectAndModule if request.session.get('login_status'): manage_info = { 'account': request.session["now_account"], 'projects': projectlist } init_filter_session(request) return render_to_response('base.html', manage_info) else: return HttpResponseRedirect("/qacenter/login/")
def hot_td(request): """ 常用事务:调用量前十 :param request: :return: """ account = request.session["now_account"] projectlist = projectAndModule fav_opt = FavTd.objects tdinfo = TdInfo.objects.all().order_by('-run_count')[:10] tdlist = [] for k in xrange(len(tdinfo)): td = {} flag = fav_opt.get_fav_by_tdAndUser(account, tdinfo[k].id) if flag == 1: td.setdefault('isFav', 'true') else: td.setdefault('isFav', 'false') if k % 2 == 0: td.setdefault('right', 'true') else: td.setdefault('right', 'false') td.setdefault('id', tdinfo[k].id) td.setdefault('title', tdinfo[k].title) td.setdefault('td_url', tdinfo[k].td_url) td.setdefault('author', tdinfo[k].author) td.setdefault('instruction', tdinfo[k].instruction) td.setdefault('belong_project', tdinfo[k].belong_project) td.setdefault('belong_module', tdinfo[k].belong_module) td.setdefault('params', eval(tdinfo[k].params)) tdlist.append(td) if request.session.get('login_status'): if request.method == 'GET': manage_info = { 'account': account, 'tdList': tdlist, 'projects': projectlist } init_filter_session(request) return render_to_response('hot_td.html', manage_info) else: return HttpResponseRedirect("/qacenter/login/")