def view_index(request,tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() if not tdk: try: cust = CustomizeURL.objects.get(name = '首页') if cust.is_customize_tdk: tdk = {} tdk['page_title'] = cust.page_name tdk['keywords'] = cust.keywords tdk['short_desc'] = cust.short_desc except Exception as err: tdk = None if tdk: customize_tdk(ctx,tdk) from .oauth import SocialSites, SocialAPIError socialsites = SocialSites() s = socialsites.get_site_object_by_name('wechat') ctx['oauth'] = s.authorize_url return TemplateResponse(request,System_Config.get_template_name() + '/index.html',ctx)
def login(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Login' ctx = add_captcha(ctx) #添加验证码 customize_tdk(ctx, tdk) if request.method == 'GET': #GET请求,直接返回页面 if 'next' in request.GET: ctx['next'] = request.GET['next'] return TemplateResponse( request, System_Config.get_template_name() + '/login.html', ctx) else: ctx.update(csrf(request)) form = captcha_form(request.POST) # 获取Post表单数据 if 'next' in request.POST: next = request.POST['next'] ctx['next'] = next #if form.is_valid():# 验证表单,会自动验证验证码,(新版不要验证码了) myuser = auth.authenticate(username=request.POST['email'].lower(), password=request.POST['password']) return do_login(request, myuser, ctx)
def contact_page(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Contact us' customize_tdk(ctx, tdk) return TemplateResponse( request, System_Config.get_template_name() + '/contact.html', ctx)
def view_index(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() def get_all_top_menu(): top_menu_list = Menu.objects.filter(parent=None) return top_menu_list top_menu_list = get_all_top_menu() ctx['menu_list'] = top_menu_list if not tdk: try: cust = CustomizeURL.objects.get(name='首页') if cust.is_customize_tdk: tdk = {} tdk['page_title'] = cust.page_name tdk['keywords'] = cust.keywords tdk['short_desc'] = cust.short_desc except Exception as err: tdk = None if tdk: customize_tdk(ctx, tdk) # from .oauth import SocialSites, SocialAPIError # socialsites = SocialSites() # s = socialsites.get_site_object_by_name('facebook') # ctx['oauth'] = s.authorize_url # 判断网站服务是否到期 maturity_data = System_Config.objects.get( name='maturity_data').val # 获取到期时间 new_maturity_data = time.strptime(maturity_data, "%Y-%m-%d %H:%M:%S") # 转化为时间戳 new_maturity_data_time = time.mktime(new_maturity_data) now_time = int(time.time()) # 获取当前时间 if now_time - new_maturity_data_time >= 0: return TemplateResponse( request, System_Config.get_template_name() + '/index_error.html', ctx) else: return TemplateResponse( request, System_Config.get_template_name() + '/index.html', ctx)
def contact_page(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Contact us' def get_all_top_menu(): top_menu_list = Menu.objects.filter(parent=None) return top_menu_list top_menu_list = get_all_top_menu() ctx['menu_list'] = top_menu_list customize_tdk(ctx, tdk) return TemplateResponse( request, System_Config.get_template_name() + '/contact.html', ctx)
def view_index(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() def get_all_top_menu(): top_menu_list = Menu.objects.filter(parent=None) return top_menu_list top_menu_list = get_all_top_menu() ctx['menu_list'] = top_menu_list if not tdk: try: cust = CustomizeURL.objects.get(name='首页') if cust.is_customize_tdk: tdk = {} tdk['page_title'] = cust.page_name tdk['keywords'] = cust.keywords tdk['short_desc'] = cust.short_desc except Exception as err: tdk = None if tdk: customize_tdk(ctx, tdk) # from .oauth import SocialSites, SocialAPIError # socialsites = SocialSites() # s = socialsites.get_site_object_by_name('facebook') # ctx['oauth'] = s.authorize_url # 判断网站服务是否到期 maturity_data = System_Config.objects.get(name='maturity_data').val # 获取到期时间 new_maturity_data = time.strptime(maturity_data, "%Y-%m-%d %H:%M:%S") # 转化为时间戳 new_maturity_data_time = time.mktime(new_maturity_data) now_time = int(time.time()) # 获取当前时间 if now_time - new_maturity_data_time >= 0: return TemplateResponse(request, System_Config.get_template_name() + '/index_error.html', ctx) else: return TemplateResponse(request, System_Config.get_template_name() + '/index.html', ctx)
def view_list_view(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() def get_all_top_menu(): top_menu_list = Menu.objects.filter(parent=None) return top_menu_list top_menu_list = get_all_top_menu() ctx['menu_list'] = top_menu_list if tdk: customize_tdk(ctx, tdk) if request.method == 'GET': all = Recruit.objects.all().order_by('-sort_order') page_size = get_page_size() # count = len(all) recruit_list, page_range, current_page = my_pagination( request=request, queryset=all, display_amount=page_size) logger.debug('current_page:%s' % current_page) # 为页面准备分类的下拉列表 # from shopcart.myadmin.article_busi_category import get_all_category # busi_category_list = get_all_category() # logger.debug('busi_category_list : %s' % busi_category_list) # ctx['busi_category_list'] = busi_category_list ctx['recruit_list'] = recruit_list ctx['page_range'] = page_range ctx['page_size'] = page_size ctx['current_page'] = current_page # ctx['article_count'] = count logger.debug('正常访问招聘页面' + System_Config.get_template_name()) return TemplateResponse( request, System_Config.get_template_name() + '/recruit_list.html', ctx) else: raise Http404
def login(request,tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Login' ctx = add_captcha(ctx) #添加验证码 customize_tdk(ctx,tdk) if request.method == 'GET': #GET请求,直接返回页面 if 'next' in request.GET: ctx['next'] = request.GET['next'] return TemplateResponse(request,System_Config.get_template_name() + '/login.html',ctx) else: ctx.update(csrf(request)) form = captcha_form(request.POST) # 获取Post表单数据 if 'next' in request.POST: next = request.POST['next'] ctx['next'] = next #if form.is_valid():# 验证表单,会自动验证验证码,(新版不要验证码了) myuser = auth.authenticate(username = request.POST['email'].lower(), password = request.POST['password']) return do_login(request,myuser,ctx)
def view_list_view(request, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() def get_all_top_menu(): top_menu_list = Menu.objects.filter(parent=None) return top_menu_list top_menu_list = get_all_top_menu() ctx['menu_list'] = top_menu_list if tdk: customize_tdk(ctx, tdk) if request.method == 'GET': all = Recruit.objects.all().order_by('-sort_order') page_size = get_page_size() # count = len(all) recruit_list, page_range, current_page = my_pagination(request=request, queryset=all, display_amount=page_size) logger.debug('current_page:%s' % current_page) # 为页面准备分类的下拉列表 # from shopcart.myadmin.article_busi_category import get_all_category # busi_category_list = get_all_category() # logger.debug('busi_category_list : %s' % busi_category_list) # ctx['busi_category_list'] = busi_category_list ctx['recruit_list'] = recruit_list ctx['page_range'] = page_range ctx['page_size'] = page_size ctx['current_page'] = current_page # ctx['article_count'] = count logger.debug('正常访问招聘页面' + System_Config.get_template_name()) return TemplateResponse(request, System_Config.get_template_name() + '/recruit_list.html', ctx) else: raise Http404
def view_blog_list(request, category_id=None, tdk=None): ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'Blog' def get_all_top_menu(): top_menu_list = Menu.objects.filter(parent=None) return top_menu_list top_menu_list = get_all_top_menu() ctx['menu_list'] = top_menu_list if tdk: customize_tdk(ctx, tdk) try: blog_list_page_size_item = System_Config.objects.get(name='blog_list_page_size') blog_list_page_size = blog_list_page_size_item.val logger.debug('blog_list_page_size is %s .' % blog_list_page_size) except Exception as err: logger.debug('blog_list_page_size is not defined,use the default value 12. \Error Message:%s' % err) blog_list_page_size = 12 if request.method == 'GET': template = 'product_list.html' if 'sort_by' in request.GET: if 'direction' in request.GET: if 'desc' == request.GET['direction']: article_list = Article.objects.filter(category=Article.ARTICLE_CATEGORY_BLOG).order_by( request.GET['sort_by']).reverse() else: article_list = Article.objects.filter(category=Article.ARTICLE_CATEGORY_BLOG).order_by( request.GET['sort_by']) else: article_list = Article.objects.filter(category=Article.ARTICLE_CATEGORY_BLOG).order_by( request.GET['sort_by']) else: article_list = Article.objects.filter(category=Article.ARTICLE_CATEGORY_BLOG).order_by('-sort_order') # 按分类筛选 logger.debug('category_id : %s ' % category_id) if category_id: # 查找该分类是否设置了自定义的分类模板 try: category = ArticleBusiCategory.objects.get(id=category_id) ctx['page_key_words'] = category.keywords ctx['page_description'] = category.short_desc if category.page_title: ctx['page_name'] = category.page_title else: ctx['page_name'] = category.name if category.category_template: template = '/custmize/article_category/' + category.category_template article_list = article_list.filter(busi_category=category) except Exception as err: logger.error('Can not find category which id is %s. Error message is %s ' % (category_id, err)) if 'page_size' in request.GET: logger.debug('the page_size has been detacted') article_list, page_range, current_page = my_pagination(request=request, queryset=article_list, display_amount=request.GET['page_size']) else: article_list, page_range, current_page = my_pagination(request=request, queryset=article_list, display_amount=blog_list_page_size) ctx['article_list'] = article_list ctx['page_range'] = page_range ctx['current_page'] = current_page logger.info('template : ' + template) return TemplateResponse(request, System_Config.get_template_name() + '/' + template, ctx)