def create_ballot(request): option_id = int(request.GET['option_id']) member = member_util.get_member(request) try: VoteOption.vote_by_member(option_id, member) response = create_response(200) except: response = create_response(500) response.innerErrMsg = unicode_full_stack() return response.get_response()
def get_vote_options(request): try: vote_id = int(request.POST['id']) count = int(request.POST['count']) next_display_index = int(request.POST['item_index']) search = request.POST.get('search', '').strip() poll_options = VoteOption.objects.filter(vote_id=vote_id) if len(search) > 0: poll_options = poll_options.filter(name__contains=search) poll_options = poll_options.order_by('-vote_count') end_index = next_display_index + count response = create_response(200) if poll_options.count() > end_index: response.data.is_has_more = True select_options = poll_options[next_display_index:end_index] response.data.items = __serialize_options_to_jsonarray( select_options) response.data.item_index = end_index else: response.data.is_has_more = False if poll_options.count() == 0: response.data.item_index = 0 response.data.items = __serialize_options_to_jsonarray( poll_options) else: select_options = poll_options[next_display_index:end_index] response.data.item_index = end_index response.data.items = __serialize_options_to_jsonarray( select_options) member = member_util.get_member(request) response.data.is_member_vote = Vote.has_voted_by_member( vote_id, member) return response.get_response() except: response = create_response(500) response.errMsg = u'获取失败' response.innerErrMsg = unicode_full_stack() print response.innerErrMsg return response.get_response()
def show_news_detail(request, newsid): try: news = News.objects.get(id=newsid) #如果是weshop或weizoomjx帐号,title,Description的替换 if news.user.username in NEWS_TEXT_USERNAME: member_username = request.member.username_hexstr.decode( 'hex').decode('utf-8') re_str = ur'\{\{u\}\}|{{u}}' news.title = re.sub(re_str, member_username, news.title) news.text = re.sub(re_str, member_username, news.text) news.summary = re.sub(re_str, member_username, news.summary) # news.title = news.title.replace('{{username}}', member_username) # news.text = news.text.replace('{{username}}', member_username) # 为了支持是否显示点击关注的区域 settings = OperationSettings.get_settings_for_user(news.user.id) request.operation_settings = settings request.user_profile = news.user.get_profile() request.member = get_member(request) nick_name = get_mp_nick_name(news.user.id) #设置分享图片为默认头像 set_share_img(request) except: alert_message = u"显示图文详情异常,素材id:{}, cause:\n{}".format( newsid, unicode_full_stack()) watchdog_alert(alert_message) raise Http404(u'不存在该素材') c = RequestContext( request, { 'page_title': news.title, 'detail': news.text, 'pic_url': news.pic_url, 'is_show_cover_pic': news.is_show_cover_pic, 'date': news.created_at.strftime('%Y-%m-%d'), 'nick_name': nick_name if nick_name else '', 'hide_non_member_cover': True, 'share_page_desc': news.summary, 'share_img_url': news.pic_url }) return render_to_response('material/detail.html', c)
def record_prize(request): webapp_user = request.webapp_user lottery_id = int(request.GET['lottery_id']) prize_id = int(request.GET['prize_id']) prize_position = int(request.GET.get('prize_position', 0)) member = get_member(request) if not member: raise Http404(u"会员信息不存在") lottery = Lottery.objects.get(id=lottery_id) if prize_id: prize = Prize.objects.get(id=prize_id) else: prize = None response = create_response(200) __record_prize(webapp_user, lottery, member, prize, prize_position) return response.get_response()
def get_usage(request): member = get_member(request) lottery_records = Lottery.get_lottery_records(request, member) c = RequestContext( request, { 'page_title': u'我的抽奖', 'lottery_records': lottery_records, 'is_hide_weixin_option_menu': False }) return render_to_response( '%s/lottery/webapp/lotteries.html' % TEMPLATE_DIR, c) ######################################################################## # record_prize: 记录抽奖历史 # ######################################################################## # def record_prize(webapp_user,lottery_id,prize_id,member): # prize_position = 0 # if not member: # raise Http404(u"会员信息不存在") # lottery = Lottery.objects.get(id=lottery_id) # if prize_id: # prize = Prize.objects.get(id=prize_id) # else: # prize = None # __record_prize(webapp_user, lottery, member, prize, prize_position) # ######################################################################## # # __record_prize: 记录抽奖历史内部操作 # ######################################################################## # def __record_prize(webapp_user, lottery, member, prize, prize_position=0): # prize_money = 0 # #减积分 # if lottery.expend_integral > 0: # webapp_user.consume_integral(lottery.expend_integral, u'参与抽奖,花费积分') # if not prize: # LotteryRecord.objects.create(owner=lottery.owner, member=member, lottery=lottery, lottery_name=lottery.name, prize_type=0, prize_level=0, # prize_name=u'谢谢参与', is_awarded=True, prize_number=time.time(), prize_detail='', prize_money=prize_money) # return None # relation = LotteryHasPrize.objects.get(lottery=lottery, prize=prize) # #实物 # if relation.prize_type == 0: # is_awarded = False # prize_detail = relation.prize_source # #优惠券 # elif relation.prize_type == 1: # is_awarded = True # rule_id = relation.prize_source # # coupons = create_coupons(lottery.owner, rule_id, 1, member.id) # # prize_detail = coupons[0].coupon_id # # prize_money = coupons[0].money # coupon, msg = consume_coupon(lottery.owner.id, rule_id, member.id) # if coupon: # prize_detail = coupon.coupon_id # prize_money = coupon.money # else: # watchdog_notice('微信抽奖失败,错误原因:%s,owner.id:%s:rule.id:%s,member.id' # % (msg, lottery.owner.id, rule_id, member.id)) # LotteryRecord.objects.create(owner=lottery.owner, member=member, lottery=lottery, lottery_name=lottery.name, prize_type=0, prize_level=0, # prize_name=u'谢谢参与', is_awarded=True, prize_number=time.time(), prize_detail='', prize_money=prize_money) # return None # #兑换码 # elif relation.prize_type == 2: # is_awarded = True # prize_detail = relation.prize_source # #积分 # elif relation.prize_type == 3: # is_awarded = True # prize_detail = relation.prize_source # #增加积分 # webapp_user.consume_integral(-int(prize_detail), u'参与抽奖,赢得积分') # from hashlib import md5 # cur_time = str(time.time()) # prize_number = md5(cur_time).hexdigest()[10:-10] #生成一个12位字符串 # LotteryRecord.objects.create(owner=lottery.owner, member=member, lottery=lottery, lottery_name=lottery.name, prize_type=relation.prize_type, prize_level=prize.level, # prize_name=prize.name, is_awarded=is_awarded, prize_number=prize_number, prize_detail=prize_detail, prize_money=prize_money, prize_position=prize_position) # #更改奖品个数 # Prize.decrease_count(prize, 1) # return None
def get_member_activites(request): profile = request.user_profile webapp_user = request.webapp_user member = member_util.get_member(request) activities_items = [] all_lotteries_items = [] #活动 events = event_models.eventParticipance.objects.filter( member_id=member.id).order_by('-created_at') events_items = [] for event in events: try: event_id = event.belong_to event_details = event_models.event.objects.get(id=event_id) events_items.append({ 'id': str(event_id), 'name': event_details.name, 'url': '/m/apps/event/m_event/?webapp_owner_id=%d&id=%s' % (event_details.owner_id, str(event_id)), 'participant_time': event.created_at.strftime('%m月%d日'), 'activity_type_name': u'活动报名' }) except: pass #投票 votes = vote_models.voteParticipance.objects.filter( member_id=member.id).order_by('-created_at') votes_items = [] for vote in votes: try: vote_id = vote.belong_to vote_details = vote_models.vote.objects.get(id=vote_id) votes_items.append({ 'id': str(vote_id), 'name': vote_details.name, 'url': '/m/apps/vote/m_vote/?webapp_owner_id=%d&id=%s' % (vote_details.owner_id, str(vote_id)), 'participant_time': vote.created_at.strftime('%m月%d日'), 'activity_type_name': u'微信投票' }) except: pass #调研 surveies = survey_models.surveyParticipance.objects.filter( member_id=member.id).order_by('-created_at') surveies_items = [] for survey in surveies: try: survey_id = survey.belong_to survey_details = survey_models.survey.objects.get(id=survey_id) surveies_items.append({ 'id': str(survey_id), 'name': survey_details.name, 'url': '/m/apps/survey/m_survey/?webapp_owner_id=%d&id=%s' % (survey_details.owner_id, str(survey_id)), 'participant_time': survey.created_at.strftime('%m月%d日'), 'activity_type_name': u'用户调研' }) except: pass #抽奖 lotteries = lottery_models.lottoryRecord.objects.filter( member_id=member.id).order_by('-created_at') lotteries_items = [] for lottery in lotteries: try: lottery_id = lottery.belong_to lottery_details = lottery_models.lottery.objects.get(id=lottery_id) lotteries_items.append({ 'id': str(lottery_id), 'name': lottery_details.name, 'url': '/m/apps/lottery/m_lottery/?webapp_owner_id=%d&id=%s' % (lottery_details.owner_id, str(lottery_id)), 'participant_time': lottery.created_at.strftime('%m月%d日'), 'type': u'抽奖' }) except: pass # 幸运码抽奖 exlotteries = exlottery_models.ExlottoryRecord.objects.filter( member_id=member.id).order_by('-created_at') exlotteries_items = [] for exlottery in exlotteries: try: exlottery_id = exlottery.belong_to code = exlottery.code exlottery_details = exlottery_models.Exlottery.objects.get( id=exlottery_id) exlotteries_items.append({ 'id': str(exlottery_id), 'name': exlottery_details.name, 'url': '/m/apps/exlottery/m_exlottery/?webapp_owner_id=%d&id=%s&ex_code=%s' % (exlottery_details.owner_id, str(exlottery_id), code), 'participant_time': exlottery.created_at.strftime('%m月%d日'), 'type': u'幸运码抽奖' }) except: pass # 砸金蛋 eggs = egg_models.EggRecord.objects.filter( member_id=member.id).order_by('-created_at') eggs_items = [] for egg in eggs: try: egg_id = egg.belong_to egg_details = egg_models.Egg.objects.get(id=egg_id) eggs_items.append({ 'id': str(egg_id), 'name': egg_details.name, 'url': '/m/apps/egg/m_egg/?webapp_owner_id=%d&id=%s' % (egg_details.owner_id, str(egg_id)), 'participant_time': egg.created_at.strftime('%m月%d日'), 'type': u'砸金蛋' }) except: pass # 刮刮卡 scratches = scratch_models.ScratchRecord.objects.filter( member_id=member.id).order_by('-created_at') scratches_items = [] for scratch in scratches: try: scratch_id = scratch.belong_to scratch_details = scratch_models.Scratch.objects.get(id=scratch_id) scratches_items.append({ 'id': str(scratch_id), 'name': scratch_details.name, 'url': '/m/apps/scratch/m_scratch/?webapp_owner_id=%d&id=%s' % (scratch_details.owner_id, str(scratch_id)), 'participant_time': scratch.created_at.strftime('%m月%d日'), 'type': u'刮刮卡' }) except: pass # 扫码抽奖 scanlotteries = scanlottery_models.ScanlotteryRecord.objects.filter( member_id=member.id).order_by('-created_at') scanlotteries_items = [] for scanlottery in scanlotteries: try: scanlottery_id = scanlottery.belong_to scanlottery_details = scanlottery_models.Scanlottery.objects.get( id=scanlottery_id) scanlotteries_items.append({ 'id': str(scanlottery_id), 'name': scanlottery_details.name, 'url': '/m/apps/scanlottery/m_scanlottery/?webapp_owner_id=%d&id=%s' % (scanlottery_details.owner_id, str(scanlottery_id)), 'participant_time': scanlottery.created_at.strftime('%m月%d日'), 'type': u'扫码抽奖' }) except: pass for events_item in events_items: activities_items.append(events_item) for votes_item in votes_items: activities_items.append(votes_item) for surveies_item in surveies_items: activities_items.append(surveies_item) #微信抽奖&幸运码抽奖&砸金蛋&刮刮卡&扫码抽奖(add by sunhan 2016-7-29) for lotteries_item in lotteries_items: all_lotteries_items.append(lotteries_item) for exlotteries_item in exlotteries_items: all_lotteries_items.append(exlotteries_item) for eggs_item in eggs_items: all_lotteries_items.append(eggs_item) for scratches_items in scratches_items: all_lotteries_items.append(scratches_items) for scanlotteries_item in scanlotteries_items: all_lotteries_items.append(scanlotteries_item) c = RequestContext( request, { 'page_title': u'我的活动列表', 'activities_items': sorted(activities_items, key=operator.itemgetter('participant_time'), reverse=True), 'all_lotteries_items': sorted(all_lotteries_items, key=operator.itemgetter('participant_time'), reverse=True), 'is_hide_weixin_option_menu': True }) return render_to_response('activity/webapp/my_activities.html', c)