def post(self, request): receiver = request.POST.get('username') address = request.POST.get('address') postcode = request.POST.get('postcode') mobile = request.POST.get('mobile') if not all([receiver, address, postcode, mobile]): return render(request, 'address.html', {'errmsg': 'caoyaolu请输入地址信息'}) addr = Address() addr.receiver = receiver addr.address = address addr.tel_phone = mobile addr.zip_code = postcode addr.user = request.user exist_addr = Address.objects.GetDefaultAddress(user=request.user) default_addr = addr if not exist_addr: addr.is_default = True else: default_addr = exist_addr addr.save() address_list = Address.objects.GetAddressList(request.user) return render( request, 'address.html', { 'errmsg': 'caoyaolu请输入地址信息', 'address': default_addr, 'page': 'address', 'address_list': address_list })
def post(self, request): user = request.user name = request.POST.get("name", "") tel = request.POST.get("tel", "") addr = request.POST.get("addr", "") postal = request.POST.get("postal", "") address = Address(user=user, name=name, tel=tel, addr=addr, postal=postal) address.save() return HttpResponse(status=200)
def post(self, request): # print('测试222') recipient = request.POST.get('recipient') cell_phone = request.POST.get('cell_phone') province = Citys.objects.get(id=request.POST.get('province')) city = Citys.objects.get(id=request.POST.get('city')) country = Citys.objects.get(id=request.POST.get('country')) street = Citys.objects.get(id=request.POST.get('street')) detail_address = request.POST.get('detail_address') address = Address(user=request.user, consignee=recipient, phone=cell_phone, province=province, city=city, country=country, street=street, detail_address=detail_address) address.save() return redirect(reverse('bookapp:member_address'))
def create(self, validated_data): username = validated_data.get("username", None) email = validated_data.get("email", None) password = validated_data.get("password", None) first_name = validated_data.get('first_name', None) last_name = validated_data.get('last_name', None) user_object = User(username=username, email=email, first_name=first_name, last_name=last_name) user_object.set_password(password) user_object.save() profile_object = Profile(user_id=user_object.id, ) address_object = Address(user_id=user_object.id) profile_object.save() address_object.save() return user_object
def profile(request): findprofile = Profile.objects.filter(user_id=request.user.id).first() if findprofile == None: print("No profile found, making one..") tempprofile = Profile() tempprofile.user = request.user tempprofile.save() findpicture = UserImage.objects.filter(user_id=request.user.id).first() if findpicture == None: findpicture = UserImage() findpicture.user = request.user findpicture.save() if request.user.is_staff: return redirect('/user/admin-option') postform = User.objects.filter(id=request.user.id).first() address = Address.objects.filter(user_id=request.user.id).first() if address == None: address = Address() address.user = request.user address.address = None address.zip_code = None address.city = None address.country = None if request.method == 'POST': personalform = PersonalInfo(instance=postform, data=request.POST) if personalform.is_valid(): postform.save() addressform = AddressInfo(instance=address, data=request.POST) if addressform.is_valid(): address.save() messages.success(request, 'Nýjar upplýsingar vistaðar') else: messages.error( request, 'Ekki gékk að vista heimilisfangs upplýsingar, vinsamlegast reyndu aftur.' ) return redirect('/user/profile') messages.error( request, 'Ekki gékk að vista upplýsingar, vinsamlegast reyndu aftur.') return render( request, 'user/profile.html', { 'form': PersonalInfo(instance=postform), 'address': AddressInfo(instance=address) })
def address(request): if request.method == "GET": return render(request, 'store/address.html', {}) else: # 收货人 recr_name = request.POST["recr_name"] # 收货人电话 recr_tel = request.POST["recr_tel"] # 收货人所在省份 province = request.POST["province"] # 收货人所在城市 city = request.POST["city"] # 收货人所在县区 area = request.POST["area"] # 收货人详细地址 street = request.POST["street"] # 邮政编码 postal = request.POST["postal"] # 地址标签 add_label = request.POST["add_label"] try: # 默认地址 is_default = request.POST["is_default"] addresses = Address.objects.filter(user=request.user) for address in addresses: address.is_default = False address.save() address = Address(recr_name=recr_name, recr_tel=recr_tel, province=province, city=city, area=area, street=street, postal=postal, add_label=add_label, user=request.user, is_default=True) address.save() except: address = Address(recr_name=recr_name, recr_tel=recr_tel, province=province, city=city, area=area, street=street, postal=postal, add_label=add_label, user=request.user) address.save() return redirect(reverse("store:confirm"))
def indetlogin(request): address_name = request.POST.get('name') print(address_name) addr = request.POST.get('addr') code = request.POST.get('code') phone_name = request.POST.get('phone') cart = request.session.get("cart") c = Address(consignee=address_name, detailaddress=addr, postalcode=code, telephone=phone_name) c.save() print(1111111) # for i in cart.cartlen: # oic =Orderitem.objects.filter(orderid=1)[0] # orderid =oic.orderid # oi =Orderitem(productname=i.book.name,price=i.total_price,orderid=orderid) # oi.save() # l ='1234567890' # ord_num=''.join(random.sample(1,9)) # order =Orders(ordernumber=ord_num,expenditure=cart.total_price) # order.save() # order_id =order.id # request.session['order_id']=order_id return redirect('car:indentok')
def create_user(request): """Creates an new user for the website""" if request.method == 'POST': form = userCreateForm(data=request.POST) # Creates the form if form.is_valid(): user = form.save(commit=False) # Creates the user user.password = make_password(form.cleaned_data['password']) user.save() user.address = Address() # Creates an address instance for user # Saves all product images if user decides to add more than one return redirect('backend_users') else: form = userCreateForm() return render(request, 'backend/backend_create_user.html', {'form': form})
def post(self, request): self.request = request data = self.request.POST user_id = self.request.session.get('user_id', '') if not user_id: return HttpResponseRedirect("/user/login?next=/user/user_site") address_id = data.get("address_id") username = data.get('username') address = data.get('address') userphone = data.get('userphone') if address_id: Address.objects.filter(user_id=user_id, id=address_id).update(username=username, address=address, userphone=userphone) else: a = Address() a.username = username a.address = address a.userphone = userphone a.user_id = user_id a.save() return HttpResponseRedirect('/user/user_site')
def post(self, request): try: user_id = request.user.id data = json.loads(request.body) if data['is_default']: Address.objects.filter(user_id=user_id).update(is_default=0) Address( name = data['name'], phone_number = data['phone_number'], user_id = user_id, address = data['address'], detailed_address = data['detailed_address'], zip_code = data['zip_code'], is_default = data['is_default'] ).save() return JsonResponse({"message": "ADDRESS_CREATED"}, status=200) except KeyError: return JsonResponse({"message": "KEY_ERROR"}, status=400) except ValueError: return JsonResponse({"message": "VALUE_ERROR"}, status=400)
def address_add(request): """ 增加收货地址 :param request: :return: """ if request.method == 'GET': return render(request, 'usermess/address_add.html', {}) elif request.method == 'POST': recv = request.POST['recv'] phone = request.POST['phone'] province = request.POST['province'] city = request.POST['city'] country = request.POST['country'] intro = request.POST['intro'] try: set_default = request.POST['set_default'] address_list = Address.objects.filter(user=request.user) for addr in address_list: addr.isdefault = False addr.save() address = Address(rece=recv, iphone=phone, province=province, city=city, country=country, detailaddress=intro, isdefault=True, user=request.user) except: address = Address(rece=recv, iphone=phone, province=province, city=city, country=country, isdefault=False, detailaddress=intro, user=request.user) address.save() return redirect(reverse('user:address_list'))
def post(self, req): try: id = int(req.POST['id']) phone = req.POST['number'] city = req.POST['city'] country = req.POST['country'] code = req.POST['postCode'] address = req.POST['address'] if phone == '' or city == '' or country == '' or code == '' or address == '': messages.add_message(req, messages.WARNING, 'ورودی اشتباه') return JsonResponse({'redirect': '/UserPanel/Address/'}) if checkLang([city, country, address]) == False: messages.add_message(req, messages.WARNING, 'ادرس و شهر و استان را فارسی وارد کنید') return JsonResponse({'redirect': '/UserPanel/Address/'}) if checkNumbersValue(phone, 11) == False or checkNumber(phone) == False: messages.add_message(req, messages.WARNING, 'شماره تلفن فقط اعداد و 11 رقم باشد') return JsonResponse({'redirect': '/UserPanel/Address/'}) if checkNumbersValue(code, 10) == False or checkNumber(code) == False: messages.add_message(req, messages.WARNING, 'کد پستی فقط اعداد و 11 رقم باشد') return JsonResponse({'redirect': '/UserPanel/Address/'}) if id == -1: ADDR = Address( telephone=phone, city=city, country=country, postCode=code, address=address, userProfile=UserProfile.objects.getUserByUsername( req.user.username)) ADDR.save() return JsonResponse({'stat': 'success'}) else: ADDR = Address.objects.get(id=id) ADDR.telephone = phone ADDR.city = city ADDR.country = country ADDR.postCode = code ADDR.address = address ADDR.save() return JsonResponse({'stat': 'success'}) except Exception as Err: print(Err) messages.add_message(req, messages.WARNING, 'ورودی اشتباه') return JsonResponse({'redirect': '/UserPanel/Address/'})
def post(self, req): err = False user = UserProfile.objects.getUserByUsername(req.user.username) try: username = req.POST.get('username') if username == None: username = '' city = req.POST['city'] country = req.POST['country'] name = req.POST['name'] gender = int(req.POST['gender']) lastName = req.POST['lastName'] number = req.POST['number'] postCode = req.POST['postCode'] address = req.POST['address'] if checkLang([name, lastName, address]) == False: err = True self.context['messageType'] = 'alert-danger' messages.add_message(req, messages.ERROR, 'لضفا زبان فارسی وارد نمایید') if checkNumbersValue(postCode, 10) == False: self.context['messageType'] = 'alert-danger' err = True messages.add_message(req, messages.ERROR, 'کد پستی اشتباه ') if checkNumbersValue(number, 11) == False: self.context['messageType'] = 'alert-danger' err = True messages.add_message(req, messages.ERROR, 'شماره اشتباه اشتباه ') if gender != 1 and gender != 0: self.context['messageType'] = 'alert-danger' err = True messages.add_message(req, messages.ERROR, 'جنسیت اشتباه ') print(err) if err == False: user.name = name user.lastName = lastName user.telephone = number user.postCode = postCode user.address = address user.Gender = gender user.city = city user.country = country ADDR = Address.objects.filter( userProfile__id=req.user.userprofile.id) print(len(ADDR)) if len(ADDR) == 0: ADDR = Address( userProfile=UserProfile.objects.getUserByUsername( req.user.username), telephone=number, postCode=postCode, address=address, city=city, country=country) ADDR.save() else: ADDR[0].telephone = number ADDR[0].postCode = postCode ADDR[0].address = address ADDR[0].city = city ADDR[0].country = country ADDR[0].save() user.isFullUser = True user.save() self.context['name'] = name self.context['lastName'] = lastName self.context['telephone'] = number self.context['postCode'] = postCode self.context['address'] = address self.context['gender'] = gender self.context['city'] = city self.context['country'] = country self.context['messageType'] = 'alert-success' messages.add_message(req, messages.SUCCESS, 'اضلاعات ثبت شد') except Exception as err: messages.add_message(req, messages.ERROR, err) return render(req, 'userPanel/info.html', context=self.context)
def post(self, request): user = request.user if not user.is_authenticated: return JsonResponse({'res': 0, 'errmsg': '用户未登陆'}) addr_id = request.POST.get('addr_id') pay_style = request.POST.get('pay_style') sku_ids = request.POST.get('sku_ids') if not all([addr_id, pay_style, sku_ids]): return JsonResponse({'res': 1, 'errmsg': '数据不完整'}) if pay_style not in OrderInfo.PAY_METHODS.keys(): return JsonResponse({'res': 2, 'errmsg': '非法的支付方式'}) try: addr = Address.objects.get(id=addr_id) except Address.DoesNotExist(): return JsonResponse({'res': 3, 'errmsg': '地址非法'}) order_id = datetime.now().strftime('%Y%m%d%H%M%S') + str(user.id) transit_price = 12 total_count = 0 total_price = 0 save_id = transaction.savepoint() try: order = OrderInfo.objects.create(order_id=order_id, user=user, addr=addr, pay_method=pay_style, total_count=total_count, total_price=total_price, transit_price=transit_price) sku_ids = sku_ids.split(',') conn = get_redis_connection('default') cart_key = 'cart_%d' % user.id for sku_id in sku_ids: try: sku = GoodsSKU.objects.select_for_update().get(id=sku_id) except: return JsonResponse({'res': 4, 'errmsg': '商品不存在'}) count = conn.hget(cart_key, sku_id) if int(count) > sku.stock: return JsonResponse({'res': 6, 'errmsg': '库存不足'}) OrderGoods.objects.create(order=order, sku=sku, count=count, price=sku.price) sku.stock - +int(count) sku.sales += int(count) sku.save() amount = sku.price * int(count) total_count += int(count) total_price += amount order.total_count = total_count order.total_price = total_price order.save() except Exception as e: transaction.savepoint_rollback(save_id) transaction.savepoint_commit(save_id) conn.hdel(cart_key, *sku_ids) return JsonResponse({'res': 5, 'message': '创建成功'})