def product_update(request): id = request.POST['product_id'] dto_src = Product.objects.get(product_id=id) p_url = dto_src.picture_url if "file1" in request.FILES: file = request.FILES["file1"] p_url = file._name fp = open("%s%s" % (UPLOAD_DIR, p_url), 'wb') for chunk in file.chunks(): fp.write(chunk) fp.close() dto_new = Product(product_id=id, username=request.session["userid"], product_name=request.POST["product_name"], description=request.POST["description"], location=request.POST.get("location", "0"), locate=request.POST.get("locate", "0"), house=request.POST.get("house", "0"), room=request.POST.get("room", "0"), bed=request.POST.get("bed", "0"), bathroom=request.POST.get("bathroom", "0"), pet=request.POST.get("pet", "0"), language=request.POST.get("language", "0"), culture=request.POST.get("culture", "0"), family=request.POST.get("family", "2"), gas=request.POST.get("gas", "1"), picture_url=p_url) dto_new.save() return redirect("/product_list")
def post(self, category_id): err = ProductSchema().validate(request.json) if err: return err prod_data = request.get_json() prod_data["category"] = Category.objects.get(id=category_id) product = Product(**prod_data).save() product.reload() return ProductSchema().dump(product)
def handle(self, *args, **options): file_name = options['data'][0] with open(file_name, 'r') as json_data: for product in json.load(json_data): product_detail = Product( product_name=str(product['product_name']), product_price=str(product['product_price']), product_image_url=str(product['product_image_url']), product_stock=str(product['product_stock']), product_rating=str(product['product_rating']), product_url=str(product['product_url']), product_subtitle=str(product['product_subtitle'])) product_detail.save() self.stdout.write( self.style.SUCCESS('Successfully import data'))
def product_insert(request): #첨부파일이 있는 경우 if "file1" in request.FILES: file = request.FILES["file1"] file_name = file._name fp = open("%s%s" % (UPLOAD_DIR, file_name), "wb") for chunk in file.chunks(): fp.write(chunk) fp.close() else: file_name = "-" dto = Product( product_name=request.POST["product_name"], description=request.POST["description"], # price=request.POST["price"], username=request.POST["username"], locate=request.POST["locate"], location=request.POST["location"], picture_url=file_name, # priceTips=request.get("priceTips"), language=request.POST.get("language", "no"), culture=request.POST.get("culture", "no"), house=request.POST.get("house", "no"), room=request.POST.get("room", "no"), bed=request.POST.get("bed", "no"), bathroom=request.POST.get("bathroom", "no"), family=request.POST.get("family", "no"), pet=request.POST.get("pet", "no"), gas=request.POST.get("gas", "no"), 공용화장실=request.POST.get("공용화장실", "0"), 객실내화장실=request.POST.get("객실내화장실", "0"), 객실밖화장실=request.POST.get("객실밖화장실", "0"), 경기도고양시=request.POST.get("경기도고양시", "0"), 경기도광주시=request.POST.get("경기도광주시", "0"), 경기도김포시=request.POST.get("경기도김포시", "0"), 경기도부천시=request.POST.get("경기도부천시", "0"), 경기도성남시=request.POST.get("경기도성남시", "0"), 경기도수원시=request.POST.get("경기도수원시", "0"), 경기도안양시=request.POST.get("경기도안양시", "0"), 경기도양평군=request.POST.get("경기도양평군", "0"), 경기도오산시=request.POST.get("경기도오산시", "0"), 경기도용인시=request.POST.get("경기도용인시", "0"), 경기도이천시=request.POST.get("경기도이천시", "0"), 경기도파주시=request.POST.get("경기도파주시", "0"), 서울특별시강남구=request.POST.get("서울특별시강남구", "0"), 서울특별시강동구=request.POST.get("서울특별시강동구", "0"), 서울특별시강북구=request.POST.get("서울특별시강북구", "0"), 서울특별시강서구=request.POST.get("서울특별시강서구", "0"), 서울특별시구로구=request.POST.get("서울특별시구로구", "0"), 서울특별시도봉구=request.POST.get("서울특별시도봉구", "0"), 서울특별시동대문구=request.POST.get("서울특별시동대문구", "0"), 서울특별시동작구=request.POST.get("서울특별시동작구", "0"), 서울특별시마포구=request.POST.get("서울특별시마포구", "0"), 서울특별시서대문구=request.POST.get("서울특별시서대문구", "0"), 서울특별시서초구=request.POST.get("서울특별시서초구", "0"), 서울특별시성북구=request.POST.get("서울특별시성북구", "0"), 서울특별시송파구=request.POST.get("서울특별시송파구", "0"), 서울특별시양천구=request.POST.get("서울특별시양천구", "0"), 서울특별시영등포구=request.POST.get("서울특별시영등포구", "0"), 서울특별시용산구=request.POST.get("서울특별시용산구", "0"), 서울특별시종로구=request.POST.get("서울특별시종로구", "0"), 서울특별시중구=request.POST.get("서울특별시중구", "0"), internet=request.POST.get("internet", "0"), TV=request.POST.get("TV", "0"), laundry=request.POST.get("laundry", "0"), Air_Conditioning=request.POST.get("Air_Conditioning", "0"), Fridge=request.POST.get("Fridge", "0"), Hair_dryer=request.POST.get("Hair_dryer", "0"), kitchen_available=request.POST.get("kitchen_available", "0"), Health_club=request.POST.get("Health_club", "0"), Parking=request.POST.get("Parking", "0"), Garden=request.POST.get("Garden", "0"), Desk_and_Lamp=request.POST.get("Desk_and_Lamp", "0"), smoking_possible=request.POST.get("smoking_possible", "0"), single_room=request.POST.get("single_room", "0"), double_room=request.POST.get("double_room", "0"), triple_room=request.POST.get("triple_room", "0"), quadruple_room=request.POST.get("quadruple_room", "0"), dorm=request.POST.get("dorm", "0"), #hetero minday=request.POST.get("minday", "0"), maxday=request.POST.get("maxday", "0"), welcome_irrelevant=request.POST.get("welcome_irrelevant", "0"), welcome_males=request.POST.get("welcome_iwelcome_malesrrelevant", "0"), welcome_females=request.POST.get("welcome_females", "0"), welcome_couples=request.POST.get("welcome_couples", "0"), welcome_families=request.POST.get("welcome_families", "0"), welcome_students=request.POST.get("welcome_students", "0"), Computer=request.POST.get("Computer", "0"), Smoke_alarm=request.POST.get("Smoke_alarm", "0"), Dresser_Drawers=request.POST.get("Dresser_Drawers", "0"), Closet_Wardrobe=request.POST.get("Closet_Wardrobe", "0"), Wheelchair_Accessible=request.POST.get("Wheelchair_Accessible", "0"), Barbecue=request.POST.get("Barbecue", "0"), Bikes_for_use=request.POST.get("Bikes_for_use", "0"), Patio=request.POST.get("Patio", "0"), Gym_at_home=request.POST.get("Gym_at_home", "0"), Bedside_Locker_Nightstand=request.POST.get("Bedside_Locker_Nightstand", "0"), Radio=request.POST.get("Radio", "0"), telephone=request.POST.get("telephone", "0"), Carpet_Moquette=request.POST.get("Carpet_Moquette", "0"), fax=request.POST.get("fax", "0"), Mirror=request.POST.get("Mirror", "0"), Shopping_Centre=request.POST.get("Shopping_Centre", "0"), Amusement_Park=request.POST.get("Amusement_Park", "0"), Swimming_Pool=request.POST.get("Swimming_Pool", "0"), Hospital=request.POST.get("Hospital", "0"), Tennis=request.POST.get("Tennis", "0"), Park=request.POST.get("Park", "0"), Gym=request.POST.get("Gym", "0"), Golf=request.POST.get("Golf", "0"), Swimming=request.POST.get("Swimming", "0"), Cinema=request.POST.get("Cinema", "0"), Library=request.POST.get("Library", "0"), Museum=request.POST.get("Museum", "0"), Restaurant=request.POST.get("Restaurant", "0"), Bowling=request.POST.get("Bowling", "0"), Airport=request.POST.get("Airport", "0"), Beach=request.POST.get("Beach", "0"), Fishing=request.POST.get("Fishing", "0"), Sports_arena=request.POST.get("Sports_arena", "0"), subway_station=request.POST.get("subway_station", "0"), vegetarian=request.POST.get("vegetarian", "0"), 경상도=request.POST.get("경상도", "0"), 대구광역시=request.POST.get("대구광역시", "0"), 부산광역시=request.POST.get("부산광역시", "0"), 인천광역시=request.POST.get("인천광역시", "0"), 제주도=request.POST.get("제주도", "0"), 충청북도=request.POST.get("충청북도", "0"), 울산광역시=request.POST.get("울산광역시", "0"), within_a_hour=request.POST.get("within_a_hour", "0"), within_two_hours=request.POST.get("within_two_hours", "0"), 몇_시간_이내=request.POST.get("몇_시간_이내", "0"), 하루_이내=request.POST.get("하루_이내", "0"), 며칠_이내=request.POST.get("며칠_이내", "0"), 강아지=request.POST.get("강아지", "0"), 고양이=request.POST.get("고양이", "0"), 어류=request.POST.get("어류", "0"), 토끼=request.POST.get("토끼", "0"), 햄스터=request.POST.get("햄스터", "0"), 강원도강릉시=request.POST.get("강원도강릉시", "0"), 경기도양주시=request.POST.get("경기도양주시", "0"), 경기도의왕시=request.POST.get("경기도의왕시", "0"), 경상남도창원시=request.POST.get("경상남도창원시", "0"), 경상북도경산시=request.POST.get("경상북도경산시", "0"), 대구광역시동구=request.POST.get("대구광역시동구", "0"), 대구광역시북구=request.POST.get("대구광역시북구", "0"), 부산광역시부산진구=request.POST.get("부산광역시부산진구", "0"), 부산광역시사하구=request.POST.get("부산광역시사하구", "0"), 부산광역시해운대구=request.POST.get("부산광역시해운대구", "0"), 서울특별시노원구=request.POST.get("서울특별시노원구", "0"), 서울특별시중랑구=request.POST.get("서울특별시중랑구", "0"), 울산광역시남구=request.POST.get("울산광역시남구", "0"), 울산광역시중구=request.POST.get("울산광역시중구", "0"), 인천관역시인천=request.POST.get("인천관역시인천", "0"), 인천광역시계양구=request.POST.get("인천광역시계양구", "0"), 인천광역시남동구=request.POST.get("인천광역시남동구", "0"), 인천광역시부평구=request.POST.get("인천광역시부평구", "0"), 인천광역시서구=request.POST.get("인천광역시서구", "0"), 인천광역시연수구=request.POST.get("인천광역시연수구", "0"), 인천광역시중구=request.POST.get("인천광역시중구", "0"), 제주도서귀포시=request.POST.get("제주도서귀포시", "0"), 제주도제주시=request.POST.get("제주도제주시", "0"), 충청북도단양군=request.POST.get("충청북도단양군", "0") # welcome_irrelevant=request.POST.get("welcome_irrelevant", "0"), # welcome_males=request.POST.get("welcome_males", "0"), # welcome_couples=request.POST.get("welcome_couples","0"), # welcome_families=request.POST.get("welcome_families", "0"), # internet=request.POST.get("internet", "0"), # kitchen_available=request.POST.get("kitchen_available", "0"), # Parking=request.POST.get("Parking", "0"), # Air_Conditioning=request.POST.get("Air_Conditioning", "0"), # Computer=request.POST.get("Computer", "0"), # Smoke_alarm=request.POST.get("Smoke_alarm", "0"), # Desk_and_Lamp=request.POST.get("Desk_and_Lamp", "0"), # Dresser_Drawers=request.POST.get("Dresser_Drawers", "0"), # Closet_Wardrobe=request.POST.get("Closet_Wardrobe", "0"), # Hair_dryer=request.POST.get("Hair_dryer", "0"), # Garden=request.POST.get("Garden", "0"), # Wheelchair_Accessible=request.POST.get("Wheelchair_Accessible", "0"), # Barbecue=request.POST.get("Barbecue", "0"), # Bikes_for_use=request.POST.get("Bikes_for_use", "0"), # Gym_at_home=request.POST.get("Gym_at_home", "0"), # Bedside_Locker_Nightstand=request.POST.get("Bedside_Locker_Nightstand", "0"), ) dto.save() return redirect("/product_list")
def delete(self): product = Product.objects(id=request.get_json()["id"]) product.delete() return ProductSchema().dump(product)
def put(self): product = Product.get_product(request.get_json()["id"]) product.update(**request.get_json()) product.reload() return ProductSchema().dump(product)
def add_stuff(request): c1 = Coupon(name="50% off") c1.save() c2 = Coupon(name="buy 1 get 1 free") c2.save() c3 = Coupon(name="1 dollar off") c3.save() c4 = Coupon(name="2 dollars off") c4.save() Product( title='Slingshot', description='To keep your frienemies away when you need to.', picture='slingshot.jpg', rating=4, price=14.99, ).save() p = Product( title='Beanie Baby', description='A timeless toy for all ages and genders', picture='beanie.jpg', rating=5, price=24.49, ) p.save() p.coupons.add(c2) p.save() Product( title='White T-shirt', description='Your typical white tee - very comfortable!', picture='tshirt.jpg', rating=3, price=3.99, ).save() p = Product( title='Red Solo Cup', description= 'Better than the ones you’ll find at your typical frat party! (100)', picture='cup.jpg', rating=4, price=7.99, ) p.save() p.coupons.add(c4) p.save() p = Product( title='Portable Apparatus for Sitting', description='Patent protected', picture='chair.jpg', rating=1, price=12.69, ) p.save() p.coupons.add(c1) p.save() Product( title='Cannon', description='More effective than a slingshot', picture='cannon.jpg', rating=5, price=299.99, ).save() p = Product( title='Haribo Sugarless Gummy Bears', description='5 pounds of diarrhea!', picture='haribo.jpg', rating=5, price=12.99, ) p.save() p.coupons.add(c2) p.save() product_list = Product.objects.all() for p in product_list: p.available_coupons = p.coupons.all() if p.available_coupons: p.price = p.available_coupons[0].calculate_price(p.price) p.save() return HttpResponse("done.")