def sign_up(request): if request.method == "POST": form1 = MerchantSignUpForm(request.POST) form2 = MerchantForm(request.POST) if form1.is_valid() and form2.is_valid(): merchant = User.objects.create_user( username=form1.cleaned_data["username"], email=form1.cleaned_data["email"], first_name=form1.cleaned_data["first_name"], password=form1.cleaned_data["password1"], last_name=form1.cleaned_data["last_name"], ) merch = Merchant( user=merchant, company=form2.cleaned_data["company"], address1=form2.cleaned_data["address1"], address2=form2.cleaned_data["address2"], address3=form2.cleaned_data["address3"], phone_number=form2.cleaned_data["phone_number"], ) merch.save() groups = Group.objects.get(name="merchant") groups.user_set.add(merchant) return HttpResponse("/") else: error = "below fields are required" data = {"error": error} return HttpResponse(json.dumps(data), content_type="application/json") else: form1 = MerchantSignUpForm() form2 = MerchantForm() variables = RequestContext(request, {"form1": form1, "form2": form2}) return render_to_response("merchant/sign_up.html", variables)
def load_merchant(csv_file, sheet): book = xlrd.open_workbook(csv_file) # Open an .xls file sheet = book.sheet_by_index(sheet) # Get the first sheet for counter in range(11): # Loop for five times if counter: # grab the current row rows = sheet.row_values(counter) mercent = Merchant(merchant_id=rows[0], merchant_name=rows[1], merchant_address=rows[2]) mercent.save() return True
class LoadTestCase(TestCase): def setUp(self): self.path = os.path.join(os.getcwd(), 'assignment_table_load.xls') self.sheet = 2 self.mercent = Merchant(merchant_id='001',merchant_name="test merchant", merchant_address="address") self.mercent.save() self.test_item = Item(item_id="0001",merchant_id="0002",item_name="one Item", item_price=200,merchant_obj=self.mercent) self.test_item.save() self.new_item = Item(item_id="0002",merchant_id="0002",item_name="one Item new", item_price=200,merchant_obj=self.mercent) self.new_item.save() self.cart = Cart(customer="test Customer") self.cart.save() def test_data_found(self): """Data found according to search""" merchant = load_merchant(self.path, 3) item = load_item(self.path, 2) transaction = load_transaction(self.path, 0) sales = load_sales(self.path, 1) assert merchant assert item assert transaction assert sales def test_cart_create(self): row1 = Rows(sn=1,item=self.test_item,quantity=2.5, unit='piece', cart = self.cart) row2 = Rows(sn=2,item=self.test_item,quantity=3.5, unit='piece', cart = self.cart) row3 = Rows(sn=3,item=self.test_item,quantity=42.5, unit='piece', cart = self.cart) row1.save() row2.save() row3.save() assert self.cart.rows.all() assert self.cart.status name = self.cart.item_update(1, self.test_item, self.new_item) assert name == self.new_item.item_name self.cart.cancel() assert not self.cart.status
def setUp(self): self.path = os.path.join(os.getcwd(), 'assignment_table_load.xls') self.sheet = 2 self.mercent = Merchant(merchant_id='001',merchant_name="test merchant", merchant_address="address") self.mercent.save() self.test_item = Item(item_id="0001",merchant_id="0002",item_name="one Item", item_price=200,merchant_obj=self.mercent) self.test_item.save() self.new_item = Item(item_id="0002",merchant_id="0002",item_name="one Item new", item_price=200,merchant_obj=self.mercent) self.new_item.save() self.cart = Cart(customer="test Customer") self.cart.save()
def setUpClass(cls): deal = set_advertiser_and_category() cls.deal = Deal(**deal) cls.deal.save() cls.user = User.objects.create_user('testuser1', '*****@*****.**', '12345') is_merchant = cls.user.profile.is_approved_merchant() if not is_merchant: cls.merchant = Merchant(advertiser_ptr=cls.deal.advertiser, userprofile=cls.user.profile, enabled=True, approved=True, intlnumber='123456789') cls.merchant.save() super(OrderModelTestCase, cls).setUpClass()
def setUpClass(cls): deal = set_advertiser_and_category() deal['title'] = 'Deal #3' # dictionary cls.deal = Deal(**deal) cls.deal.save() cls.user = User.objects.create_user('testuser3', '*****@*****.**', '123456') is_merchant = cls.user.profile.is_approved_merchant() if not is_merchant: cls.merchant = Merchant(advertiser_ptr=cls.deal.advertiser, userprofile=cls.user.profile, enabled=True, approved=True, intlnumber='123456789') cls.merchant.save() cls.selenium = webdriver.Chrome() cls.wait = ui.WebDriverWait(cls.selenium, 10) super(SalesHistoryAndTrendTestCase, cls).setUpClass()
def setUpClass(cls): Deal.objects.all().delete() User.objects.all().delete() deal = set_advertiser_and_category() # dictionary cls.deal = Deal(**deal) cls.deal.save() cls.user = User.objects.create_user('testuser1', '*****@*****.**', '12345') is_merchant = cls.user.profile.is_approved_merchant() if not is_merchant: cls.merchant = Merchant(advertiser_ptr=cls.deal.advertiser, userprofile=cls.user.profile, enabled=True, approved=True, intlnumber='123456789') cls.merchant.save() cls.client = Client() super(MerchantManageDealsTestCase, cls).setUpClass()
def createMerchant(request): if request.POST: # 获取参数 username = request.POST.get('username', None) merchantName = request.POST.get('merchantName', None) password = request.POST.get('password', None) password2 = request.POST.get('password2', None) phone = request.POST.get('phone', None) # 判断用户是否存在 user = User.objects.filter(username=username) if len(user) > 0: return render(request, 'createMerchant.html', {'error_msg': '用户名已经被使用'}) elif password != password2: return render(request, 'createMerchant.html', {'error_msg': '密码不一致'}) elif len(password) == 0: return render(request, 'createMerchant.html', {'error_msg': '密码不能为空'}) # 这是用户名可以使用的时候 # 向django_user数据表种添加数据 user = User.objects.create_user(username=username, password=password) # 向Merchant表中添加数据 merchant = Merchant() # 这是建立外键的一对一关系 merchant.user_id = user.id merchant.merchantName = merchantName # 这是为phone属性赋值 merchant.phone = phone merchant.save() return render(request, 'merchantLogin.html', {'msg': '创建成功,请登录'}) else: return render(request, 'createMerchant.html')
def post(self, request, **kwargs): name = request.POST.get('name') context = { 'profile': self.request.user.profile, 'countries': { 'choices': COUNTRY_CHOICES, 'default': 2 }, 'locations_kenya': { 'choices': KENYAN_LOCATIONS, 'default': 84 }, 'locations_nigeria': { 'choices': NIGERIAN_LOCATIONS, 'default': 25 }, 'breadcrumbs': [ { 'name': 'My Account', 'url': reverse('account') }, { 'name': 'Merchant', 'url': reverse('account_merchant') }, { 'name': 'Merchant Register', }, ] } try: advertiser = Advertiser.objects.get(name__exact=name) mssg = "Company Name Already taken/exists" messages.add_message(request, messages.ERROR, mssg) return TemplateResponse(request, self.template_name, context) except Advertiser.DoesNotExist: country = int(request.POST.get('user_country')) if country == 1: location = int(request.POST.get('nigeria_user_location')) elif country == 2: location = int(request.POST.get('kenya_user_location')) telephone = request.POST.get('telephone') intlnumber = request.POST.get('intlnumber') email = request.POST.get('email') address = request.POST.get('address') slug = slugify(name) userprofile = request.user.profile logo = request.FILES.get('logo') # pack merchant attributes in a dictionary merchant = dict(name=name, country=country, location=location, telephone=telephone, email=email, address=address, slug=slug, intlnumber=intlnumber, logo=logo, userprofile=userprofile) # remove logo if empty if not logo: del (merchant['logo']) merchant = Merchant(**merchant) merchant.save() # generate token and prepare message token = totp_token.now() msg = { 'reqtype': 'json', 'api_key': settings.NEXMO_USERNAME, 'api_secret': settings.NEXMO_PASSWORD, 'from': settings.NEXMO_FROM, 'to': intlnumber, 'text': str(token), } sms = NexmoMessage(msg) response = sms.send_request() if response: return redirect(reverse('account_merchant_verify')) else: mssg = ("Your merchant account has been created. " "However, we could not send the OTP to your phone. " "Please click the Resend OTP button to try again!") messages.add_message(request, messages.ERROR, mssg) return redirect(reverse('account_merchant_verify'))
def register(request): if request.method == "GET": data = {'title': '商家注册'} return render(request, 'merchant/register.html', context=data) elif request.method == "POST": merchantName = request.POST.get('merchantName') phone = request.POST.get('phone') email = request.POST.get('email') password = request.POST.get('password') idCard = request.POST.get('idCard') idCard_front = request.FILES.get('idCard_front') idCard_back = request.FILES.get('idCard_back') icon = request.FILES.get('icon') password = make_password(password) merchant = Merchant() merchant.m_merchantName = merchantName merchant.m_phone = phone merchant.m_email = email merchant.m_password = password merchant.m_idCard = idCard merchant.m_idCard_front = idCard_front merchant.m_idCard_back = idCard_back merchant.m_icon = icon merchant.save() return render(request, 'merchant/login.html')