def CatApi(request): cds = request.GET lastdate = request.GET.get('lastdate',None) if lastdate == '0': lastdate=None (page,offset) = getPageAndOffset(cds) city=request.GET.get('cityid',None) #city=None p={} p['code']=1 p['msg']='Request is successful' #if not lastdate: p['list']=getcat(3,None,city,page,offset) #else: if lastdate: p['count']=getcat(3,lastdate,city) else: p['count']=0 p['lastdate']=0 if p.has_key('list'): if len(p['list'])>0 : if not page>1: p['lastdate']=p['list'][0]['begin_time'] response = json.dumps(p) return HttpResponse(response, mimetype="application/json")
def SearchKey(request): cds = request.GET keyword = cds.get('keywords',None) cityid = cds.get('city',None) p={} p['code']=1 p['cat']=getcat(4) p['city']=getCity() if not keyword: p['msg']='keyword Fail' return HttpResponse(json.dumps(p), content_type="application/json") if len(keyword) > 20: p['msg']='keyword Fail' return HttpResponse(json.dumps(p), content_type="application/json") else: #events_lis = mc.get(keyword+'_search_lis') keyword= keyword.replace('/',' ') keyword= keyword.replace(',',' ') events_lis = cache.get('_'.join(keyword.split())+'_search_lis') p['code']=1 p['msg']='Request is successful' p['keys']=keyword p['list'] =[] if not events_lis: ids=[] for key in keyword.split(): ids.extend(search(key)) if ids: try: tag=NewEventTag.objects.get(name=keyword) tag.hot=tag.hot+1 tag.save() except: try: NewEventTag.objects.create(name=keyword,hot=1) except: pass cache.set('_'.join(keyword.split())+'_search_lis',events_lis,300) events_lis = feelnum.objects.filter(event__old_event__in = ids)#.order_by('district_id='+str(district_id),'event_begin_time') if cityid: try: events_lis = events_lis.filter(event__city__in=cityid.split(',')) except: pass p['list'] = [getevent(item.event.old_event_id) for item in events_lis[0:10]] response = json.dumps(p) return HttpResponse(response, mimetype="application/json")
def HomeApi(request): p={} p['code']=1 p['msg']='Request is successful' p['theme']=getTheme() p['city']=getCity() p['category']=getcat() callback = request.GET.get('callback',None) if callback: response = '%s(%s)' % (callback,json.dumps(p)) else: response = json.dumps(p) return HttpResponse(response, mimetype="application/json")
def SearchKey(request): cds = request.GET keyword = cds.get('keywords',None) cityid = cds.get('city',None) p={} p['code']=1 p['cat']=getcat(4) p['city']=getCity() (page,offset) = getPageAndOffset(cds) start = (page-1)*offset end = page*offset if not keyword and not cityid: p['msg']='keyword Fail' return HttpResponse(json.dumps(p), content_type="application/json") if len(keyword) > 20: p['msg']='keyword Fail' return HttpResponse(json.dumps(p), content_type="application/json") else: #events_lis = mc.get(keyword+'_search_lis') keyword= keyword.replace('/',' ') keyword= keyword.replace(',',' ') events = cache.get('_'.join(keyword.split())+'_search_lis_life') p['code']=1 p['msg']='Request is successful' p['keys']=keyword p['ids']=[] p['list'] =[] if not events: events_lis=feelnum.objects.filter(event__end_time__gt=datetime.date.today()).filter( event__isshow__in=(1,8)).order_by('feelnum') if keyword: or_queries=[] for se in keyword.split(): or_queries += [models.Q(**{orm_lookup: se}) for orm_lookup in ['event__fname__icontains','event__search__icontains']] #arg+=[Q(address__icontains=qu)|Q(title__icontains=qu)|Q(city__district_name__icontains=qu)] if or_queries: events_lis = events_lis.filter(reduce(operator.or_, or_queries)) if cityid: try: events_lis = events_lis.filter(event__city__in=cityid.split(',')) except: pass events = [item.event.old_event_id for item in events_lis] cache.set('_'.join(keyword.split())+'_search_lis_life',events,300) p['list'] = [getevent(item,cds.get('new',False),cds.get('version','')) for item in events[start:end]] ''' if not events_lis: ids=[] for key in keyword.split(): ids.extend(search(key)) if ids: p['ids']=ids try: tag=NewEventTag.objects.get(name=keyword) tag.hot=tag.hot+1 tag.save() except: try: NewEventTag.objects.create(name=keyword,hot=1) except: pass cache.set('_'.join(keyword.split())+'_search_lis_life',events_lis,300) events_lis = NewEventTable.objects.filter(event__old_event__in = ids)#.order_by('district_id='+str(district_id),'event_begin_time') if cityid: try: events_lis = events_lis.filter(event__city__in=cityid.split(',')) except: pass NewAppEvent(None,id,cds.get('new',False)) p['list'] = [getevent(item.event.old_event_id,cds.get('new',False),cds.get('version','')) for item in events_lis[0:10]] ''' response = json.dumps(p) return HttpResponse(response, mimetype="application/json")
def SearchKey(request): cds = request.GET keyword = cds.get('keywords', None) cityid = cds.get('city', None) p = {} p['code'] = 1 p['cat'] = getcat(4) p['city'] = getCity() (page, offset) = getPageAndOffset(cds) start = (page - 1) * offset end = page * offset if not keyword and not cityid: p['msg'] = 'keyword Fail' return HttpResponse(json.dumps(p), content_type="application/json") if len(keyword) > 20: p['msg'] = 'keyword Fail' return HttpResponse(json.dumps(p), content_type="application/json") else: #events_lis = mc.get(keyword+'_search_lis') keyword = keyword.replace('/', ' ') keyword = keyword.replace(',', ' ') events = cache.get('_'.join(keyword.split()) + '_search_lis_life') p['code'] = 1 p['msg'] = 'Request is successful' p['keys'] = keyword p['ids'] = [] p['list'] = [] if not events: events_lis = feelnum.objects.filter( event__end_time__gt=datetime.date.today()).filter( event__isshow__in=(1, 8)).order_by('feelnum') if keyword: or_queries = [] for se in keyword.split(): or_queries += [ models.Q(**{orm_lookup: se}) for orm_lookup in [ 'event__fname__icontains', 'event__search__icontains' ] ] #arg+=[Q(address__icontains=qu)|Q(title__icontains=qu)|Q(city__district_name__icontains=qu)] if or_queries: events_lis = events_lis.filter( reduce(operator.or_, or_queries)) if cityid: try: events_lis = events_lis.filter( event__city__in=cityid.split(',')) except: pass events = [item.event.old_event_id for item in events_lis] cache.set('_'.join(keyword.split()) + '_search_lis_life', events, 300) p['list'] = [ getevent(item, cds.get('new', False), cds.get('version', '')) for item in events[start:end] ] ''' if not events_lis: ids=[] for key in keyword.split(): ids.extend(search(key)) if ids: p['ids']=ids try: tag=NewEventTag.objects.get(name=keyword) tag.hot=tag.hot+1 tag.save() except: try: NewEventTag.objects.create(name=keyword,hot=1) except: pass cache.set('_'.join(keyword.split())+'_search_lis_life',events_lis,300) events_lis = NewEventTable.objects.filter(event__old_event__in = ids)#.order_by('district_id='+str(district_id),'event_begin_time') if cityid: try: events_lis = events_lis.filter(event__city__in=cityid.split(',')) except: pass NewAppEvent(None,id,cds.get('new',False)) p['list'] = [getevent(item.event.old_event_id,cds.get('new',False),cds.get('version','')) for item in events_lis[0:10]] ''' response = json.dumps(p) return HttpResponse(response, mimetype="application/json")