Beispiel #1
0
def file_delete(request,item_type,item_id,host_item_id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	ctx['file_delete_url'] = '/file-delete/' + item_type
	if request.method == 'GET':
		try:
			if item_type == 'product':
				image = Product_Images.objects.get(id=item_id)
				image.delete()
			elif item_type == 'product_album':
				image = Album.objects.get(id=item_id)
				image.delete()
			elif item_type == 'article':
				image = Album.objects.get(id=item_id)
				image.delete()
			else:
				raise Http404
		except:
			raise Http404
		
		redirect_url = '/admin/file-upload/' + item_type + '/' + host_item_id + "/"
		if 'return_url' in request.GET:
			redirect_url = request.GET.get('return_url')
		
		return redirect(redirect_url)
Beispiel #2
0
def view_index(request):
    logger.info('开始展示首页')
    hashkey = CaptchaStore.generate_key()
    imgage_url = captcha_image_url(hashkey)
    ctx = {}
    ctx['system_para'] = System_Para.get_default_system_parameters()
    ctx['hashkey'] = hashkey
    ctx['imgage_url'] = imgage_url
    #ctx['i18n_text'] = _('Welcome to %(site_name)s.') % {'site_name':'imycart.com 小伙伴的购物车'}
    ctx['i18n_text'] = _(
        'You are resetting you password in %(sitename)s .') % {
            'sitename': System_Config.objects.get(name='site_name').val
        }
    ctx['i18n_text_test'] = _('Today is %(sitename)s.') % {'sitename': 9}
    ctx['i18n_text_near_example'] = _('Today is %(month)s.') % {'month': 9}
    ctx['i18n_text_example'] = _('Today is %(month)s %(day)s.') % {
        'month': 9,
        'day': 6
    }
    ctx['value'] = 2980.0
    ctx['show_const'] = Order.ORDER_STATUS_PAYED_UNCONFIRMED
    logger.info('i18n_text:' + ctx['i18n_text'])

    #测试下微信的分享功能

    #要注意最后的那个 /  !!!!!妈的,搞了两天,一直不行,就因为这个/
    jssdk_sign = WechatJSSDKSign('http://aws.imycart.com/')
    jssdk_config = jssdk_sign.sign()
    ctx['wechat_config'] = jssdk_config

    return render(request,
                  System_Config.get_template_name() + '/index.html', ctx)
Beispiel #3
0
def info(request):
    ctx = {}
    ctx.update(csrf(request))
    ctx['system_para'] = System_Para.get_default_system_parameters()
    if request.method == 'GET':
        #GET请求,直接返回页面
        return render(request,
                      System_Config.get_template_name() + '/user_info.html',
                      ctx)
    else:
        logger.debug("Modify User Info")
        form = user_info_form(request.POST)  # 获取Post表单数据
        myuser = request.user
        if form.is_valid():  # 验证表单
            myuser.first_name = form.cleaned_data['first_name']
            myuser.last_name = form.cleaned_data['last_name']
            logger.debug(myuser.last_name)
        else:
            logger.debug('not validate')
        if 'changePassword' in request.POST:
            #需要更改密码
            myuser.set_password(request.POST['password'])
        else:
            #不更改密码
            logger.debug('not checked')
        myuser.save()
        return redirect('/user/info/?success=true')
Beispiel #4
0
def info(request):
	ctx = {}
	ctx.update(csrf(request))
	ctx['system_para'] = System_Para.get_default_system_parameters()	
	if request.method == 'GET':
		#GET请求,直接返回页面
		return render(request,System_Config.get_template_name() + '/user_info.html',ctx)
	else:
		logger.debug("Modify User Info")
		form = user_info_form(request.POST) # 获取Post表单数据
		myuser = request.user
		if form.is_valid():# 验证表单
			myuser.first_name = form.cleaned_data['first_name']
			myuser.last_name = form.cleaned_data['last_name']
			logger.debug(myuser.last_name)
		else:
			logger.debug('not validate')
		if 'changePassword' in request.POST:
			#需要更改密码
			myuser.set_password(request.POST['password'])
		else:
			#不更改密码
			logger.debug('not checked')
		myuser.save()
		return redirect('/user/info/?success=true')
Beispiel #5
0
def file_upload(request,item_type,item_id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	ctx['action_url'] = '/file-upload/' + item_type + '/' + item_id + "/"
	ctx['file_delete_url'] = '/file-delete/' + item_type
	ctx['host_item_id'] = item_id
	if request.method == 'GET':
		if item_type == 'product' or item_type == 'product_album':
			try:
				item = Product.objects.get(id=item_id)
				ctx['item'] = item
				try:
					ctx['image_list'] = Product_Images.objects.filter(product=item).order_by('create_time').reverse()
					if item_type == 'product_album':
						ctx['image_list'] = Album.objects.filter(item_type=item_type,item_id=item.id).order_by('create_time').reverse()
				except:
					ctx['image_list'] = []
			except:
				raise Http404
		elif item_type == 'article':
			raise Http404
		else:
			raise Http404
		return render(request,System_Config.get_template_name() + '/file_upload.html',ctx)
	else:
		if item_type == 'product' or item_type == 'product_album':
			try:
				item = Product.objects.get(id=item_id)
			except:
				raise Http404
			filenames = handle_uploaded_file(request.FILES['upload'],item_type,item_id)
			#加入到对象的图片列表中去
			if item_type == 'product':
				pi = Product_Images.objects.create(image=filenames['image_url'],thumb=filenames['thumb_url'],product=item)
			else:
				ai = Album.objects.create(image=filenames['image_url'],thumb=filenames['thumb_url'],item_type=item_type,item_id=item.id)
		elif item_type == 'article':
			try:
				item = Article.objects.get(id=item_id)
			except:
				raise Http404
			filenames = handle_uploaded_file(request.FILES['upload'],item_type,item_id)
			ai = Album.objects.create(image=filenames['image_url'],thumb=filenames['thumb_url'],item_type=item_type,item_id=item.id)
		else:
			raise Http404
		#判断是否是从CKEDITER传上来的
		if 'CKEditorFuncNum' in request.GET:
			logger.debug('请求来自CKEDITER.')
			script = '<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction("' + request.GET['CKEditorFuncNum'] + '","' + filenames['image_url'] + '");</script>';
			logger.debug('返回的script: %s' % [script])
			return HttpResponse(script,content_type='text/html;charset=UTF-8')
		return redirect('/file-upload/' + item_type + '/' + item_id + "/")
Beispiel #6
0
def ckediter(request,item_type,item_id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	ctx['upload_url'] = '/admin/file-upload/' + item_type + '/' + item_id + '/'
	ctx['article_content'] = ''
	ctx['id'] = item_id
	if request.method == 'GET':
		try:
			if item_type == 'product':
				ctx['article_content'] = Product.objects.get(id=item_id).description
			elif item_type == 'article':
				ctx['article_content'] = Article.objects.get(id=item_id).content
			else:
				raise Http404
		except:
			raise Http404
		return render(request,'admin/ckediter.html',ctx)
Beispiel #7
0
def ckediter(request,item_type,item_id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	ctx['upload_url'] = '/admin/file-upload/' + item_type + '/' + item_id + '/'
	ctx['article_content'] = ''
	ctx['id'] = item_id
	if request.method == 'GET':
		try:
			if item_type == 'product':
				ctx['article_content'] = Product.objects.get(id=item_id).description
			elif item_type == 'article':
				ctx['article_content'] = Article.objects.get(id=item_id).content
			else:
				raise Http404
		except:
			raise Http404
		return render(request,'admin/ckediter.html',ctx)
Beispiel #8
0
def file_delete(request,item_type,item_id,host_item_id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	ctx['file_delete_url'] = '/file-delete/' + item_type
	if request.method == 'GET':
		try:
			if item_type == 'product':
				image = Product_Images.objects.get(id=item_id)
				image.delete()
			elif item_type == 'product_album':
				image = Album.objects.get(id=item_id)
				image.delete()
			elif item_type == 'article':
				raise Http404
			else:
				raise Http404
		except:
			raise Http404
		return redirect('/file-upload/' + item_type + '/' + host_item_id + "/")
Beispiel #9
0
def product_opration(request, opration, id):
    ctx = {}
    ctx['system_para'] = System_Para.get_default_system_parameters()
    if request.method == 'GET':
        if opration == 'add':
            if id != '0':
                ctx['image_upload_url'] = '/admin/file-upload/product/%s/' % id
                ctx['edit_url'] = '/admin/shopcart/product/%s/change/' % id
            return render(request, 'admin/product/add.html', ctx)
        else:
            raise Http404
    elif request.method == 'POST':
        if opration == 'add':
            form = product_add_form(request.POST)
            if form.is_valid():
                product = form.save()
                logger.debug('product id: %s' % product.id)
                return redirect('/admin/product/add/%s' % product.id)
            else:
                logger.error('form is not valid')
    else:
        raise Http404
Beispiel #10
0
def product_opration(request,opration,id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	if request.method == 'GET':
		if opration == 'add':
			if id != '0':
				ctx['image_upload_url'] = '/admin/file-upload/product/%s/' % id
				ctx['edit_url'] = '/admin/shopcart/product/%s/change/' % id
			return render(request,'admin/product/add.html',ctx)
		else:
			raise Http404
	elif request.method == 'POST':
		if opration == 'add':
			form = product_add_form(request.POST)
			if form.is_valid():
				product = form.save()
				logger.debug('product id: %s' % product.id)
				return redirect('/admin/product/add/%s' % product.id)
			else:
				logger.error('form is not valid')
	else:
		raise Http404
Beispiel #11
0
def product_list(request):
    ctx = {}
    ctx['system_para'] = System_Para.get_default_system_parameters()
    if request.method == 'GET':

        name_condition = request.GET.get('name', '')
        item_number_condition = request.GET.get('item_number', '')
        from django.db.models import Q
        product_list = Product.objects.filter(
            Q(name__icontains=name_condition)).filter(
                Q(item_number__icontains=item_number_condition))
        #icontains是大小写不敏感的,contains是大小写敏感的

        if 'page_size' in request.GET:
            page_size = request.GET['page_size']
        else:
            try:
                page_size = int(
                    System_Config.objects.get(
                        name='admin_product_list_page_size').val)
            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
        ctx['item_count'] = Product.objects.all().count()
        ctx['page_size'] = page_size
        ctx['query_item_number'] = item_number_condition
        ctx['query_name'] = name_condition
        return render(
            request,
            System_Config.get_template_name('admin') +
            '/product_list_content.html', ctx)
    else:
        raise Http404
Beispiel #12
0
def file_upload(request, item_type, item_id):
    ctx = {}
    ctx['system_para'] = System_Para.get_default_system_parameters()
    ctx['action_url'] = '/file-upload/' + item_type + '/' + item_id + "/"
    ctx['file_delete_url'] = '/file-delete/' + item_type
    ctx['host_item_id'] = item_id
    if request.method == 'GET':
        if item_type == 'product' or item_type == 'product_album':
            try:
                item = Product.objects.get(id=item_id)
                ctx['item'] = item
                try:
                    ctx['image_list'] = Product_Images.objects.filter(
                        product=item).order_by('create_time').reverse()
                    if item_type == 'product_album':
                        ctx['image_list'] = Album.objects.filter(
                            item_type=item_type,
                            item_id=item.id).order_by('create_time').reverse()
                except:
                    ctx['image_list'] = []
            except:
                raise Http404
        elif item_type == 'article':
            raise Http404
        else:
            raise Http404
        return render(request,
                      System_Config.get_template_name() + '/file_upload.html',
                      ctx)
    else:
        if item_type == 'product' or item_type == 'product_album':
            try:
                item = Product.objects.get(id=item_id)
            except:
                raise Http404
            filenames = handle_uploaded_file(request.FILES['upload'],
                                             item_type, item_id)
            #加入到对象的图片列表中去
            if item_type == 'product':
                pi = Product_Images.objects.create(
                    image=filenames['image_url'],
                    thumb=filenames['thumb_url'],
                    product=item)
            else:
                ai = Album.objects.create(image=filenames['image_url'],
                                          thumb=filenames['thumb_url'],
                                          item_type=item_type,
                                          item_id=item.id)
        elif item_type == 'article':
            try:
                item = Article.objects.get(id=item_id)
            except:
                raise Http404
            filenames = handle_uploaded_file(request.FILES['upload'],
                                             item_type, item_id)
            ai = Album.objects.create(image=filenames['image_url'],
                                      thumb=filenames['thumb_url'],
                                      item_type=item_type,
                                      item_id=item.id)
        else:
            raise Http404
        #判断是否是从CKEDITER传上来的
        if 'CKEditorFuncNum' in request.GET:
            logger.debug('请求来自CKEDITER.')
            script = '<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction("' + request.GET[
                'CKEditorFuncNum'] + '","' + filenames[
                    'image_url'] + '");</script>'
            logger.debug('返回的script: %s' % [script])
            return HttpResponse(script, content_type='text/html;charset=UTF-8')
        return redirect('/file-upload/' + item_type + '/' + item_id + "/")
Beispiel #13
0
def file_upload(request,item_type,item_id):
	ctx = {}
	ctx['system_para'] = System_Para.get_default_system_parameters()
	ctx['action_url'] = '/admin/file-upload/' + item_type + '/' + item_id + "/"
	ctx['file_delete_url'] = '/file-delete/' + item_type
	ctx['host_item_id'] = item_id
	if request.method == 'GET':
		if item_type == 'product' or item_type == 'product_album':
			try:
				item = Product.objects.get(id=item_id)
				ctx['item'] = item
				try:
					ctx['image_list'] = Product_Images.objects.filter(product=item).order_by('create_time').reverse()
					if item_type == 'product_album':
						ctx['image_list'] = Album.objects.filter(item_type=item_type,item_id=item.id).order_by('create_time').reverse()
				except:
					ctx['image_list'] = []
			except:
				raise Http404
		elif item_type == 'article':
			try:
				item = Article.objects.get(id=item_id)
				ctx['item'] = item
				try:
					ctx['image_list'] = Album.objects.filter(item_type=item_type,item_id=item.id).order_by('create_time').reverse()
				except:
					ctx['image_list'] = []
			except:
				raise Http404
		else:
			raise Http404
		return render(request,'admin/file_upload.html',ctx)
	else:
		
		manual_name = request.POST.get('manual_name','noname')	
		same_name_handle = request.POST.get('same_name_handle','reject')
	
		if item_type == 'product' or item_type == 'product_album':
			try:
				item = Product.objects.get(id=item_id)
			except:
				raise Http404
			

			logger.debug("filename_type:%s" % request.POST['filename_type'])
			filenames = handle_uploaded_file(request.FILES['upload'],item_type,item_id,request.POST['filename_type'],manual_name,same_name_handle)
			if filenames['upload_result'] == False:
				return HttpResponse(filenames['upload_error_msg'])
				
			#加入到对象的图片列表中去
			sort = request.POST.get('sort','0')
			is_show = request.POST.get('is_show_in_product_detail',False)
			
			if item_type == 'product':
				pi = Product_Images.objects.create(image=filenames['image_url'],thumb=filenames['thumb_url'],product=item,sort=sort,is_show_in_product_detail=is_show)
			else:
				ai = Album.objects.create(image=filenames['image_url'],thumb=filenames['thumb_url'],item_type=item_type,item_id=item.id)
		elif item_type == 'article':
			try:
				item = Article.objects.get(id=item_id)
			except:
				raise Http404
			filenames = handle_uploaded_file(request.FILES['upload'],item_type,item_id,request.POST['filename_type'],manual_name,same_name_handle)
			if filenames['upload_result'] == False:
				return HttpResponse(filenames['upload_error_msg'])			
		
			logger.debug('Upload success!!!')
			ai = Album.objects.create(image=filenames['image_url'],thumb=filenames['thumb_url'],item_type=item_type,item_id=item.id)
			logger.debug('ai success!!!')
		else:
			raise Http404
		#判断是否是从CKEDITER传上来的
		if 'CKEditorFuncNum' in request.GET:
			logger.debug('请求来自CKEDITER.')
			script = '<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction("' + request.GET['CKEditorFuncNum'] + '","' + filenames['image_url'] + '");</script>';
			logger.debug('返回的script: %s' % [script])
			return HttpResponse(script,content_type='text/html;charset=UTF-8')
			
		return_url = '/admin/file-upload/' + item_type + '/' + item_id + "/"
		if 'return_url' in request.POST:
			return_url = request.POST.get('return_url')
		return redirect(return_url)
Beispiel #14
0
def article_basic_edit(request):
    ctx = {}
    ctx['system_para'] = System_Para.get_default_system_parameters()

    result = {}
    result['success'] = False
    result['message'] = ''
    result['data'] = {}

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

    if request.method == 'GET':
        id = request.GET.get('id', '')
        if id != '':
            try:
                article = Article.objects.get(id=id)
                ctx['article'] = article

                #图片处理URL
                ctx['action_url'] = '/admin/file-upload/article/%s/' % id
                logger.debug('action_url:%s' % ctx['action_url'])

                ctx['file_delete_url'] = '/file-delete/article'

                try:
                    ctx['image_list'] = Album.objects.filter(
                        item_type='article').filter(
                            item_id=id).order_by('create_time').reverse()
                    logger.debug("ctx['image_list']:%s" % ctx['image_list'])
                except Exception as err:
                    logger.error("Error:%s" % err)
                    ctx['image_list'] = []

            except Exception as err:
                logger.error(
                    'Can not find article which id is %s. The error message is %s'
                    % (id, err))
        return render(
            request,
            System_Config.get_template_name('admin') + '/article_detail.html',
            ctx)
    elif request.method == 'POST':
        try:
            article = Article.objects.get(id=request.POST['id'])
            form = article_basic_info_form(request.POST, instance=article)
        except:
            form = article_basic_info_form(request.POST)
            logger.info('New product to store.')

        if form.is_valid():
            article = form.save()
            result['success'] = True
            result['message'] = '文章保存成功'
            data = {}
            data['article_id'] = article.id
            result['data'] = data
        else:
            result['success'] = False
            result['message'] = '文章保存失败'
            result['data'] = {}
        return JsonResponse(result)
    else:
        raise Http404
Beispiel #15
0
def product_basic_edit(request):
    ctx = {}
    ctx['system_para'] = System_Para.get_default_system_parameters()

    result = {}
    result['success'] = False
    result['message'] = ''
    result['data'] = {}

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

    #加载分类树信息
    from shopcart.category import get_all_top_categorys
    top_cat_list = get_all_top_categorys()
    ctx['top_cat_list'] = top_cat_list

    #加载属性组
    from shopcart.models import Attribute_Group
    attribute_group_list = Attribute_Group.objects.all()
    ctx['attribute_group_list'] = attribute_group_list

    if request.method == 'GET':
        id = request.GET.get('id', '')
        if id != '':
            try:
                product = Product.objects.get(id=id)
                ctx['product'] = product

                pcl = []
                for cat in product.categorys.all():
                    pcl.append(cat.id)

                ctx['product_category_id_list'] = pcl

                if product.attributes.all():
                    ctx['attribute_group_belong'] = product.attributes.all(
                    )[0].get_attribute_groups()

                #图片处理URL
                ctx['action_url'] = '/admin/file-upload/product/%s/' % id
                logger.debug('action_url:%s' % ctx['action_url'])

                ctx['file_delete_url'] = '/file-delete/product'

                try:
                    ctx['image_list'] = Product_Images.objects.filter(
                        product=product).order_by('create_time').reverse()
                    logger.debug("ctx['image_list']:%s" % ctx['image_list'])
                except Exception as err:
                    logger.error("Error:%s" % err)
                    ctx['image_list'] = []

            except Exception as err:
                logger.error(
                    'Can not find product which id is %s. The error message is %s'
                    % (id, err))
        return render(
            request,
            System_Config.get_template_name('admin') + '/product_detail.html',
            ctx)
    elif request.method == 'POST':
        try:
            product = Product.objects.get(id=request.POST['id'])
            form = product_basic_info_form(request.POST, instance=product)
        except:
            form = product_basic_info_form(request.POST)
            logger.info('New product to store.')

        if form.is_valid():
            product = form.save()
            result['success'] = True
            result['message'] = '商品保存成功'
            data = {}
            data['product_id'] = product.id
            result['data'] = data
            #return redirect('/admin/product-edit/?id=%s' % product.id)
        else:
            #return HttpResponse('商品保存失败,请重试。')
            result['success'] = False
            result['message'] = '商品保存失败'
            result['data'] = {}
        return JsonResponse(result)
    else:
        raise Http404