def get_content_hongbao(request): ret_dict = {} id = request.GET.get('id', '') if not id: ret_dict['code'] = 1 ret_dict['message'] = u"参数错误" return JsonResponse(ret_dict) try: wel = Welfare.objects.get(id=id) except: ret_dict['code'] = 2 ret_dict['message'] = u"系统错误" return JsonResponse(ret_dict) update_view_count(wel) if wel.type != "hongbao": ret_dict['code'] = 3 ret_dict['message'] = u"类型错误" return JsonResponse(ret_dict) wel = wel.hongbao strategy = wel.strategy.replace('"/media/', '"' + host + '/media/') ret_dict = { 'code': 0, 'image': host + wel.pic.url, 'strategy': strategy, 'num': wel.view_count, 'time': wel.time_limit, 'url': wel.exp_url_mobile, 'title': wel.title } return JsonResponse(ret_dict)
def add_finance(request, id=None): if id is None: ad_list = Advertisement.objects.filter(location__in=['0', '4'], is_hidden=False)[0:1] context = {'ad_list': ad_list} return render(request, 'finance-add.html', context) else: id = int(id) news = None try: news = Finance.objects.get(id=id) except Finance.DoesNotExist: raise Http404(u"该页面不存在") if not news.state in ["1", "2"]: raise Http404(u"该项目已下线") update_view_count(news) scheme = news.scheme table = [] str_rows = scheme.split('|') for str_row in str_rows: row = str_row.split('#') table.append(row) other_wel_list = Finance.objects.filter( state='1', level__in=['normal', 'all']).order_by('-view_count')[0:10] context = { 'news': news, 'type': 'Finance', 'other_wel_list': other_wel_list, 'table': table, } return render(request, 'detail-finance.html', context)
def get_content_task(request): ret_dict = {} id = request.GET.get("id") id = int(id) news = None try: news = Task.objects.get(id=id) except Task.DoesNotExist: ret_dict['code'] = 1 ret_dict['msg'] = u"该任务不存在" else: update_view_count(news) ret_dict['code'] = 0 strategy = news.strategy.replace('"/media/', '"' + host + '/media/') rules = news.rules.replace('"/media/', '"' + host + '/media/') taskinfo = { 'is_forbidden': news.is_forbidden, 'left_num': news.left_num, 'rules': rules, 'strategy': strategy, 'url': news.exp_url_mobile, 'title': news.title, } ret_dict['taskinfo'] = taskinfo if is_authenticated_app(request): try: UserTask.objects.get(user=request.user, task=news) except UserTask.DoesNotExist: ret_dict.update(accepted=0) else: ret_dict.update(accepted=1) return JsonResponse(ret_dict)
def add_finance(request, id=None): if id is None: ad_list = Advertisement.objects.filter(location__in=['0','4'],is_hidden=False)[0:1] context = {'ad_list':ad_list} return render(request, 'finance-add.html',context) else: id = int(id) news = None try: news = Finance.objects.get(id=id) except Finance.DoesNotExist: raise Http404(u"该页面不存在") if not news.state in ["1", "2"]: raise Http404(u"该项目已下线") update_view_count(news) scheme = news.scheme table = [] str_rows = scheme.split('|') for str_row in str_rows: row = str_row.split('#') table.append(row); other_wel_list = Finance.objects.filter(state='1', level__in=['normal','all']).order_by('-view_count')[0:10] context = { 'news':news, 'type':'Finance', 'other_wel_list':other_wel_list, 'table':table, } return render(request, 'detail-finance.html', context)
def get_content_youhuiquan(request): ret_dict = {} id = request.GET.get('id', '') if not id: ret_dict['code'] = 1 ret_dict['message'] = u"参数错误" return JsonResponse(ret_dict) try: wel = Welfare.objects.get(id=id) except: ret_dict['code'] = 2 ret_dict['message'] = u"系统错误" return JsonResponse(ret_dict) update_view_count(wel) if wel.type != "youhuiquan": ret_dict['code'] = 3 ret_dict['message'] = u"类型错误" return JsonResponse(ret_dict) wel = wel.couponproject if wel.ctype == '2': wel.left_count = wel.coupons.filter(user__isnull=True).count() else: wel.left_count = u"充足" strategy = wel.strategy.replace('/media/', host + '/media/') ret_dict = { 'code': 0, 'image': host + wel.pic.url, 'strategy': strategy, 'num': wel.left_count, 'time': wel.time_limit, 'url': wel.exp_url_mobile, 'title': wel.title, } return JsonResponse(ret_dict)
def exp_welfare_openwindow(request): wel_id = request.GET.get('id', None) wel_type = request.GET.get('type', None) if not wel_id or not wel_type: logger.error("wel_id or type is missing!!!") raise Http404 wel_id = int(wel_id) wel_type = str(wel_type) model = globals()[wel_type] wel = model.objects.get(id=wel_id) if wel_type == "Task" and not wel.is_forbidden: obj, created = UserTask.objects.get_or_create(user=request.user, task=wel) if created: if wel.left_num <= 1: wel.state = '2' wel.left_num = F("left_num") - 1 wel.save(update_fields=["left_num", "state"]) update_view_count(wel) url = wel.exp_url_mobile if url == '': js = ''' <script> alert("本项目仅限电脑端体验,请前往电脑端。"); window.history.back(); </script> ''' else: js = "<script>window.location.href='" + url + "';</script>" return HttpResponse(js)
def task(request, id=None): if id is None: ad_list = Advertisement.objects.filter(Q(location='0') | Q(location='3'), is_hidden=False)[0:8] strategy_list = Press.objects.filter(type='2')[0:10] context = {'ad_list': ad_list, 'strategy_list': strategy_list} task_type = ContentType.objects.get_for_model(Task) event_list = UserEvent.objects.filter(event_type='1', content_type=task_type.id)[0:6] exps = [] for event in event_list: username = event.user.username task = event.content_object if len(username) > 4: username = username[0:4] + '****' else: username = username + '****' exps.append({'username': username, 'title': task.title}) context.update({'exps': exps}) defalut_filter = request.GET.get('type', '') if defalut_filter == 'junior': context.update(defalut_filter=1) elif defalut_filter == 'middle': context.update(defalut_filter=2) elif defalut_filter == 'senior': context.update(defalut_filter=3) else: context.update(defalut_filter=0) return render(request, 'taskWelfare.html', context) else: id = int(id) news = None try: news = Task.objects.get(id=id) except Task.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(news) other_wel_list = Task.objects.filter( state='1').order_by('-view_count')[0:10] context = { 'news': news, 'type': 'Task', 'other_wel_list': other_wel_list } if request.user.is_authenticated(): try: UserTask.objects.get(user=request.user, task=news) except UserTask.DoesNotExist: context.update(accepted=0) else: context.update(accepted=1) else: context.update(accepted=0) return render(request, 'detail-task.html', context)
def welfare(request, id=None, type=None): if not id: wel_list = Welfare.objects.filter(state='1', is_display=True) if type: type = str(type) if type == 'hb': return render(request, 'm_hongbao.html') elif type == 'yhq': return render(request, 'm_youhuiquan.html') elif type == 'by': return render(request, 'm_baoyou.html') raise Http404 elif id: id = int(id) try: wel = Welfare.objects.get(id=id) except Welfare.DoesNotExist: raise Http404(u"该页面不存在") # other_wel_list = Welfare.objects.filter(is_display=True, state='1').order_by('-view_count')[0:10] # if wel.type != "baoyou": # url = request.get_full_path() # weixin_params = get_weixin_params(url) # context['weixin_params'] = weixin_params update_view_count(wel) template = '' if wel.type == "youhuiquan": template = 'm_detail_youhuiquan.html' wel = wel.couponproject if wel.ctype == '2': wel.left_count = wel.coupons.filter(user__isnull=True).count() else: wel.left_count = u"充足" elif wel.type == "hongbao": template = 'm_detail_hongbao.html' wel = wel.hongbao elif wel.type == "baoyou": template = 'm_detail_hongbao.html' wel = wel.baoyou ref_url = request.META.get('HTTP_REFERER', "") context = { 'news': wel, 'type': 'Welfare', } if 'next=' in ref_url: context.update({'back': True}) return render(request, template, context)
def task(request, id=None): if id is None: ad_list = Advertisement.objects.filter(Q(location='0')|Q(location='3'),is_hidden=False)[0:8] strategy_list = Press.objects.filter(type='2')[0:10] context = {'ad_list':ad_list,'strategy_list':strategy_list} task_type = ContentType.objects.get_for_model(Task) event_list = UserEvent.objects.filter(event_type='1',content_type = task_type.id)[0:6] exps = [] for event in event_list: username = event.user.username task = event.content_object if len(username) > 4: username = username[0:4] + '****' else: username = username + '****' exps.append({'username':username,'title':task.title}) context.update({'exps':exps}) defalut_filter = request.GET.get('type','') if defalut_filter=='junior': context.update(defalut_filter=1) elif defalut_filter=='middle': context.update(defalut_filter=2) elif defalut_filter=='senior': context.update(defalut_filter=3) else: context.update(defalut_filter=0) return render(request, 'taskWelfare.html', context) else: id = int(id) news = None try: news = Task.objects.get(id=id) except Task.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(news) other_wel_list = Task.objects.filter(state='1').order_by('-view_count')[0:10] context = {'news':news,'type':'Task','other_wel_list':other_wel_list} if request.user.is_authenticated(): try: UserTask.objects.get(user=request.user,task=news) except UserTask.DoesNotExist: context.update(accepted=0) else: context.update(accepted=1) else: context.update(accepted=0) return render(request, 'detail-task.html',context)
def finance(request, id=None): if id is None: ad_list = Advertisement.objects.filter(Q(location='0') | Q(location='4'), is_hidden=False)[0:8] strategy_list = Press.objects.filter(type='2')[0:10] context = {'ad_list': ad_list, 'strategy_list': strategy_list} rank_users = MyUser.objects.order_by('-accu_income')[0:6] for i in range(len(rank_users)): key = 'rank' + str(i + 1) username = rank_users[i].username if len(username) > 4: username = username[0:4] + '****' else: username = username + '****' income = rank_users[i].accu_income context.update( {key: { 'username': username, 'income': str(income) }}) return render(request, 'finance.html', context) else: id = int(id) news = None try: news = Finance.objects.get(id=id) except Finance.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(news) scheme = news.scheme table = [] str_rows = scheme.split('|') for str_row in str_rows: row = str_row.split('#') table.append(row) other_wel_list = Finance.objects.filter( state='1', level__in=['normal', 'all']).order_by('-view_count')[0:10] context = { 'news': news, 'type': 'Finance', 'other_wel_list': other_wel_list, 'table': table, } return render(request, 'detail-finance.html', context)
def get_content_finance(request): ret_dict = {} id = request.GET.get("id") id = int(id) news = None try: news = Finance.objects.get(id=id) except Finance.DoesNotExist: ret_dict['code'] = 1 ret_dict['msg'] = u"该福利不存在" else: update_view_count(news) ret_dict['code'] = 0 strategy = news.strategy.replace('"/media/', '"' + host + '/media/') rules = news.rules.replace('"/media/', '"' + host + '/media/') marks = news.marks.all()[0:3] mlist = [] for mark in marks: mlist.append(mark.name) scheme = news.scheme table = [] str_rows = scheme.split('|') for str_row in str_rows: row = str_row.split('#') table.append(row) financeinfo = { 'rules': rules, 'strategy': strategy, 'url': news.exp_url_mobile, 'title': news.title, 'state': news.state, 'introduction': news.introduction, 'background': news.background, 'regcap': news.regcap, 'onlinedate': news.onlinedate, 'depository': news.depository, 'ICP': news.ICP, 'marks': mlist, 'scheme': table } ret_dict['financeinfo'] = financeinfo return JsonResponse(ret_dict)
def exp_welfare_erweima(request): if not request.is_ajax(): logger.warning("Experience refused no-ajax request!!!") raise Http404 result = {} if not request.user.is_authenticated(): url = reverse('user_guide') + '?next=' + request.META['HTTP_REFERER'] result['url'] = url result['code'] = '0' return JsonResponse(result) wel_id = request.GET.get('id', None) wel_type = request.GET.get('type', None) if not wel_id or not wel_type: logger.error("wel_id is missing!!!") raise Http404 wel_id = int(wel_id) wel_type = str(wel_type) model = globals()[wel_type] wel = model.objects.get(id=wel_id) update_view_count(wel) if wel_type == 'Welfare': if wel.type == "hongbao": wel = wel.hongbao elif wel.type == "baoyou": wel = wel.baoyou if wel.isonMobile: result['url'] = wel.exp_code.url else: logger.error( str(model) + ":" + str(wel.id) + " is not onMobile wel !!!") raise Http404 result['code'] = '1' if wel_type == "Task" and not wel.is_forbidden: obj, created = UserTask.objects.get_or_create(user=request.user, task=wel) if created: if wel.left_num <= 1: wel.state = '2' wel.left_num = F("left_num") - 1 wel.save(update_fields=["left_num", "state"]) return JsonResponse(result)
def get_content_information(request): ret_dict = {} id = request.GET.get("id") id = int(id) news = None try: news = Information.objects.get(id=id) except Information.DoesNotExist: ret_dict['code'] = 1 ret_dict['msg'] = u"该新闻不存在" else: update_view_count(news) ret_dict['code'] = 0 content = news.content.replace('"/media/', '"' + host + '/media/') info = { 'source': news.source, 'content': content, 'time': news.pub_date.strftime("%Y-%m-%d %H:%M"), } ret_dict['info'] = info return JsonResponse(ret_dict)
def finance(request, id=None): if id is None: ad_list = Advertisement.objects.filter(Q(location='0')|Q(location='4'),is_hidden=False)[0:8] strategy_list = Press.objects.filter(type='2')[0:10] context = {'ad_list':ad_list,'strategy_list':strategy_list} rank_users = MyUser.objects.order_by('-accu_income')[0:6] for i in range(len(rank_users)): key = 'rank'+str(i+1) username = rank_users[i].username if len(username) > 4: username = username[0:4] + '****' else: username = username + '****' income = rank_users[i].accu_income context.update({key:{'username':username,'income':str(income)}}) return render(request, 'finance.html',context) else: id = int(id) news = None try: news = Finance.objects.get(id=id) except Finance.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(news) scheme = news.scheme table = [] str_rows = scheme.split('|') for str_row in str_rows: row = str_row.split('#') table.append(row); other_wel_list = Finance.objects.filter(state='1', level__in=['normal','all']).order_by('-view_count')[0:10] context = { 'news':news, 'type':'Finance', 'other_wel_list':other_wel_list, 'table':table, } return render(request, 'detail-finance.html', context)
def welfare(request, id=None, page=None, type=None): if not id: if not page: page = 1 else: page = int(page) full_path = str(request.get_full_path()) path_split = [] if 'list-page' in full_path: path_split = re.split('list-page\d+', full_path) elif '?' in full_path: path_split = full_path.split('?') path_split[1] = '?' + path_split[1] else: path_split = [full_path, ''] page_dic = {} ref_dic = {} page_dic['pre_path'] = path_split[0] page_dic['suf_path'] = path_split[1] wel_list = Welfare.objects.filter(is_display=True) state = request.GET.get('state', '1') full_path_ = re.sub(r'/list-page\d+&?', '', full_path, 1) ref_path1 = re.sub(r'state=\d+&?', '', full_path_, 1) ref_path2, num = re.subn(r'state=\d+', 'state=2', full_path_) if num == 0: if '?' in ref_path2: ref_path2 += '&state=2' else: ref_path2 += '?state=2' if ref_path1[-1] == '?' or ref_path1[-1] == '&': ref_path1 = ref_path1[:-1] ref_dic = { 'state': state, 'ref_path1': ref_path1, 'ref_path2': ref_path2, } if state: # ref_path = re.sub(r'state=\d+', 'state=1', full_path, 1) state = str(state) wel_list = wel_list.filter(state=state) if type: type = str(type) if type == 'hb': wel_list = wel_list.filter(type="hongbao") elif type == 'yhq': wel_list = wel_list.filter(type="youhuiquan") elif type == 'by': wel_list = wel_list.filter(type="baoyou") search_key = request.GET.get('key', '') if search_key: wel_list = wel_list.filter( Q(title__contains=search_key) | Q(company__name__contains=search_key)) business = request.GET.get('business', '') if business: wel_list = wel_list.filter(company__name=business) wel_list, page_num = listing(wel_list, 12, int(page)) if page_num < 10: page_list = range(1, page_num + 1) else: if page < 6: page_list = range(1, 8) + ["...", page_num] elif page > page_num - 5: page_list = [1, '...'] + range(page_num - 6, page_num + 1) else: page_list = [1, '...'] + range(page - 2, page + 3) + ['...', page_num] page_dic['page_list'] = page_list ad_list = Advertisement.objects.filter(Q(location='0') | Q(location='2'), is_hidden=False)[0:8] strategy_list = Press.objects.filter(type='2')[0:10] hot_wel_list = Welfare.objects.filter( is_display=True, state='1').order_by('-view_count')[0:2] business_list = Company.objects.order_by('-view_count')[0:10] hot_info = Information.objects.filter( is_display=True).order_by('-view_count').first() context = { 'wel_list': wel_list, 'business_list': business_list, 'ad_list': ad_list, 'strategy_list': strategy_list, 'page_dic': page_dic, 'ref_dic': ref_dic, 'hot_wel_list': hot_wel_list, 'info': hot_info, 'type': type, } ranks = RecommendRank.objects.all()[0:6] for i in range(len(ranks)): key = 'rank' + str(i + 1) username = ranks[i].user.username if len(username) > 4: username = username[0:4] + '****' else: username = username + '****' acc_num = ranks[i].acc_num context.update( {key: { 'username': username, 'acc_num': str(acc_num) + u'条' }}) return render(request, 'wfl-welfare.html', context) elif id: id = int(id) wel = None try: wel = Welfare.objects.get(id=id) except Welfare.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(wel) other_wel_list = Welfare.objects.filter( is_display=True, state='1').order_by('-view_count')[0:10] template = 'detail-common.html' if wel.type == "youhuiquan": template = 'detail-youhuiquan.html' wel = wel.couponproject if wel.ctype == '2': wel.left_count = wel.coupons.filter(user__isnull=True).count() else: wel.left_count = u"充足" elif wel.type == "hongbao": wel = wel.hongbao template = 'detail-hongbao.html' elif wel.type == "baoyou": wel = wel.baoyou return render(request, template, { 'news': wel, 'type': 'Welfare', 'other_wel_list': other_wel_list })
def information(request, type=None, page=None, id=None): if not id: if not page: page = 1 else: page = int(page) full_path = str(request.get_full_path()) path_split = [] if 'list-page' in full_path: path_split = re.split('list-page\d+', full_path) elif '?' in full_path: path_split = full_path.split('?') path_split[1] = '?' + path_split[1] else: path_split = [full_path, ''] page_dic = {} ref_dic = {} page_dic['pre_path'] = path_split[0] page_dic['suf_path'] = path_split[1] info_list = Information.objects.filter(is_display=True) state = request.GET.get('state', '1') full_path_ = re.sub(r'/list-page\d+&?', '', full_path, 1) ref_path1 = re.sub(r'state=\d+&?', '', full_path_, 1) ref_path2, num = re.subn(r'state=\d+', 'state=2', full_path_) if num == 0: if '?' in ref_path2: ref_path2 += '&state=2' else: ref_path2 += '?state=2' if ref_path1[-1] == '?' or ref_path1[-1] == '&': ref_path1 = ref_path1[:-1] ref_dic = { 'state': state, 'ref_path1': ref_path1, 'ref_path2': ref_path2, } if type: type = str(type) info_list = info_list.filter(type=type) info_list, page_num = listing(info_list, 6, int(page)) if page_num < 10: page_list = range(1, page_num + 1) else: if page < 6: page_list = range(1, 8) + ["...", page_num] elif page > page_num - 5: page_list = [1, '...'] + range(page_num - 6, page_num + 1) else: page_list = [1, '...'] + range(page - 2, page + 3) + ['...', page_num] page_dic['page_list'] = page_list hot_info_list = Information.objects.filter( is_display=True).order_by('-view_count')[0:10] hot_wel_list = Welfare.objects.order_by('-view_count')[0:10] ad_list = Advertisement.objects.filter(Q(location='0') | Q(location='10'), is_hidden=False)[0:8] context = { 'info_list': info_list, 'page_dic': page_dic, 'hot_info_list': hot_info_list, 'hot_wel_list': hot_wel_list, 'type': type, 'ad_list': ad_list, } return render(request, 'information.html', context) elif id: id = int(id) info = None try: info = Information.objects.get(id=id) except Information.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(info) hot_info_list = Information.objects.filter( is_display=True).order_by('-view_count')[0:6] return render(request, 'detail-information.html', { 'info': info, 'hot_info_list': hot_info_list, 'type': 'Information' })
def welfare(request, id=None, page=None, type=None): if not id: if not page: page = 1 else: page = int(page) full_path = str(request.get_full_path()) path_split = [] if 'list-page' in full_path: path_split = re.split('list-page\d+',full_path) elif '?' in full_path: path_split = full_path.split('?') path_split[1] = '?' + path_split[1] else: path_split=[full_path, ''] page_dic = {} ref_dic = {} page_dic['pre_path'] = path_split[0] page_dic['suf_path'] = path_split[1] wel_list = Welfare.objects.filter(is_display=True) state = request.GET.get('state', '1') full_path_ = re.sub(r'/list-page\d+&?', '', full_path, 1) ref_path1 = re.sub(r'state=\d+&?', '', full_path_, 1) ref_path2, num = re.subn(r'state=\d+', 'state=2', full_path_) if num == 0: if '?' in ref_path2: ref_path2 += '&state=2' else: ref_path2 += '?state=2' if ref_path1[-1] == '?' or ref_path1[-1] == '&': ref_path1 = ref_path1[:-1] ref_dic = {'state':state, 'ref_path1':ref_path1, 'ref_path2':ref_path2,} if state: # ref_path = re.sub(r'state=\d+', 'state=1', full_path, 1) state = str(state) wel_list = wel_list.filter(state=state) if type: type = str(type) if type == 'hb': wel_list = wel_list.filter(type="hongbao") elif type == 'yhq': wel_list = wel_list.filter(type="youhuiquan") elif type == 'by': wel_list = wel_list.filter(type="baoyou") search_key = request.GET.get('key', '') if search_key: wel_list = wel_list.filter(Q(title__contains=search_key)|Q(company__name__contains=search_key)) business = request.GET.get('business', '') if business: wel_list = wel_list.filter(company__name=business) wel_list, page_num = listing(wel_list, 12, int(page)) if page_num < 10: page_list = range(1,page_num+1) else: if page < 6: page_list = range(1,8) + ["...",page_num] elif page > page_num - 5: page_list = [1,'...'] + range(page_num-6, page_num+1) else: page_list = [1,'...'] + range(page-2, page+3) + ['...',page_num] page_dic['page_list'] = page_list ad_list = Advertisement.objects.filter(Q(location='0')|Q(location='2'),is_hidden=False)[0:8] strategy_list = Press.objects.filter(type='2')[0:10] hot_wel_list = Welfare.objects.filter(is_display=True, state='1').order_by('-view_count')[0:2] business_list = Company.objects.order_by('-view_count')[0:10] hot_info = Information.objects.filter(is_display=True).order_by('-view_count').first() context = { 'wel_list':wel_list, 'business_list':business_list, 'ad_list':ad_list, 'strategy_list':strategy_list, 'page_dic':page_dic, 'ref_dic':ref_dic, 'hot_wel_list':hot_wel_list, 'info':hot_info, 'type':type, } ranks = RecommendRank.objects.all()[0:6] for i in range(len(ranks)): key = 'rank'+str(i+1) username = ranks[i].user.username if len(username) > 4: username = username[0:4] + '****' else: username = username + '****' acc_num = ranks[i].acc_num context.update({key:{'username':username,'acc_num':str(acc_num)+u'条'}}) return render(request, 'wfl-welfare.html', context) elif id: id = int(id) wel = None try: wel = Welfare.objects.get(id=id) except Welfare.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(wel) other_wel_list = Welfare.objects.filter(is_display=True, state='1').order_by('-view_count')[0:10] template = 'detail-common.html' if wel.type == "youhuiquan": template = 'detail-youhuiquan.html' wel = wel.couponproject if wel.ctype == '2': wel.left_count = wel.coupons.filter(user__isnull=True).count() else: wel.left_count = u"充足" elif wel.type == "hongbao": wel = wel.hongbao template = 'detail-hongbao.html' elif wel.type == "baoyou": wel = wel.baoyou return render(request, template,{'news':wel,'type':'Welfare', 'other_wel_list':other_wel_list})
def information(request, type=None, page=None, id=None): if not id: if not page: page = 1 else: page = int(page) full_path = str(request.get_full_path()) path_split = [] if 'list-page' in full_path: path_split = re.split('list-page\d+',full_path) elif '?' in full_path: path_split = full_path.split('?') path_split[1] = '?' + path_split[1] else: path_split=[full_path, ''] page_dic = {} ref_dic = {} page_dic['pre_path'] = path_split[0] page_dic['suf_path'] = path_split[1] info_list = Information.objects.filter(is_display=True) state = request.GET.get('state', '1') full_path_ = re.sub(r'/list-page\d+&?', '', full_path, 1) ref_path1 = re.sub(r'state=\d+&?', '', full_path_, 1) ref_path2, num = re.subn(r'state=\d+', 'state=2', full_path_) if num == 0: if '?' in ref_path2: ref_path2 += '&state=2' else: ref_path2 += '?state=2' if ref_path1[-1] == '?' or ref_path1[-1] == '&': ref_path1 = ref_path1[:-1] ref_dic = {'state':state, 'ref_path1':ref_path1, 'ref_path2':ref_path2,} if type: type = str(type) info_list = info_list.filter(type=type) info_list, page_num = listing(info_list, 6, int(page)) if page_num < 10: page_list = range(1,page_num+1) else: if page < 6: page_list = range(1,8) + ["...",page_num] elif page > page_num - 5: page_list = [1,'...'] + range(page_num-6, page_num+1) else: page_list = [1,'...'] + range(page-2, page+3) + ['...',page_num] page_dic['page_list'] = page_list hot_info_list = Information.objects.filter(is_display=True).order_by('-view_count')[0:10] hot_wel_list = Welfare.objects.order_by('-view_count')[0:10] ad_list = Advertisement.objects.filter(Q(location='0')|Q(location='10'),is_hidden=False)[0:8] context = { 'info_list':info_list, 'page_dic':page_dic, 'hot_info_list':hot_info_list, 'hot_wel_list':hot_wel_list, 'type':type, 'ad_list':ad_list, } return render(request, 'information.html', context) elif id: id = int(id) info = None try: info = Information.objects.get(id=id) except Information.DoesNotExist: raise Http404(u"该页面不存在") update_view_count(info) hot_info_list = Information.objects.filter(is_display=True).order_by('-view_count')[0:6] return render(request, 'detail-information.html',{'info':info, 'hot_info_list':hot_info_list, 'type':'Information'})