当前位置: 首页>>代码示例>>Python>>正文


Python models.System_Config类代码示例

本文整理汇总了Python中shopcart.models.System_Config的典型用法代码示例。如果您正苦于以下问题:Python System_Config类的具体用法?Python System_Config怎么用?Python System_Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了System_Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

def login(request):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['page_name'] = 'Login'
	ctx = add_captcha(ctx) #添加验证码
	if request.method == 'GET':
		#GET请求,直接返回页面
		if 'next' in request.GET:
			ctx['next'] = request.GET['next']
		return render(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'])
		if myuser is not None:
			auth.login(request,myuser)
			mycart = merge_cart(request)
			redirect_url = reverse('product_view_list')
			if 'next' in request.POST:
				if len(request.POST['next']) > 0:
					redirect_url = request.POST['next']
			
			response = redirect(redirect_url)
			response.set_cookie('cart_id',mycart.id)
			response.set_cookie('imycartuser',myuser.email)
			return response
		else:
			ctx['login_result'] = _('Your account name or password is incorrect.')
			return render(request,System_Config.get_template_name() + '/login.html',ctx)
开发者ID:imycart,项目名称:imycart,代码行数:35,代码来源:myuser.py

示例2: reset_password

def reset_password(request):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['page_name'] = 'Reset Password'
	if request.method == 'GET':
		ctx['success_display'] = 'display:none;'
		ctx['form_display'] = ''
		try:
			#日期大小与比较要用 "日期字段名__gt=" 表示大于
			reset_password = Reset_Password.objects.filter(expirt_time__gt=datetime.datetime.now()).get(email=request.GET['email'],validate_code=request.GET['validate_code'],is_active=True)
			ctx['email'] = reset_password.email
			ctx['validate_code'] = reset_password.validate_code
			return render(request,System_Config.get_template_name() + '/reset_password.html',ctx)
		except:
			raise Http404
			#ctx['form_display'] = 'none'
			#ctx['reset_message'] = _('Can not find the password reset apply request.')
	else:
		try:
			reset_password = Reset_Password.objects.filter(expirt_time__gt=datetime.datetime.now()).get(email=request.POST['email'],validate_code=request.POST['validate_code'],is_active=True)
			myuser = MyUser.objects.get(email=reset_password.email)
			myuser.set_password(request.POST['password'])
			reset_password.is_active = False
			reset_password.save()
			myuser.save()
			ctx['success_display'] = ''
			ctx['form_display'] = 'display:none;'
			ctx['reset_message'] = _('The password has been reseted.')
		except:
			ctx['success_display'] = ''
			ctx['form_display'] = 'display:none;'
			ctx['reset_message'] = _('Opration faild.')		
		return render(request,System_Config.get_template_name() + '/reset_password.html',ctx)
开发者ID:imycart,项目名称:imycart,代码行数:33,代码来源:myuser.py

示例3: register

def register(request):
	ctx = {}
	ctx.update(csrf(request))
	ctx['system_para'] = get_system_parameters()
	ctx['menu_products'] = get_menu_products()
	ctx['page_name'] = 'Regitser'
	ctx = add_captcha(ctx) #添加验证码
	logger.debug('Enter register function.')
	if request.method == 'GET':
		#GET请求,直接返回页面
		return TemplateResponse(request,System_Config.get_template_name() + '/register.html',ctx)
	else:
		form = register_form(request.POST) # 获取Post表单数据
		if form.is_valid():# 验证表单
			from .utils import get_remote_ip
			ip = get_remote_ip(request)
			myuser = MyUser.objects.create_user(username=None,email=form.cleaned_data['email'].lower(),password=form.cleaned_data['password'],first_name=form.cleaned_data['first_name'],last_name=form.cleaned_data['last_name'])
			myuser.reg_ip = ip
			myuser.last_ip = ip
			myuser.save()
			
			#触发用户注册成功的事件
			signals.user_registration_success.send(sender='MyUser',user=myuser)
			#return redirect('/user/login')
			
			#准备登陆
			myuser.password = form.cleaned_data['password']
			return inner_login(request,myuser,ctx)
		else:
			logger.error('form is not valid')
			ctx['reg_result'] = _('Registration faild.')
			return TemplateResponse(request,System_Config.get_template_name() + '/register.html',ctx)			
开发者ID:icetusorg,项目名称:cetusshop,代码行数:32,代码来源:myuser.py

示例4: do_login

def do_login(request,myuser,ctx):
	logger.debug('do_login myuser:%s' % myuser)
	if myuser is not None:
		if myuser.is_active == True:
			auth.login(request,myuser)
			from .utils import get_remote_ip
			ip = get_remote_ip(request)
			myuser.last_ip = ip
			myuser.save()
			mycart = merge_cart(request)
			redirect_url = reverse('product_view_list')
			if 'next' in request.POST:
				if len(request.POST['next']) > 0:
					redirect_url = request.POST['next']
				
			response = redirect(redirect_url)
			response.set_cookie('cart_id',mycart.id,max_age = 3600*24*365)
			response.set_cookie('cart_item_type_count',mycart.cart_products.all().count(),max_age = 3600*24*365)
			response.set_cookie('icetususer',myuser.email)
			logger.debug('>>>>>>>>>user.backend:%s , type is %s' % (myuser.backend,type(myuser.backend)))
			return response
		else:
			ctx['login_result'] = _('Your account has been banned!')
			return TemplateResponse(request,System_Config.get_template_name() + '/login.html',ctx)
	else:
		ctx['login_result'] = _('Your account name or password is incorrect.')
		return TemplateResponse(request,System_Config.get_template_name() + '/login.html',ctx)	
开发者ID:icetusorg,项目名称:cetusshop,代码行数:27,代码来源:myuser.py

示例5: detail

def detail(request,id):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['page_name'] = 'Blog'
	try:
		article = Article.objects.get(id=id)
	except:
		raise Http404
		
	ctx['article'] = article
		
	if request.method =='GET': #正常访问,返回动态页面
		return render(request,System_Config.get_template_name() + '/article.html', ctx)
	elif request.method == 'POST':#通过ajax访问,生成静态文件
		content = render_to_string(System_Config.get_template_name() + '/article.html', ctx)
		result_dict = {}
		try:
			import codecs,os
			#先获取商品所属分类,作为目录
			dir = 'media/' + article.folder
			if not os.path.exists(dir):
				os.makedirs(dir)
			f = codecs.open(dir + article.static_file_name ,'w','utf-8')
			f.write(content)
			f.close()
			result_dict['success'] = True
			result_dict['message'] = _('File already generated.')
		except Exception as err:
			logger.error('写文件失败。' + str(err))
			result_dict['success'] = False
			result_dict['message'] = _('File generate failed.')
		finally:
			if f is not None:
				f.close()
		return JsonResponse(result_dict)
开发者ID:imycart,项目名称:imycart,代码行数:35,代码来源:article.py

示例6: forget_password

def forget_password(request):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['menu_products'] = get_menu_products()
	ctx['page_name'] = 'Forget Password'
	ctx = add_captcha(ctx) #添加验证码
	if request.method == 'GET':
		ctx['form_display'] = ''
		ctx['success_display'] = 'display:none;'
		return render(request,System_Config.get_template_name() + '/forget_password.html',ctx)
	else:
		form = captcha_form(request.POST) # 获取Post表单数据
		if form.is_valid():
			ctx['form_display'] = 'display:none;'
			ctx.update(csrf(request))
			s_uuid = str(uuid.uuid4())
			reset_password = Reset_Password.objects.create(email=request.POST['email'],validate_code=s_uuid,apply_time=datetime.datetime.now(),expirt_time=(datetime.datetime.now() + datetime.timedelta(hours=24)),is_active=True)
			mail_ctx = {}
			mail_ctx['reset_url'] =  System_Config.get_base_url() + "/user/reset-password?email=" + reset_password.email + "&validate_code=" + reset_password.validate_code
			my_send_mail(useage='reset_password',ctx=mail_ctx,send_to=reset_password.email,title=_('You are resetting you password in %(site_name)s .') % {'site_name':System_Config.objects.get(name='site_name').val})
			ctx['apply_message'] = _('If there is an account associated with %(email_address)s you will receive an email with a link to reset your password.') % {'email_address':reset_password.email}
			ctx['success_display'] = ''
		else:
			ctx['apply_message'] = _('Please check your verify code.')
		return render(request,System_Config.get_template_name() + '/forget_password.html',ctx)
开发者ID:imycartorg,项目名称:imycart,代码行数:25,代码来源:myuser.py

示例7: __init__

	def __init__(self,timestamp,nonce,echostr,signature):
		self.ret = {
			'app_id':System_Config.objects.get(name='wechat_app_id').val,
			'timestamp':timestamp,
			'nonce':nonce,
			'echostr':echostr,
			'token':System_Config.objects.get(name='wechat_token').val,
			'signature':signature,
			'wechat_api_url':System_Config.get(name='wechat_api_url').val,
			'wechat_api_port':System_Config.get(name='wechat_api_port').val
		}
开发者ID:imycart,项目名称:imycart,代码行数:11,代码来源:wechat.py

示例8: detail

def detail(request,id):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['menu_products'] = get_menu_products()
	ctx['page_name'] = 'Blog'
	try:
		article = Article.objects.get(id=id)
	except:
		raise Http404
		
	ctx['article'] = article
		
	template = '/article.html'
		
	if article.detail_template != '':
		if article.detail_template != 'USE_DEFAULT':
			template = '/custmize/' + article.detail_template	
	
	logger.info('The template name is %s' % template)
	
	if request.method =='GET': #正常访问,返回动态页面
		return render(request,System_Config.get_template_name() + template, ctx)
	elif request.method == 'POST':#通过ajax访问,生成静态文件
		content = render_to_string(System_Config.get_template_name() + template, ctx)
		result_dict = {}
		try:
			import codecs,os
			dir = 'www/' + article.folder
			dir_http = article.folder
			
			if not os.path.exists(dir):
				os.makedirs(dir)
				
			if not dir.endswith('/'):
				dir = dir + '/'
				
			if not dir_http.endswith('/'):
				dir_http = dir_http + '/'
			
			f = codecs.open(dir + article.static_file_name ,'w','utf-8')
			f.write(content)
			f.close()
			result_dict['success'] = True
			result_dict['message'] = _('File already generated.')
			result_dict['static_url'] = dir_http + article.static_file_name
		except Exception as err:
			logger.error('写文件失败。' + str(err))
			result_dict['success'] = False
			result_dict['message'] = _('File generate failed.')
		finally:
			if f is not None:
				f.close()
		return JsonResponse(result_dict)
开发者ID:imycartorg,项目名称:imycart,代码行数:53,代码来源:article.py

示例9: place_order

def place_order(request):
	logger.info('Start to place order.')
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['page_name'] = 'Place Order'
	if request.method == 'POST':
		logger.debug('address_id:' + str(request.POST['address_id']))
		try:
			address = Address.objects.get(id=request.POST['address_id'])
		except:
			ctx['order_result'] = _('Address is not correct')
			return render(request,System_Config.get_template_name() + '/order_result.html',ctx)
			
		if address not in request.user.addresses.all():
			#如果这个地址不是这个用户的,报错
			ctx['order_result'] = 'System Error.Please try again.'
			return render(request,System_Config.get_template_name() + '/order_result.html',ctx)
		
		#金额
		sub_total,shipping,discount,total,remark = request.POST['sub_total'],request.POST['shipping'],request.POST['discount'],request.POST['total'],request.POST['remark']
		logger.debug('>>>>>0:sub_total=' + str(sub_total))
		#生成主订单
		logger.debug('>>>>>1')
		order = Order.objects.create(order_number=get_serial_number(),user=request.user,status=Order.ORDER_STATUS_PLACE_ORDER,country=address.country,province=address.province,city=address.city,district=address.district,address_line_1=address.address_line_1,
			address_line_2=address.address_line_2,first_name=address.first_name,last_name=address.last_name,zipcode=address.zipcode,tel=address.tel,mobile=address.mobile,email=request.user.email,
			products_amount = sub_total,shipping_fee=shipping,discount=discount,order_amount=total,to_seller=remark)

		logger.debug('>>>>>2:order.id='+str(order.id))
		cart_product_id = request.POST.getlist('cart_product_id',[])
		logger.debug('>>>>>3:cart_product_id='+str(cart_product_id))
		
		#计算汇总金额
		amount_to_check = 0.00
		
		for cp_id in cart_product_id:
			cp = Cart_Products.objects.get(id=cp_id)
			
			amount_to_check = amount_to_check + cp.get_total()
			#向主订单加入商品
			logger.debug('>>>>>5:product.id='+str(cp.product.id))
			op = Order_Products.objects.create(product_id=cp.product.id,product_attribute=cp.product_attribute,order=order,name=cp.product.name,short_desc=cp.product.short_desc,price=cp.get_product_price(),
				thumb=cp.product.thumb,image=cp.product.image,quantity=cp.quantity)
			logger.debug('>>>>>6:op.id='+str(op.id))
			#删除购物车中商品
			cp.delete()
			logger.debug('>>>>>8:cp.delete')
		
		#TODO:校验总金额是否正确,不正确则抛出异常
		logger.debug('>>>>>9:amount_to_check=' + str(amount_to_check))
		if abs(amount_to_check-float(sub_total)) > 0.01: #浮点数比较,没法直接用 ==
			raise Exception('System error.Please try again.')
		
		return redirect('/cart/payment/' + str(order.id))
开发者ID:imycart,项目名称:imycart,代码行数:53,代码来源:order.py

示例10: handle_uploaded_file

def handle_uploaded_file(f,type='other',product_sn='-1'):
	file_name = ""

	file_names = {}
	
	if not type.endswith('/'):
		type += '/'
	if not product_sn.endswith('/'):
		product_sn += '/'
	
	destination = None
	try:
		path = 'media/' + type + product_sn
		import os
		if not os.path.exists(path):
			os.makedirs(path)
			
		ext = f.name.split('.')[-1]
		logger.debug(str(ext))
		
		#允许上传的类型
		file_allow = ['JPG','JPEG','PNG','GIF']
		if ext.upper() not in file_allow:
			raise Exception('%s File type is not allowed to upload.' % [ext])
		
		random_name = str(uuid.uuid1())
		
		file_name = path + random_name + '.' + ext
		file_thumb_name = path + random_name + '-thumb' + '.' + ext
		
		destination = open(file_name, 'wb+')
		logger.debug('file_name: %s' % file_name)
		for chunk in f.chunks():
			destination.write(chunk)
		destination.close()
		
		result = thumbnail(file_name,file_thumb_name)
		if not result:
			raise Exception('thumbnail failed.')
		else:
			file_names['image'] = file_name
			file_names['thumb'] = file_thumb_name
			file_names['image_url'] = System_Config.get_base_url() + '/' + file_name
			file_names['thumb_url'] = System_Config.get_base_url() + '/' + file_thumb_name
	except Exception as e:
		#pass
		logger.error(str(e))
	finally:
		if destination:
			destination.close()
	return file_names
开发者ID:imycart,项目名称:imycart,代码行数:51,代码来源:utils.py

示例11: edit

def edit(request):
    ctx = {}
    ctx['system_para'] = get_system_parameters()
    ctx['page_name'] = '文章分类管理'

    if request.method == 'GET':
        id = request.GET.get('id', '')
        try:
            category = ArticleBusiCategory.objects.get(id=id)
            ctx['category'] = category
        except Exception as err:
            logger.error("Can not find ArticleBusiCategory which id is %s . \n Error message: %s" % (id, err))

        # 加载自定义模板供选择
        from .file import file_list
        template_list = file_list(System_Config.get_template_name('client') + '/custmize/',
                                  'custmize_template_article_category')
        logger.debug('>>>>>>>>>>>>>>>>>>custmize_template_article_category: %s' % template_list)
        ctx['custmize_template'] = template_list

        return TemplateResponse(request,
                                System_Config.get_template_name('admin') + '/article_busi_category_detail.html', ctx)
    elif request.method == 'POST':
        result = {}
        result['success'] = False
        result['message'] = '文章分类保存失败'
        category = None

        try:
            id = request.POST.get('id', '')
            category = ArticleBusiCategory.objects.get(id=id)
        except Exception as err:
            logger.info(
                'Can not find ArticleBusiCategory which id is [%s]. Create one. \n Error Message: %s' % (id, err))

        if category:
            form = article_busi_category_form(request.POST, instance=category)
        else:
            form = article_busi_category_form(request.POST)

        if form.is_valid():
            category = form.save()
            result['success'] = True
            result['message'] = '文章分类保存成功'
            result['category_id'] = category.id
        return JsonResponse(result)

    else:
        raise Http404
开发者ID:icetusorg,项目名称:cetusshop,代码行数:49,代码来源:article_busi_category.py

示例12: view_blog_list

def view_blog_list(request):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['menu_products'] = get_menu_products()
	ctx['page_name'] = 'Blog'
	
	try:
		blog_list_page_size = System_Config.objects.get('blog_list_page_size')
	except:
		logger.debug('blog_list_page_size is not defined,use the default value 12.')
		blog_list_page_size = 12
	
	if request.method =='GET':
		product_list = None
		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)
		
		if 'page_size' in request.GET:
			logger.debug('the page_size has been detacted')
			article_list, page_range = my_pagination(request=request, queryset=article_list,display_amount=request.GET['page_size'])
		else:
			article_list, page_range = my_pagination(request=request, queryset=article_list,display_amount=blog_list_page_size)
		
		ctx['article_list'] = article_list
		ctx['page_range'] = page_range
		return render(request,System_Config.get_template_name() + '/blog_list.html',ctx)
