예제 #1
0
파일: views.py 프로젝트: chengdg/weizoom
def edit_red_envelope_view(request, id):
	if int(id) > 0:
		try:
			red_envelope = RedEnvelope.objects.get(id=id)
		except:
			raise Http404('不存在该微信红包')
		
		relations = RedEnvelopeHasPrize.objects.filter(red_envelope=red_envelope)
		prize_ids = [r.prize_id for r in relations]
		prizes = Prize.objects.filter(id__in=prize_ids)
		id2prize = dict([(p.id, p) for p in prizes])
		red_envelope.prizes = []
		for r in relations:
			prize = id2prize[r.prize_id]
			prize.prize_source = r.prize_source
			prize.prize_type = r.prize_type
			red_envelope.prizes.append(prize)

		red_envelope.prizes.sort(lambda x,y: cmp(x.level, y.level))
		
		#转换为json
		response = JsonResponse()
		response.id = red_envelope.id
		response.name = red_envelope.name
		response.total_award_value = red_envelope.total_award_value
		response.desc = red_envelope.desc
		response.can_repeat = red_envelope.can_repeat
		response.daily_play_count = red_envelope.daily_play_count
		response.prizes = {}
		for prize in red_envelope.prizes:
			prize_json = {}
			prize_json['prize_source'] = prize.prize_source
			prize_json['prize_type'] = prize.prize_type
			prize_json['prize_name'] = prize.name
			prize_json['prize_level'] = prize.level
			prize_json['prize_odds'] = prize.odds
			prize_json['prize_count'] = prize.count
			response.prizes[prize.id] = prize_json
			
		lottery_json = response.get_json()
	else:
		red_envelope = {'can_update': True}
		lottery_json = ''

	coupon_rules = get_coupon_rules(request.user)
	
	c = RequestContext(request, {
		'first_nav_name': MARKET_TOOLS_NAV,
		'second_navs': export.get_second_navs(request),
		'second_nav_name': SECOND_NAV_NAME,
		'red_envelope': red_envelope,
		'lottery_json':lottery_json,
		'coupon_rules':coupon_rules
	})
	return render_to_response('red_envelope/editor/edit_red_envelope.html', c)
예제 #2
0
파일: views.py 프로젝트: chengdg/weizoom
def create_activity(request):
	if request.POST:
		name = request.POST["name"]
		detail =request.POST.get("detail", '')
		guide_url = request.POST.get("guide_url", '')
		is_enable_offline_sign = request.POST.get("is_enable_offline_sign", False)
		is_non_member = request.POST.get("is_non_member", False)
		prize_type = request.POST.get("prize_type", '-1')
		prize_source = request.POST.get("prize_source", '')

		start_date, end_date = __get_start_time_and_end_time(request)
		current_time = datetime.today()
		current_time = current_time.strftime('%Y-%m-%d')
		current_time = datetime.strptime(current_time, '%Y-%m-%d')
		start_date_time = datetime.strptime(start_date, '%Y-%m-%d')

		status = ACTIVITY_STATUS_NO_START
		if start_date_time == current_time:
			status = ACTIVITY_STATUS_RUNING
		
		activity = Activity.objects.create(
			owner=request.user, 
			guide_url=guide_url, 
			name=name, 
			start_date=start_date, 
			end_date=end_date, 
			detail=detail, 
			status=status,
			is_enable_offline_sign=is_enable_offline_sign,
			prize_type=prize_type,
			prize_source=prize_source,
			is_non_member=is_non_member
		)

		__update_activity_items(request, activity.id)
		
		return HttpResponseRedirect('/market_tools/activity/')
	else:
		coupon_rules = get_coupon_rules(request.user)
		coupon_rule_items = []
		for coupon_rule in coupon_rules:
			coupon_rule_items.append(coupon_rule.to_dict())
		c = RequestContext(request, {
			'first_nav_name': MARKET_TOOLS_NAV,
			'second_navs': export.get_second_navs(request),
			'second_nav_name': SECOND_NAV_NAME,
			'activity': {'can_update': True},
			'coupon_rule_items': json.dumps(coupon_rule_items)
		})
		return render_to_response('activity/editor/edit_activity.html', c)
