Beispiel #1
0
def add_goods():
    goods_info = ctx.request.input(goods_name='',
                                   description='',
                                   tags='',
                                   goods_price='')
    goods_name = goods_info.goods_name.strip()
    goods_description = goods_info.description.strip()
    goods_ori_img = ctx.request.get('goods_img')
    img_filename = goods_img.Filename
    img_type = img_filename.spilt('.')[-1]
    #generate a unique fileid for the img file of this goods
    img_filename = random_id() + img_type if img_type else random_id() + '.jpg'
    fout = open(ctx.root_path + '/static/img/' + img_filename, 'w')
    fout.write(goods_ori_img.file.read())
    fout.close()
    goods_owner_acct = user.account
    goods_id = random_id()
    #insert the goods into
    goods = Goods(goods_id=goods_id,owner_account=goods_owner_acct,goods_name=goods_name,\
        img_filename=img_filename,description=goods_description,goods_price=goods_price,status=3)
    goods.insert()

    #build the relation between goods and tags
    goods_tags_list = goods_info.tags.strip().split(' ')
    for tag in goods_tags_list:
        goodstag = Goodstag(goods_id=goods_id, tag_name=tag, status=0)
        goodstag.insert()

        goods_added = Goods.find_first('where goods_id=?', goods_id)
    # goods_added.update(status=3) #need to add a new db_interface
    goods_added.status = 3
    goods_added.update()
    return redirect('/')  #need to modified
Beispiel #2
0
def static_search_goods():
	user = ctx.request.user
	s_factor_name = ctx.request.get('s_factor_name')
	s_text_value = ctx.request.get('s_text_value')

	if s_factor_name == 'name':
		name = '%' + s_text_value + '%'
		goods = Goods.find_by('where goods_name like ? and status = 0 limit 6',name)
	elif s_factor_name == 'tag':
		#TODO: add join search mode
	else:
		price = float(s_text_value)
		goods = Goods.find_by('where goods_price < ? and status = 0 limit 6',price)

	return Jinja2Template('index.html',_user=user,_goods=goods,_s_factor_name_name=s_factor_name,_s_factor_name_value=s_text_value)
Beispiel #3
0
def show_item_details():
	#get the query_string
	qstr = ctx.request.query_string()
	#parse the query_string
	qstr_dict = parse_query(qstr)
	#get the goods_id
	goods_id = qstr_dict.goods_id.lower()
	item = Goods.find_first('where goods_id = ?',goods_id)
	if not item:
		raise per_redirect('/')#redirect to a page that

	buyer = None
	if item.buyer_account:
		buyer = User.find_first('where account = ?',item.buyer_account)
	item.img_filename = '/img/' + item.img_filename
	tags = Goodstag.find_by('where goods_id = ? and status = 0',goods_id)

	_user = ctx.request.user
	return Jinja2Template('item_detail.html',_user=user,_item=item, _buyer=buyer,_tags=tags)