开发者ID:imycartorg,项目名称:imycart,代码行数:34,代码来源:article.py

示例13: list

def list(request):
    ctx = {}
    ctx['system_para'] = get_system_parameters()
    ctx['page_name'] = '文章分类管理'

    if request.method == 'GET':
        # category_list = ArticleBusiCategory.objects.all().order_by('-update_time')
        category_list = ArticleBusiCategory.objects.all().order_by('-sort_order')

        count = category_list.count()

        page_size = get_page_size()
        category_list, page_range, current_page = my_pagination(request=request, queryset=category_list,
                                                                display_amount=page_size)

        ctx['category_list'] = category_list
        ctx['page_range'] = page_range
        ctx['page_size'] = page_size
        ctx['current_page'] = current_page
        ctx['count'] = count

        return TemplateResponse(request, System_Config.get_template_name('admin') + '/article_busi_category_list.html',
                                ctx)
    elif request.method == 'POST':
        raise Http404
    else:
        raise Http404
开发者ID:icetusorg,项目名称:cetusshop,代码行数:27,代码来源:article_busi_category.py

示例14: price_adjusment

def price_adjusment(request):
	result_dict = {}
	if request.method == 'POST':
		order_id = request.POST.get('order_id','')
		price = request.POST.get('price_adjusment','0')
		
		logger.debug('price_adjusment:%s' % price)
		
		try:
			order = Order.objects.get(id=order_id)
			price = float(price)
		except Exception as err:
			logger.error('Can not find order [%s] \n Error Message:%s' %(order_id,err))
			result_dict['success'] = False
			result_dict['message'] = '价格调整失败'
			return JsonResponse(result_dict)
		
		
		order.price_adjusment = price
		order.calculate_total_price()
		order.save()
		result_dict['success'] = True
		result_dict['message'] = '价格调整成功'
		return JsonResponse(result_dict)
	else:
		ctx = {}
		ctx['system_para'] = get_system_parameters()
		ctx['page_name'] = '价格调整'
		ctx['order_id'] = request.GET.get('order_id')
		return TemplateResponse(request,System_Config.get_template_name('admin') + '/order_price_adjusment.html',ctx)