예제 #3
0
def member_qrocde(request):
	mpuser = get_system_user_binded_mpuser(request.user)

	if (mpuser is None) or (not mpuser.is_certified) or (not mpuser.is_service):
		should_show_authorize_cover = True
	else:
		should_show_authorize_cover = False

	coupon_rules = get_coupon_rules(request.user)
	member_qrcode_settings = MemberQrcodeSettings.objects.filter(owner=request.user)
	member_qrcode_setting = member_qrcode_settings[0] if member_qrcode_settings.count() > 0 else None
	if member_qrcode_setting:
		award_contents = MemberQrcodeAwardContent.objects.filter(member_qrcode_settings=member_qrcode_setting)
		if award_contents.count() > 0:
			award_content = award_contents[0] if member_qrcode_setting.award_member_type == 1 else None
		else:
			award_content = None
	else:
		award_contents = None
		award_content = None
	member_grades = MemberGrade.get_all_grades_list(request)

	if member_grades and award_contents:

		for member_grade in member_grades:
			content = award_contents.filter(member_level=member_grade.id)[0] if award_contents.filter(member_level=member_grade.id).count() > 0 else None
			if content:
				member_grade.award_type = content.award_type
				member_grade.award_content = content.award_content

	c = RequestContext(request, {
		'first_nav_name': export.MEMBER_FIRST_NAV,
		'second_navs': export.get_second_navs(request),
		'second_nav_name': export.MEMBER_QRCODE,
		'member_grades': member_grades,
		'member_qrcode_settings': member_qrcode_setting,
		'coupon_rules': coupon_rules,
		'award_content': award_content,
		'member_grades': member_grades,
		'should_show_authorize_cover': should_show_authorize_cover,
		'is_hide_weixin_option_menu': True
	})

	return render_to_response('member/editor/member_qrcode.html', c)
예제 #4
0
    def get(request):
        mpuser = get_system_user_binded_mpuser(request.manager)

        if (mpuser is
                None) or (not mpuser.is_certified) or (not mpuser.is_service):
            should_show_authorize_cover = True
        else:
            should_show_authorize_cover = False

        coupon_rules = get_coupon_rules(request.manager)
        try:
            member_qrcode_setting = MemberChannelQrcodeSettings.objects.get(
                owner=request.manager)
        except:
            member_qrcode_setting = None

        if member_qrcode_setting:
            try:
                award_content = MemberChannelQrcodeAwardContent.objects.get(
                    owner=request.manager)
            except:
                award_content = None
        else:
            award_content = None

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
                'third_nav_name':
                export.ADVANCE_MANAGE_MEMBER_CHANNEL_QRCODE_NAV,
                'member_qrcode_settings': member_qrcode_setting,
                'coupon_rules': coupon_rules,
                'award_content': award_content,
                'should_show_authorize_cover': should_show_authorize_cover,
                'is_hide_weixin_option_menu': True
            })

        return render_to_response(
            'weixin/advance_manage/edit_member_channel_qrcode.html', c)
예제 #5
0
파일: views.py 프로젝트: chengdg/weizoom
def update_research(request, research_id):
    research = Research.objects.get(id=research_id)

    research_items = []
    for research_item in ResearchItem.objects.filter(research=research):
        type = 'text'
        if research_item.type == RESEARCHITEM_TYPE_SELECT:
            type = 'select'
        elif research_item.type == RESEARCHITEM_TYPE_IMAGE:
            type = 'image'
        elif research_item.type == RESEARCHITEM_TYPE_CHECKBOX:
            type = 'checkbox'

        research_items.append({
            'id': research_item.id,
            'title': research_item.title,
            'initial_data': research_item.initial_data,
            'is_mandatory': research_item.is_mandatory,
            'type': type
        })

    coupon_rules = get_coupon_rules(request.user)
    coupon_rule_items = []
    for coupon_rule in coupon_rules:
        coupon_rule_items.append({
            'id': coupon_rule.id,
            'name': coupon_rule.name,
        })

    c = RequestContext(
        request, {
            'first_nav_name': MARKET_TOOLS_NAV,
            'second_navs': export.get_second_navs(request),
            'second_nav_name': SECOND_NAV_NAME,
            'research': research,
            'research_items': json.dumps(research_items),
            'coupon_rule_items': json.dumps(coupon_rule_items)
        })
    return render_to_response('research/editor/edit_research.html', c)
