def singer_get(req): back = {'state':'ok'} q = req.GET or req.POST f = int(q.get('f','0')) l = int(q.get('l','14')) kwd = q.get('kwd') if kwd: lk = len(kwd) if lk==2: rs = Singer.objects.filter(singer_nationality__contains=kwd) if lk==3: sex = kwd[2:3] nationality = kwd[:2] rs = Singer.objects.filter(singer_sex=sex,singer_nationality__contains=nationality) if lk==4: rs = Singer.objects.filter(singer_style__contains=kwd) else: name = q.get('name') if name: rs = Singer.objects.filter(singer_name=name) else: rs = Singer.objects.all() back['count'] = rs.count() back['data'] = [{'pk':m.pk,'name':m.singer_name,'sex':m.singer_sex,'nationality':m.singer_nationality,'style':m.singer_style,'album':m.singer_album,'song':m.singer_song,'heat':m.singer_heat} for m in rs[f:f+l]] return to_json(back)
def remove(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') Hcountry.objects.filter(pk=id).delete() back['id'] = id return to_json(back)
def check(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') check = q.get('check') Contact.objects.filter(pk=id).update(check=check) back['back'] = check return to_json(back)
def search(req): back = {'state':'ok'} q = req.GET or req.POST kwd = q.get('kwd') if Song.objects.filter(name=kwd): back['data'] = 1 else: back['data'] = 2 return to_json(back)
def login(req): back = {'status':'ok'} seoTitle='后台登录' uname=req.GET.get('uname') pwd=req.GET.get('pwd') if uname=='tml' and pwd=='tml': req.session['uname']=uname back['uname'] = uname return to_json(back)
def song_irecommend(req): back = {'state':'ok'} q = req.GET or req.POST f = int(q.get('f','0')) l = int(q.get('l','10')) rs = IRecommend.objects.all().order_by('-iRecommend_similarity') back['count'] = rs.count() back['data'] = [{'pk':m.pk,'name':m.iRecommend_song,'singer':m.iRecommend_singer,'album':m.iRecommend_album,'heat':m.heat} for m in rs[f:f+l]] return to_json(back)
def get(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') if id: rr = Hcountry.objects.filter(pk=id) else: rr = Hcountry.objects.all() r = [{'id':m.pk,'name':m.name,'rank':m.rank} for m in rr] back['data'] = r return to_json(back)
def singer_chart(req): back = {'state':'ok'} singer = '陈奕迅' nodes = [{'category':0, 'name': singer, 'value' : 350}] links = [] r = Singers.objects.filter(singer=singer).order_by('-simi')[:18] for j in r: nodes.append({'category':0, 'name': j.simiSinger, 'value' : j.simi}) links.append({'source' : j.simiSinger, 'target' : singer, 'weight' : j.simi, 'name': '歌手'}) back['data'] = {'nodes':nodes,'links':links} return to_json(back)
def get(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') if id: rr = News.objects.filter(pk=id) else: rr = News.objects.all() r = [{'id':m.pk,'name':m.name,'pdate':m.pdate,'abs':m.abs,'rank':m.rank,'text':m.text,'pic':m.pic} for m in rr] back['data'] = r return to_json(back)
def get(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') if id: rr = lastPage.objects.filter(pk=id) else: rr = lastPage.objects.all() r = [{'id':m.pk,'from_user':m.from_user,'to_user':m.to_user,'page':m.page,'did':m.did} for m in rr] back['data'] = r return to_json(back)
def song_get(req): back = {'state':'ok'} q = req.GET or req.POST f = int(q.get('f','0')) l = int(q.get('l','10')) name = q.get('name') if name: objs = Song.objects.filter(name=name) else: objs = Song.objects.all().order_by('-heat')[f:f+l] back['data'] = [{'pk':m.pk,'name':m.name,'singer':m.singer,'album':m.album,'language':m.language,'style':m.style,'heat':m.heat,'tag':m.theme_tag} for m in objs] return to_json(back)
def news_get(req): back = {'state':'ok'} q = req.GET or req.POST f = int(q.get('f','0')) l = int(q.get('l','14')) pk = q.get('pk') if pk: objs = News.objects.filter(pk=pk) else: objs = News.objects.all().order_by('-date')[f:f+l] back['data'] = [{'pk':m.pk,'title':m.title,'datefull':m.date.strftime('%Y-%m-%d %H:%M:%S'),'date':m.date.strftime('%Y-%m-%d'),'abstr':m.abstr,'singer':m.singer} for m in objs] return to_json(back)
def get(req): back = {'status':'ok'} q = req.GET or req.POST check = q.get('check') id = q.get('id') if id: rr = Contact.objects.filter(pk=id) else: rr = Contact.objects.filter(check=check) r = [{'id':m.pk,'name':m.name,'check':m.check,'sex':m.sex or '','email':m.email or '','phone':m.phone,'advice':m.advice or '','reply':m.reply or '','time':m.time} for m in rr] back['data'] = r return to_json(back)
def knowledge_get(req): back = {'status':'ok'} q = req.GET or req.POST kwd = q.get('kwd') fromNum = int(q.get('fromNum',0)) limitNum = int(q.get('limitNum',20)) cur = connection.cursor() if kwd: obj = News.objects.filter(title__contains=kwd) else: obj = News.objects.all() back['data'] = [{'pk':m.pk,'title':m.title,'topics':getTpcs(cur,m.pk),'url':m.url,'pubDate':m.pubDate.strftime('%Y-%m-%d')} for m in obj[fromNum:fromNum+limitNum]] back['count'] = obj.count() return to_json(back)
def save(req): q = req.GET or req.POST name = q.get('name') name_en = q.get('name_en') num = q.get('num') tp = q.get('tp') p = q.get('p') pid = getId(p) if name: kwargs = {'name':name,'name_en':name_en,'code':'1000'+num,'tp':tp,'pid':pid} if not Citys.objects.filter(**kwargs): c = Citys(**kwargs) c.save() return to_json(name)
def update(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') name = q.get('name') rank = q.get('rank') kwargs = {'name':name,'rank':rank} if id: Hcountry.objects.filter(pk=id).update(**kwargs) back['id'] = id else: h = Hcountry(**kwargs) h.save() back['id'] = h.id return to_json(back)
def get(req): back = {'status':'ok'} q = req.GET or req.POST hid = q.get('hid') id = q.get('id') if id: rr = Success.objects.filter(pk=id) else: if hid: rr = Success.objects.filter(hid=hid) else: rr = Success.objects.all() r = [{'id':m.pk,'name':m.name,'pdate':m.pdate,'abs':m.abs,'rank':m.rank,'text':m.text,'pic':m.pic,'hid':m.hid,'hname':getHospitalAttr(m.hid)} for m in rr] back['data'] = r return to_json(back)
def contactData(req): back = {'status':'ok'} if req.META.has_key('HTTP_X_FORWARDED_FOR'): ip = request.META['HTTP_X_FORWARDED_FOR'] else: ip = req.META['REMOTE_ADDR'] q = req.GET or req.POST if Contact.objects.filter(ip=ip,check=0): back['status'] = 'error' back['msg'] = '您已提交信息,不能重复提交,我们会尽快跟您联系' else: c = Contact(name=q.get('name') or None,sex=q.get('sex') or None,email=q.get('email') or None,phone=q.get('phone') or None,advice=q.get('advice') or None,reply=q.get('reply') or None,ip=ip) c.save() back['msg'] = '您已提交信息,我们会尽快跟您联系' back['id'] = c.id return to_json(back)
def update(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') from_user = q.get('from_user') to_user = q.get('to_user') page = q.get('page') did = q.get('did') kwargs = {'from_user':from_user,'to_user':to_user,'page':page,'did':did} if id: lastPage.objects.filter(pk=id).update(**kwargs) back['id'] = id else: h = lastPage(**kwargs) h.save() back['id'] = h.id return to_json(back)
def update(req): back = {'status':'ok'} q = req.GET or req.POST id = q.get('id') name = q.get('name') pdate = q.get('pdate') abs = q.get('abs') rank = q.get('rank') text = q.get('text') pic = q.get('pic') kwargs = {'name':name,'pdate':pdate,'abs':abs,'rank':rank,'text':text,'pic':pic} if id: News.objects.filter(pk=id).update(**kwargs) back['id'] = id else: h = News(**kwargs) h.save() back['id'] = h.id return to_json(back)
def knowledge_get(req): back = {'status': 'ok'} q = req.GET or req.POST kwd = q.get('kwd') fromNum = int(q.get('fromNum', 0)) limitNum = int(q.get('limitNum', 20)) cur = connection.cursor() if kwd: obj = News.objects.filter(title__contains=kwd) else: obj = News.objects.all() back['data'] = [{ 'pk': m.pk, 'title': m.title, 'topics': getTpcs(cur, m.pk), 'url': m.url, 'pubDate': m.pubDate.strftime('%Y-%m-%d') } for m in obj[fromNum:fromNum + limitNum]] back['count'] = obj.count() return to_json(back)
def getLocation(req): back = {'status':'ok'} q = req.GET or req.POST spt = q.get('spt',u'到') kwd = q.get('kwd') if kwd: kwds = kwd.split(spt) if len(kwds)==2: back['from'] = getloc(kwds[0]) back['to'] = getloc(kwds[1]) else: w = getloc(kwds[0]) if w: back['from'] = w else: back['msg']='no city' else: back['status']='error' back['msg']='need kwd' return to_json(back)
def index(req): return to_json('hello word')
def logout(req): back = {'status':'ok'} req.session.delete() return to_json(back)
def song_chart(req): back = {'state':'ok'} r = Songs.objects.all().order_by('-sim')[:9] back['data'] = {'y':[m.simiSong for m in r][::-1],'s':[n.sim for n in r][::-1]} return to_json(back)
def get(req): back = {'state': 'ok'} req.session['user_token'] = 1 back['user_token'] = req.session['user_token'] return to_json(back)
def reg(req): back = {'status':'ok'} return to_json(back)