def create(request): if request.method=='POST': name = request.REQUEST.get('name','') price = float(request.REQUEST.get('price',1)) price_type = float(request.REQUEST.get('price_type',1)) order_time = request.REQUEST.get('order_time',datetime.datetime.now().strftime('%Y-%m-%d')) trip_start_time = request.REQUEST.get('trip_start_time',datetime.datetime.now().strftime('%Y-%m-%d')) trip_end_time = request.REQUEST.get('trip_end_time',datetime.datetime.now().strftime('%Y-%m-%d')) key_desc = request.REQUEST.get('key_desc','') start_city = request.REQUEST.get('start_city','') end_city = request.REQUEST.get('end_city','') pics = request.REQUEST.get('pics','') trips = request.REQUEST.get('trips',json.dumps([])) product = Products() product.name = name product.price = price product.price_type = price_type product.total_price = price*price_type product.order_time = datetime.datetime.strptime(order_time,'%Y-%m-%d') product.trip_start_time = datetime.datetime.strptime(trip_start_time,'%Y-%m-%d') product.trip_end_time = datetime.datetime.strptime(trip_end_time,'%Y-%m-%d') product.key_desc = key_desc product.start_city = start_city product.end_city = end_city product.pics = pics product.trips = trips product.date_count = len(json.loads(trips)) product.user = request.user try: product.save() return HttpResponseRedirect('/ink/product/index') except: return {} return {}
def setUp(self): user = User() user.is_superuser = 1 user.username = '******' user.set_password('password2') user.email = '*****@*****.**' user.first_name = 'aa' user.is_active = 1 user.save() self.user = user c = Client() self.c = c self.c.login( username='******', password='******') product = Products() product.name = '123123' product.price = 123 product.price_type = 1 product.total_price = 1*2 product.order_time = datetime.datetime.strptime('2014-03-20','%Y-%m-%d') product.trip_start_time = datetime.datetime.strptime('2014-06-20','%Y-%m-%d') product.trip_end_time = datetime.datetime.strptime('2014-09-09','%Y-%m-%d') product.key_desc = '123' product.start_city = '123' product.end_city = '123' product.pics = '' product.trips = '' product.date_count = 4 product.user = self.user product.save() self.product = product
def rend_data(request): product = Products() product.name = u'海南七日游' product.price = 1 product.price_type = 1 product.total_price = 1 product.order_time = datetime.datetime.strptime('2014-03-31','%Y-%m-%d') product.trip_start_time = datetime.datetime.strptime('2014-06-15','%Y-%m-%d') product.trip_end_time = datetime.datetime.strptime('2014-09-15','%Y-%m-%d') product.key_desc = u'海南七日游' product.start_city = u'北京' product.end_city = u'海南' product.pics = '' product.trips = '游艇' product.date_count = len(json.loads(json.dumps([{'name':u'第一天'},{'name':u'第二天'}]))) product.user = request.user try: product.save() return HttpResponseRedirect('/ink/product/index') except: return {} return {}