def host(req): if not req.user.is_superuser: return HttpResponseRedirect("/info/not_admin") hostlist = Host.objects.all() if req.method == "GET": return ren2res("apps/apps_host.html", req, paginate(req, hostlist)) elif req.method == "POST": i = 0 page = paginate(req, hostlist) submit = [] # get host id, refer to apps_host_add.html for n in req.POST.keys(): if n[0:6] == "hostid": host_id = n[6:] try: item = Host.objects.get(id=host_id) except: page.update(err="无效的主机ID") return ren2res("apps/apps_host.html", req, page) name = req.POST["name" + host_id].strip() ip = req.POST["ip" + host_id].strip() port = req.POST["port" + host_id].strip() port = port if port != "" else SERVANT_PORT error = host_check(name, ip, port) if error: page.update(err=error) return ren2res("apps/apps_host.html", req, page) item.name = name item.ip = ip item.port = port submit.append(item) for x in submit: x.save() page.update(info="修改成功") return ren2res("apps/apps_host.html", req, page)
def download(req): if req.method=='GET': item=[] for f in os.listdir(DBDATA_DIR): nm=os.path.join(DBDATA_DIR,f) if os.path.isfile(nm): item.append({'name':f,'date':asctime(localtime(os.path.getmtime(nm))),'size':os.path.getsize(nm),'url':'/dbdata/'+f}) return ren2res('data/download.html',req,paginate(req,item))
def list(req): if req.user.is_superuser: dict={'super':req.user.is_superuser} dict.update(paginate(req,User.objects.filter(is_active=True),8)) if req.method=='GET': return ren2res("user/list.html",req,dict) else : return HttpResponseRedirect("/info/not_admin/")
def verify(req): if not req.user.is_superuser : return HttpResponseRedirect("/info/not_admin/") dict={'super':req.user.is_superuser} if req.method=='GET': dict.update(paginate(req,User.objects.filter(is_active=False).filter(last_login__isnull=True),8)) return ren2res("user/verify.html",req,dict) if req.method=='POST': try: a=User.objects.get(id=req.POST['id']) except ObjectDoesNotExist: dict.update(err="用户不存在") return ren2res("user/verify.html",req,dict) a.is_active=True a.save() dict.update(paginate(req,User.objects.filter(is_active=False),8)) dict.update(info="修改成功") return ren2res("user/verify.html",req,dict)
def list(req): if req.method=='GET': jobs=Job.objects.all() if not req.user.is_superuser: jobs=jobs.filter(uid=req.user) if jobs.exists(): jobs=jobs.order_by("-add_time") return ren2res("jobs/list.html",req,paginate(req,jobs)) else: return ren2res("jobs/list.html",req,{'info':"没有提交的作业!"})
def list(req): if req.method == 'GET': jobs = Job.objects.all() if not req.user.is_superuser: jobs = jobs.filter(uid=req.user) if jobs.exists(): jobs = jobs.order_by("-add_time") return ren2res("jobs/list.html", req, paginate(req, jobs)) else: return ren2res("jobs/list.html", req, {'info': "没有提交的作业!"})
def download(req): if req.method == 'GET': item = [] for f in os.listdir(DBDATA_DIR): nm = os.path.join(DBDATA_DIR, f) if os.path.isfile(nm): item.append({ 'name': f, 'date': asctime(localtime(os.path.getmtime(nm))), 'size': os.path.getsize(nm), 'url': '/dbdata/' + f }) return ren2res('data/download.html', req, paginate(req, item))
def render(template,req,qs,field='trade_date'): q=QueryDict(mutable=True) dict={} qs=qs.using(USE_DB).annotate(the_filter_date=F(field)) sd=req.GET.get('sdate') if sd: q['sdate']=sd dict.update(sdate=sd) sd=datetime.strptime(sd,"%Y-%m-%d") qs=qs.filter(the_filter_date__gte=sd) ed=req.GET.get('edate') if ed: q['edate']=ed dict.update(edate=ed) ed=datetime.strptime(ed,"%Y-%m-%d") qs=qs.filter(the_filter_date__lte=ed) dict.update(paginate(req,qs)) return ren2res(template,req,dict)
def render(template, req, qs, field='trade_date'): q = QueryDict(mutable=True) dict = {} qs = qs.using(USE_DB).annotate(the_filter_date=F(field)) sd = req.GET.get('sdate') if sd: q['sdate'] = sd dict.update(sdate=sd) sd = datetime.strptime(sd, "%Y-%m-%d") qs = qs.filter(the_filter_date__gte=sd) ed = req.GET.get('edate') if ed: q['edate'] = ed dict.update(edate=ed) ed = datetime.strptime(ed, "%Y-%m-%d") qs = qs.filter(the_filter_date__lte=ed) dict.update(paginate(req, qs)) return ren2res(template, req, dict)
def list(req): if req.method == 'GET': f = File.objects.all() return ren2res("platform/files_list.html", req, paginate(req, f))
def apps(req): if not req.user.is_superuser: return HttpResponseRedirect("/info/not_admin") if req.method == "GET": p = App.objects.filter(hide=False).order_by("id") return ren2res("apps/apps_list.html", req, paginate(req, p))