def showQ(request,query=False,template_name='q_showEvent.html'): event={} if query.isdigit(): event= NewAppEvent(False,int(query),request.GET.get('new',False)) if not event.has_key('isshow'): return render_to_response('not.html',{'error_msg':u'没有该活动 ' }) else: if not event['isshow'] in [1,8]: return render_to_response('not.html',{'error_msg':u'活动没有发布' }) note=None for con in event['event_content']: if con[0] in [u'购买须知']: note=con break body={'note':note, 'event_id':event['event_id'] } return render_to_response(template_name,body,context_instance=RequestContext(request))
def price_show(self, obj): if obj.event.old_event_id: ev = NewAppEvent(None, obj.event.old_event_id) else: ev = NewAppEvent(None, obj.event.id) return '<a href="/admin/new_event/neweventpriceunit/?q=%s" target="_blank" >%s</a>' % ( ev['id'], ev['event_price'])
def showQ(request, query=False, template_name='q_showEvent.html'): event = {} if query.isdigit(): event = NewAppEvent(False, int(query), request.GET.get('new', False)) if not event.has_key('isshow'): return render_to_response('not.html', {'error_msg': u'没有该活动 '}) else: if not event['isshow'] in [1, 8]: return render_to_response('not.html', {'error_msg': u'活动没有发布'}) note = None for con in event['event_content']: if con[0] in [u'购买须知']: note = con break body = {'note': note, 'event_id': event['event_id']} return render_to_response(template_name, body, context_instance=RequestContext(request))
def test_xml(id): event = {} ca = NewAppEvent(None,id) cont = ca['event_content'][0][1] cont = cont.replace('\n', '').replace('\r', '').replace('\r\n', '') event['mobileU'] = cont soup = BeautifulSoup(cont) # remove tag and its contents soup = unwrap_tag(soup, ['br', 'span','pre']) # rename tag: div -> p for i in soup.find_all('div'): i.name = 'p' # deal with the 'style' attributes in <img> tag_img = soup.find_all('img') for i in tag_img: try: couple = get_style_couple(i['style'].replace('px', '')) for attr, val in couple: i[attr] = val del i['style'] except KeyError: pass #soup_fmt = soup.prettify(formatter=None) #soup_fmt = replaceCharEntity(str(soup)) #pattern = re.compile(r"<p>img\d+\</p>") #soup=replaceCharEntity(str(soup)) #soup_fmt = re.sub(ur"<p>img\d+\</p>" , find_img, soup ) #try: soup_fmt = re.sub(ur"<p>img\d+\</p>" , find_img,replaceCharEntity(str(soup)) ) #except: # soup_fmt =replaceCharEntity(str(soup)) soup_fmt = '<body>' + soup_fmt + '</body>' # convert <img.../> tag into <img...></img> soup_fmt = soup_fmt.replace('/>', '></img>') #soup_fmt = re.sub('<img[^>]+>', lambda x: x.group() + '</img>', soup_fmt) event['mobileURL'] = soup_fmt.replace('\r', '').replace('\n', '') return event
def showCont(request, query=False, template_name='s_showEvent.html'): event = {} if query.isdigit(): event = NewAppEvent(False, int(query), request.GET.get('new', False)) ''' if not event.has_key('isshow'): return render_to_response('not.html',{'error_msg':u'没有该活动 ' }) else: if not event['isshow'] in [1,8]: return render_to_response('not.html',{'error_msg':u'活动没有发布' }) ''' note = [] for i in range(len(event['event_content'])): if i is 0: cont = event['event_content'][i][1].replace('<br>', '').replace( '<br />', '') cont = re.sub(ur"[\u200b]", "", cont) i = repr(cont).find('200b') if i > 0: break cont = eval(repr(cont).replace('\u200b', '').replace('200B', '')) #event['event_content'][i]=(event['event_content'][i][0],cont) note.append((event['event_content'][i][0], cont)) elif event['event_content'][i][0] in [u'行程安排']: note.append(event['event_content'][i]) body = { 'note': note, 'event_id': event['event_id'], 'event_name': event['title'], 'event_tag': ' '.join(event['event_tag']), 'event_img': event['event_img'], } return render_to_response(template_name, body, context_instance=RequestContext(request))
def more(self, event_id, district_id, new): more = [] try: mor = random.sample(event_city_cat(district_id, None, new), 5) except: mor = event_city_cat(district_id, None, new) for ev in mor: if ev != event_id: e = NewAppEvent(None, ev) if e: even = { 'id': e['event_id'], 'title': e['title'], 'price': e['app_price'], 'imgs': e['img_s'] } more.append(even) if len(more) > 3: break return more
def submitOrder_with_coupon(request, coupon_record): if request.method != 'GET': return HttpResponse(json.dumps({"code":0,"msg":"Only GETs are allowed","list":[]}), content_type="application/json") cds = request.GET price =cds['price'] price = round( float(price),2) eventId = int(cds['eventid']) event=NewAppEvent(None,eventId) ''' pr_ok=False for i in range(len(event['price_unit_info'])): pr1=round(float(event['price_unit_info'][i]['price'])*float(event['price_unit_info'][i]['discount']),1) if price is pr1: pr_ok=True break if not pr_ok: return HttpResponse(json.dumps({"code":0,"msg":"price is wrong %s,%s" % (price,pr1),"list":[]}), content_type="application/json") ''' import random number = '%s%s'%(int(time.time()),random.randint(100,1000)) if int(cds['amount']) < 1: return HttpResponse(json.dumps({"code":0,"msg":"amount must be bigger than 1","list":[]}), content_type="application/json") totalpay = float(price)*int(cds['amount']) #print cds['payMode'] # 使用了优惠券 totalpay = coupon_record.cost if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip = request.META['HTTP_X_FORWARDED_FOR'] else: ip = request.META['REMOTE_ADDR'] userid = cds.get('userid') if not userid: userid = 0 else: userid = int(userid) try: NewOrder.objects.create( order_number=number, order_user_name=cds.get('name',''), order_tel = cds.get('phone',''), order_email = cds.get('email',''), order_totalpay = totalpay, order_price = float(price), order_amount = cds['amount'], order_address = cds.get('address',''), order_payment = 'alipay', order_telphone = cds.get('phone',''), order_pay_status = 0, order_status = 0, event_id = eventId, event_name = event['title'], city_title = event['district_name'], order_reg_fields = 0, order_addtime = time.time(), order_addip = ip, order_text = cds.get('message',''), order_userid = userid, event_to=4, ) except: return HttpResponse(json.dumps({"code":0,"msg":"err","list":[]}), content_type="application/json") subject = '来自闲时app的订单通知.客户:%s,电话:%s'%(cds.get('name','').encode('utf-8'),cds.get('mobilphone','').encode('utf-8')) content = '点单号:%s\n总价:%s\n活动链接:http://www.huodongjia.com/event-%s.html'%(number,totalpay,eventId) content += dic2text(cds) sendMail(subject,content) order = { 'price':price, 'order_id':number, 'user_id':cds.get('userid',''), 'addtime':int(time.time()), 'name':cds.get('name',u'匿名'), 'phone':cds['phone'], 'address':cds.get('address',''), 'message':cds.get('message',''), "total":totalpay, "amount":cds['amount'], "order_pay_status":u"未付款", "order_status":u"未处理", } # 记录order_number coupon_record.order_id = number coupon_record.save() eventdic = getevent(eventId) return HttpResponse(json.dumps({"code":1,"msg":u"下单成功","data":{'order':order,'event':eventdic}}), content_type="application/json")
def getevent(self,id=None,new=False): if not id: return {} event={} ca=NewAppEvent(None,id,new) #print ca event['id']=ca['event_id'] #event['isurl']=True if ca['isshow']==8 else False event['title']=ca['title'] event['imgs']=ca['img_s'] event['cat']={'name':ca['cat_name'] if ca['cat_name'] else '', 'id':ca['catid'] if ca['catid'] else '', 'img':ca['cat_img']['img'] if ca['cat_img'] else '' } #event['cat_name']=ca['cat_name'] if ca['cat_name'] else '' #event['catid']=ca['catid'] if ca['catid'] else '' #event['cat_img']=ca['cat_img'] if ca['cat_img'] else '' if ca.has_key('feeltitle'): event['feeltitle']=ca['feeltitle'] if ca['feeltitle'] else '' else: event['feeltitle']='' event['mobileURL']='http://m.huodongjia.com/app-%s.html'%ca['event_id'] event['questionURL']='http://m.huodongjia.com/q-%s.html'%ca['event_id'] event['shareURL']='http://m.huodongjia.com/share-%s.html'%ca['event_id'] #des1 = ''.join(BeautifulSoup(ca['des']).findAll(text=True)) #des1 = ''.join(replaceCharEntity(des1)) event['tag']=','.join(ca['event_tag']) event['price']=ca['app_price'] event['feel']=ca['feel'] event['feelnum']=ca['feelnum'] if ca['feelnum'] else 0 event['address']=ca['event_address'] event['position']=ca['position'] event['startdate']=ca['startdate'] event['enddate']=ca['enddate'] event['islongtime']=ca['event_islongtime'] event['city']=ca['district_name'] event['detail']='' try: event['detail']=ca['detail'] except: pass if not event['detail']: event['detail']=ca['des'] if not event['detail']: i=1 str_h= str_html(ca['event_content'][0][1]) for de in str_h.split('\n'): if event['detail']: event['detail']+='\r\n' te= BeautifulSoup(de).text if te and len(te)>15: i+=1 event['detail'] += '%s' % te if i>3: break event['detail']=event['detail'].replace('\r\n\r\n','\r\n')\ .replace('\n\n\n\n','\r\n').replace('\n\n\n','\r\n').replace('\n\n','\r\n') #event['detail']= BeautifulSoup(ca['event_content'][0][1]).text[0:250] for con in ca['event_content']: if con[0] in [u'购买须知']: event['note']=con[1] break try: event['note']=str_html(event['note']).replace('\r\n','') event['note']=BeautifulSoup(event['note']).text o=event['note'].find(u'。') if o>0: event['note']=event['note'][:o] else: no=event['note'].split(u',') if len(no)>2: event['note']='%s%s' % (u','.join(no[:2]),'...') except: event['note']='' event['comment']={} try: com=UserEventMessage.objects.filter(event_id=ca['event_id']).order_by('id')[0] event['comment']['id']=com.id event['comment']['content']=com.message.txt event['comment']['date']=time.mktime(com.end_time.timetuple()) event['comment']['score']=0 event['comment']['imgs']=[] event['comment']['user']={'id':com.user.user_id,'name':com.user.user_name} except: pass event['commentTotol']={} event['more']=[] for ev in event_city_cat(ca['district_id']): if ev!=event['id']: e=NewAppEvent(None,ev) even={'id':e['event_id'],'title':e['title'],'price':e['app_price'],'imgs':e['img_s']} event['more'].append(even) if len(event['more'])>4: break return event
def getevent(self, id=None, new=False): if not id: return {} event = {} ca = NewAppEvent(None, id, new) #print ca event['eid'] = ca['id'] event['id'] = ca['event_id'] #event['isurl']=True if ca['isshow']==8 else False event['title'] = ca['title'] event['imgs'] = ca['img_s'] event['cat'] = { 'name': ca['cat_name'] if ca['cat_name'] else '', 'id': ca['catid'] if ca['catid'] else '', 'img': ca['cat_img']['img'] if ca['cat_img'] else '' } #event['cat_name']=ca['cat_name'] if ca['cat_name'] else '' #event['catid']=ca['catid'] if ca['catid'] else '' #event['cat_img']=ca['cat_img'] if ca['cat_img'] else '' if ca.has_key('feeltitle'): event['feeltitle'] = ca['feeltitle'] if ca['feeltitle'] else '' else: event['feeltitle'] = '' event['mobileURL'] = 'http://life.huodongjia.com/app/app-%s.html' % ca[ 'event_id'] event['questionURL'] = 'http://life.huodongjia.com/app/q-%s.html' % ca[ 'event_id'] event[ 'shareURL'] = 'http://life.huodongjia.com/app/share-%s.html' % ca[ 'event_id'] #des1 = ''.join(BeautifulSoup(ca['des']).findAll(text=True)) #des1 = ''.join(replaceCharEntity(des1)) event['tag'] = ','.join(ca['event_tag']) event['price'] = ca['app_price'] event['feel'] = ca['feel'] event['feelnum'] = ca['feelnum'] if ca['feelnum'] else 0 event['address'] = ca['event_address'] if ca['event_address'] else ca[ 'event_venue'] event['position'] = ca['position'] event['startdate'] = ca['startdate'] event['enddate'] = ca['enddate'] event['islongtime'] = ca['event_islongtime'] event['city'] = ca['district_name'] event['detail'] = '' try: event['detail'] = ca['detail'] except: pass if not event['detail']: event['detail'] = ca['des'] if not event['detail']: i = 1 try: str_h = str_html(ca['event_content'][0][1]) except: str_h = '' for de in str_h.split('\n'): if event['detail']: event['detail'] += '\r\n' te = BeautifulSoup(de).text if te and len(te) > 15: i += 1 event['detail'] += '%s' % te if i > 3: break event['detail']=event['detail'].replace('\r\n\r\n','\r\n')\ .replace('\n\n\n\n','\r\n').replace('\n\n\n','\r\n').replace('\n\n','\r\n') #event['detail']= BeautifulSoup(ca['event_content'][0][1]).text[0:250] for con in ca['event_content']: if con[0] in [u'购买须知']: event['note'] = con[1] break try: event['note'] = str_html(event['note']).replace('\r\n', '') event['note'] = BeautifulSoup(event['note']).text o = event['note'].find(u'。') if o > 0: event['note'] = event['note'][:o] else: no = event['note'].split(u',') if len(no) > 2: event['note'] = '%s%s' % (u','.join(no[:2]), '...') except: event['note'] = '' event['comment'] = {} try: com = UserEventMessage.objects.filter( event_id=ca['event_id']).order_by('id')[0] event['comment']['id'] = com.id event['comment']['content'] = com.message.txt event['comment']['date'] = time.mktime(com.end_time.timetuple()) event['comment']['score'] = 0 event['comment']['imgs'] = [] event['comment']['user'] = { 'id': com.user.user_id, 'name': com.user.user_name } except: pass event['commentTotol'] = {} event['more'] = self.more(event['id'], ca['district_id'], new) return event
def getevent_2_0(self,id=None,new=False): if not id: return {} event={} ca=NewAppEvent(None,id,new) #print ca event['eid']=ca['id'] event['id']=ca['event_id'] event['isurl']=True if ca['isshow']==8 else False event['title']=ca['title'] event['imgs']=ca['img_s'] event['adurl']=ca['event_img'] event['sponsor']=ca['sponsor'][0] if len(ca['sponsor'])>0 else {} #del event['imgs'][0] event['cat']={'name':ca['cat_name'] if ca['cat_name'] else '', 'id':ca['catid'] if ca['catid'] else '', 'img':ca['cat_img']['img'] if ca['cat_img'] else '' } #event['cat_name']=ca['cat_name'] if ca['cat_name'] else '' #event['catid']=ca['catid'] if ca['catid'] else '' #event['cat_img']=ca['cat_img'] if ca['cat_img'] else '' if ca.has_key('feeltitle'): event['feeltitle']=ca['feeltitle'] if ca['feeltitle'] else '' else: event['feeltitle']='' #des1 = ''.join(BeautifulSoup(ca['des']).findAll(text=True)) #des1 = ''.join(replaceCharEntity(des1)) event['tag']=','.join(ca['event_tag']) event['price']=ca['app_price'] event['feel']=ca['feel'] event['feelnum']=ca['feelnum'] if ca['feelnum'] else 0 event['address']=ca['event_address'] if ca['event_address'] else ca['event_venue'] event['position']=ca['position'] event['startdate']=ca['startdate'] event['enddate']=ca['enddate'] event['islongtime']=ca['event_islongtime'] event['city']=ca['district_name'] event['detail']='' try: event['detail']=ca['detail'] except: pass if not event['detail']: event['detail']=ca['des'] if not event['detail']: try: i=1 str_h= str_html(ca['event_content'][0][1]) for de in str_h.split('\n'): if event['detail']: event['detail']+='\r\n' te= BeautifulSoup(de).text if te and len(te)>15: i+=1 event['detail'] += '%s' % te if i>3: break event['detail']=event['detail'].replace('\r\n\r\n','\r\n')\ .replace('\n\n\n\n','\r\n').replace('\n\n\n','\r\n').replace('\n\n','\r\n') except: event['detail']='' #event['detail']= BeautifulSoup(ca['event_content'][0][1]).text[0:250] cont='' for con in ca['event_content']: if con[0] in [u'购买须知',u'相关介绍']: if con[0]==u'购买须知': event['note']=con[1] note=event['note'] elif con[0]==u'相关介绍': cont=con[1] #break try: event['note']=str_html(event['note']).replace('\r\n','') event['note']=BeautifulSoup(event['note']).text o=event['note'].find(u'。') if o>0: event['note']=event['note'][:o] else: no=event['note'].split(u',') if len(no)>2: event['note']='%s%s' % (u','.join(no[:2]),'...') except: event['note']='' note='' event['comment']={} try: com=UserEventMessage.objects.filter(event_id=ca['event_id']).order_by('id')[0] event['comment']['id']=com.id event['comment']['content']=com.message.txt event['comment']['date']=time.mktime(com.end_time.timetuple()) event['comment']['score']=0 event['comment']['imgs']=[] event['comment']['user']={'id':com.user.user_id,'name':com.user.user_name} except: pass event['commentTotol']={} if not cont: cont=ca['event_content'][0][1] #cont = cont.replace('\n','').replace('\r','').replace('<br>','').replace('<br/>','').replace('<br />','') cont = cont.replace('\n','').replace('\r','').replace('\r\n', '') try: #note=note.strip().replace('\n','').replace('\r','').replace('<br>','').replace('<br/>','').replace('<br />','') note=note.strip().replace('\n','').replace('\r','').replace(u'【', '').replace(u'】', '') except: note='' if event['isurl']: event['mobileURL'] = 'http://life.huodongjia.com/app/app-%s.html'%ca['event_id'] event['questionURL']='http://life.huodongjia.com/app/q-%s.html'%ca['event_id'] else: #event['mobileURL']=gettext(find_img_tag(cont)) #'http://m.huodongjia.com/app-%s.html'%ca['event_id'] #event['questionURL']=gettext(find_img_tag(note)) event['mobileURL'] = xml_fmt_convert(cont) event['questionURL'] = xml_fmt_convert(note) event['shareURL']='http://life.huodongjia.com/app/share-%s.html'%ca['event_id'] event['more']=self.more(event['id'], ca['district_id'], new) return event