开发者ID:icetusorg,项目名称:cetusshop,代码行数:30,代码来源:order.py

示例15: view_list

def view_list(request):
	ctx = {}
	ctx['system_para'] = get_system_parameters()
	ctx['page_name'] = 'Product'
	
	if request.method =='GET':
		product_list = None
		if 'sort_by' in request.GET:
			if 'direction' in request.GET:
				if 'desc' == request.GET['direction']:
					product_list = Product.objects.filter(is_publish=True).order_by(request.GET['sort_by']).reverse()
				else:
					product_list = Product.objects.filter(is_publish=True).order_by(request.GET['sort_by'])
				
				ctx['direction'] = request.GET['direction']
			else:
				product_list = Product.objects.filter(is_publish=True).order_by(request.GET['sort_by'])
		else:
			logger.debug("all products")
			product_list = Product.objects.filter(is_publish=True)
		
		logger.debug("no sort_by")
		if 'page_size' in request.GET:
			page_size = request.GET['page_size']
		else:
			try:
				page_size = int(System_Config.objects.get(name='product_page_size'))
			except:
				page_size = 12
		
		product_list, page_range = my_pagination(request=request, queryset=product_list,display_amount=page_size)
		
		ctx['product_list'] = product_list
		ctx['page_range'] = page_range
		return render(request,System_Config.get_template_name() + '/product_list.html',ctx)
开发者ID:imycart,项目名称:imycart,代码行数:35,代码来源:product.py


注:本文中的shopcart.models.System_Config类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。