def kaihu_ad(context): """ @note: 头条最新热榜 """ from common import utils from www.kaihu.interface import AdBase, CityBase city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', '')) dict_ads = { "mz": ["ad_mz.jpg", "8655809", u"梅州"], "my": ["ad_my.jpg", "1919994989", u"绵阳"], "chengdu": ["ad_chengdu.jpg", "2277483400", u"成都"], "deyang": ["ad_deyang.jpg", "1547037393", u"德阳"], "gy": ["ad_gy.jpg", "342437260", u"广元"], "fushun": ["ad_fushun.jpg", "1508819430", u"抚顺"], "pj": ["ad_pj.jpg", "1315946235", u"盘锦"], } dict_ads = {} for x in AdBase().get_ads(): city = CityBase().get_city_by_id(x.city_id) dict_ads[city.pinyin_abbr] = [x.img, x.qq, city.city] # print 'dict_ads', dict_ads default = ["http://static.zhixuan.com/img/kaihu/ad_common.jpg", "403897485", u""] ad_img = dict_ads.get(city_abbr, default) return render_to_response('kaihu/_kaihu_ad.html', locals(), context_instance=context).content
def _decorator(request, *args, **kwargs): city_abbr = utils.get_sub_domain_from_http_host( request.META.get('HTTP_HOST', '')) city = cb.get_city_by_pinyin_abbr(city_abbr) if not city: raise Http404 return func(request, *args, **kwargs)
def random_department(context): """ @note: 随机出现营业部 """ from common import utils from www.kaihu.interface import DepartmentBase, CityBase city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', '')) city = CityBase().get_city_by_pinyin_abbr(city_abbr) departments = DepartmentBase().get_departments_by_random(city.id)[:10] return render_to_response('kaihu/_random_department.html', locals(), context_instance=context).content
def show_index_for_all_domain(request): from www.account.views import show_index from www.kaihu.views import department_list, home as kaihu_home # 通配符域名的情况下,跳转到不同的views sub_domain = utils.get_sub_domain_from_http_host(request.META.get('HTTP_HOST', '')) if sub_domain and sub_domain not in ("127", "192"): if sub_domain == 'kaihu': return kaihu_home(request) if sub_domain not in ('www', ): return department_list(request, city_abbr=sub_domain) return show_index(request)
def process_request(self, request): setattr(request, "_process_start_timestamp", time.time()) sub_domain = utils.get_sub_domain_from_http_host(request.META.get('HTTP_HOST', '')) path = request.path if sub_domain not in ("127", "192"): if sub_domain not in ('www', 'wwwinside', 'static') and (path not in ('', '/', '/message/get_unread_count_total', '/question/get_topic_info_by_id') and not path.startswith('/static') and not path.startswith('/kaihu')): raise Http404 if sub_domain in ('www', 'wwwinside', 'static') and path.startswith('/kaihu'): raise Http404 request.sub_domain = sub_domain
def show_index_for_all_domain(request): from www.account.views import show_index from www.kaihu.views import department_list, home as kaihu_home # 通配符域名的情况下,跳转到不同的views sub_domain = utils.get_sub_domain_from_http_host( request.META.get('HTTP_HOST', '')) if sub_domain and sub_domain not in ("127", "192"): if sub_domain == 'kaihu': return kaihu_home(request) if sub_domain not in ('www', ): return department_list(request, city_abbr=sub_domain) return show_index(request)
def article_list(request, template_name='kaihu/article_list.html'): sub_domain = utils.get_sub_domain_from_http_host(request.META.get('HTTP_HOST', '')) city = cb.get_city_by_pinyin_abbr(sub_domain) if not city: raise Http404 articles = atb.get_articles_by_city_id(city.id) # 分页 page_num = int(request.REQUEST.get('page', 1)) page_objs = page.Cpt(articles, count=20, page=page_num).info articles = page_objs[0] page_params = (page_objs[1], page_objs[4]) return render_to_response(template_name, locals(), context_instance=RequestContext(request))
def article_list(request, template_name='kaihu/article_list.html'): sub_domain = utils.get_sub_domain_from_http_host( request.META.get('HTTP_HOST', '')) city = cb.get_city_by_pinyin_abbr(sub_domain) if not city: raise Http404 articles = atb.get_articles_by_city_id(city.id) # 分页 page_num = int(request.REQUEST.get('page', 1)) page_objs = page.Cpt(articles, count=20, page=page_num).info articles = page_objs[0] page_params = (page_objs[1], page_objs[4]) return render_to_response(template_name, locals(), context_instance=RequestContext(request))
def latest_article(context): """ @note: 最新资讯 """ import re from common import utils from www.kaihu.interface import ArticleBase, CityBase city_abbr = utils.get_sub_domain_from_http_host(context['request'].META.get('HTTP_HOST', '')) city = CityBase().get_city_by_pinyin_abbr(city_abbr) path = context['request'].path p = re.compile(u'\/kaihu/article\/?\d*', re.I) ps = dict(city_id=city.id) if p.findall(path): ps.update(dict(order_by="?")) articles = ArticleBase().get_articles_by_city_id(**ps)[:10] return render_to_response('kaihu/_latest_article.html', locals(), context_instance=context).content
def process_request(self, request): setattr(request, "_process_start_timestamp", time.time()) sub_domain = utils.get_sub_domain_from_http_host( request.META.get('HTTP_HOST', '')) path = request.path if sub_domain not in ("127", "192"): if sub_domain not in ('www', 'wwwinside', 'static') and ( path not in ('', '/', '/message/get_unread_count_total', '/question/get_topic_info_by_id') and not path.startswith('/static') and not path.startswith('/kaihu')): raise Http404 if sub_domain in ('www', 'wwwinside', 'static') and path.startswith('/kaihu'): raise Http404 request.sub_domain = sub_domain
def process_request(self, request): setattr(request, "_process_start_timestamp", time.time()) sub_domain = utils.get_sub_domain_from_http_host(request.META.get('HTTP_HOST', '')) request.sub_domain = sub_domain
def _decorator(request, *args, **kwargs): city_abbr = utils.get_sub_domain_from_http_host(request.META.get('HTTP_HOST', '')) city = cb.get_city_by_pinyin_abbr(city_abbr) if not city: raise Http404 return func(request, *args, **kwargs)