예제 #6
0
def edit_lottery_view(request, id):
	id = int(id)
	if id:
		lottery = Lottery.objects.get(id=id)
		lottery.can_update = False
		if lottery.status == LOTTERY_STATUS_NO_START:
			lottery.can_update = True
		
		relations = LotteryHasPrize.objects.filter(lottery=lottery)
		prize_ids = [r.prize_id for r in relations]
		prizes = Prize.objects.filter(id__in=prize_ids)
		id2prize = dict([(p.id, p) for p in prizes])
		lottery.prizes = []
		for r in relations:
			prize = id2prize[r.prize_id]
			prize.prize_source = r.prize_source
			prize.prize_type = r.prize_type
			lottery.prizes.append(prize)
		
		lottery.prizes.sort(lambda x,y: cmp(x.level, y.level))
		
		#转换为json
		response = JsonResponse()
		response.id = lottery.id
		response.name = lottery.name
		response.detail = lottery.detail
		response.expend_integral = lottery.expend_integral
		response.can_repeat = lottery.can_repeat
		response.daily_play_count = lottery.daily_play_count
		response.type = lottery.type
		response.award_hour = lottery.award_hour
		response.not_win_desc = lottery.not_win_desc
		if lottery.award_type:
			response.award_type = lottery.award_type
		else:
			response.award_type = ''
		response.start_at = lottery.start_at.strftime("%Y-%m-%d")
		response.end_at = lottery.end_at.strftime("%Y-%m-%d")
		response.prizes = {}
		for prize in lottery.prizes:
			prize_json = {}
			prize_json['prize_source'] = prize.prize_source
			prize_json['prize_type'] = prize.prize_type
			prize_json['prize_name'] = prize.name
			prize_json['prize_level'] = prize.level
			prize_json['prize_odds'] = prize.odds
			prize_json['prize_count'] = prize.count
			response.prizes[prize.id] = prize_json
			
		lottery_json = response.get_json()
	else:
		lottery = {'can_update': True}
		lottery_json = ''

	coupon_rules = get_coupon_rules(request.user)
	
	c = RequestContext(request, {
		'first_nav_name': MARKET_TOOLS_NAV,
		'second_navs': export.get_second_navs(request),
		'second_nav_name': SECOND_NAV_NAME,
		'lottery': lottery,
		'lottery_json':lottery_json,
		'coupon_rules':coupon_rules
	})
	return render_to_response('lottery/editor/edit_lottery.html', c)
예제 #7
0
파일: views.py 프로젝트: chengdg/weizoom
def update_activity(request, activity_id):
	if request.POST:
		name = request.POST["name"]
		detail =request.POST.get("detail", '')
		guide_url = request.POST.get("guide_url", '')
		is_enable_offline_sign = request.POST.get("is_enable_offline_sign", False)
		if is_enable_offline_sign:
			prize_type = request.POST.get("prize_type", '-1')
			prize_source = request.POST.get("prize_source", '')
		else:
			prize_type = -1
			prize_source = ''
		is_non_member = request.POST.get("is_non_member", False)
		start_date, end_date = __get_start_time_and_end_time(request)
		current_time = datetime.today()
		current_time = current_time.strftime('%Y-%m-%d')
		current_time = datetime.strptime(current_time, '%Y-%m-%d')
		start_date_time = datetime.strptime(start_date, '%Y-%m-%d')

		status = ACTIVITY_STATUS_NO_START
		if start_date_time == current_time:
			status = ACTIVITY_STATUS_RUNING
		
		Activity.objects.filter(id=activity_id).update(
			guide_url = guide_url, 
			name = name, 
			start_date = start_date, 
			end_date = end_date, 
			detail = detail, 
			status = status,
			prize_type = prize_type,
			prize_source = prize_source,
			is_non_member = is_non_member
		)

		__update_activity_items(request, activity_id)

		return HttpResponseRedirect('/market_tools/activity/')
	else:
		activity = Activity.objects.get(id=activity_id)
		activity.can_update = False
		if activity.status == ACTIVITY_STATUS_NO_START:
			activity.can_update = True

		activity_items = []
		for activity_item in ActivityItem.objects.filter(activity=activity):
			type = 'text'
			if activity_item.type == ACTIVITYITEM_TYPE_SELECT:
				type = 'select'
			elif activity_item.type == ACTIVITYITEM_TYPE_IMAGE:
				type = 'image'
			elif activity_item.type == ACTIVITYITEM_TYPE_CHECKBOX:
				type = 'checkbox'

			activity_items.append({
				'id': activity_item.id,
				'title': activity_item.title,
				'initial_data': activity_item.initial_data,
				'is_mandatory': activity_item.is_mandatory,
				'type': type
			})
		coupon_rules = get_coupon_rules(request.user)
		coupon_rule_items = []
		for coupon_rule in coupon_rules:
			coupon_rule_items.append({
				'id': coupon_rule.id,
				'name': coupon_rule.name,
			})
		c = RequestContext(request, {
			'first_nav_name': MARKET_TOOLS_NAV,
			'second_navs': export.get_second_navs(request),
			'second_nav_name': SECOND_NAV_NAME,
			'activity': activity,
			'activity_items': json.dumps(activity_items),
			'coupon_rule_items': json.dumps(coupon_rule_items)
		})
		return render_to_response('activity/editor/edit_activity.html', c)
예제 #8
0
def get_coupon_rules(owner):
    return coupon_util.get_coupon_rules(owner)