当前位置: 首页>>代码示例>>Python>>正文


Python models.Account类代码示例

本文整理汇总了Python中accounts.models.Account的典型用法代码示例。如果您正苦于以下问题:Python Account类的具体用法?Python Account怎么用?Python Account使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Account类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hub_add_account

def hub_add_account(request, pk):
    if request.is_ajax():
        # POST method for creating a new object
        if request.method == 'POST':

            try:
                a_type = request.POST['account_type']
                b = request.POST['balance']
                curr = request.POST['currency']
                currency = Currency.objects.filter(name=curr)
                hub = get_object_or_404(Hubs, pk=pk)
                if a_type == 'b':
                    bank = request.POST['bank_name']
                    number = request.POST['number']
                    new_acc = Account(account_type=a_type, balance=b, currency=currency[0],
                                      bank_name=bank, number=number, owner=hub)
                else:
                    new_acc = Account(account_type=a_type, balance=b, currency=currency[0],
                                      owner=hub)

            except KeyError, e:
                print "Key Error account_new_get POST"
                print e
                return HttpResponseServerError(request)
            except Exception as e:
                print "Turbo Exception account_new_get GET"
                print e.args
                return HttpResponseServerError(request)

            new_acc.save()

            return JsonResponse({'code': '200',
                                 'msg': 'all cool',
                                 'pk': new_acc.pk},
                                )
开发者ID:this-is-mike,项目名称:gvi-accounts,代码行数:35,代码来源:views.py

示例2: test_ordinary_purchase

	def test_ordinary_purchase(self):
		"""Test basic purchases (ordinary price)

		"""
		account = Account(name="tset")
		account.deposit(500) # Depost issues the save routine
		operator = None

		m1 = Merchandise(name="m1", internal_price=3, ordinary_price=4)
		m1.save()
		m2 = Merchandise(name="m2", internal_price=2, ordinary_price=4)
		m2.save()

		merchandise_list = [m1, m1, m1, m2]

		# Test a basic purchase:
		total_price = sum(m.ordinary_price for m in merchandise_list)
		trans = buy_merchandise(account, merchandise_list, operator)
		account = Account.objects.get(id=account.id) # Force update
		self.failUnlessEqual(trans.amount, -total_price)
		self.failUnlessEqual(account.balance, 500 - total_price)

		# Test if the number of purchased items related to the transaction is
		# correct:
		pm_count = PurchasedItem.objects.filter(transaction=trans).count()
		item_count = len(merchandise_list)
		self.failUnlessEqual(pm_count, item_count)
开发者ID:smyrman,项目名称:kikrit,代码行数:27,代码来源:tests.py

示例3: reg_service

def reg_service(request):
    if request.method == 'GET':
        raise Http404('Wrong URL')

    try:
        name = request.POST['name']
        email = request.POST['email']
        password = request.POST['password']

        if not (re.match(r'^.{2,15}$', name) or
                re.match(r'^[a-zA-Z0-9.-_]{2,50}@[a-zA-Z0-9]{2,30}.[a-zA-Z0-9]{1,10}$', email) or
                re.match(r'^.{6,20}$', password)):
            return HttpResponse('false')

        try:
            # If email has been registered, return 'register'
            # Or continue
            if Account.objects.get(email=email):
                return HttpResponse('registered')
        except:
            pass

        salt = generate_salt()
        encrypted_password = encrypt_pwd(password, salt)
        user = Account(name=name, email=email, pwd=encrypted_password, salt=salt, last_ip=request.META['REMOTE_ADDR'])
        user.save()
        request.session['user_id'] = user.id
        return HttpResponse('true')
    except:
        return HttpResponse('false')
开发者ID:karlind,项目名称:ewu-v4,代码行数:30,代码来源:account_service.py

示例4: register

def register(request):
    if request.method == "POST":
        nextPage = request.POST.get("next", "/")
        form = RegisterForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except:
                print "Unable to save form..."
                return render_to_response("registration/registration.html", {'form': form, 'next': nextPage}, context_instance=RequestContext(request))
            user = authenticate(username=request.POST.get("username"), password=request.POST.get("password1"))
            login(request, user)
            account = Account()
            account.user = User.objects.get(pk=user.id)
            account.created_by = user
            account.save()
            return redirect(nextPage)
        else:
            print "errors in registration"
            print form.errors
    else:
        form = RegisterForm()
        nextPage = request.GET.get("next", "/")
    # return render_to_response("registration/login.html", {}, context_instance=RequestContext(request))
    return redirect("ig.api.connectInstagram")
开发者ID:JasonTsao,项目名称:Fashion,代码行数:25,代码来源:views.py

示例5: test_against_cascade_deletion_of_purchaseditem

	def test_against_cascade_deletion_of_purchaseditem(self):
		"""Test that purchased items are not removed when related merchandise
		is

		"""
		account = Account(name="tset")
		account.deposit(500) # Depost issues the save routine
		operator = None

		m1 = Merchandise(name="m1", internal_price=3, ordinary_price=4)
		m1.save()
		m2 = Merchandise(name="m2", internal_price=2, ordinary_price=4)
		m2.save()

		# Test a basic purchase:
		trans = buy_merchandise(account, [m1], operator)

		# Test that transactions are not deleted when related merchandise is,
		# and that backup information is stored to merchandise_tags and
		# merchandise_name:
		pm1_id = PurchasedItem.objects.get(transaction=trans).id
		merchandise_name = m1.name[:30]
		merchandise_tags = "|".join((unicode(t) for t in m1.tags.all()))[:30]
		m1.delete()
		pm1 = PurchasedItem.objects.get(id=pm1_id)
		self.failUnlessEqual(pm1.merchandise_name, merchandise_name)
		self.failUnlessEqual(pm1.merchandise_tags, merchandise_tags)
开发者ID:smyrman,项目名称:kikrit,代码行数:27,代码来源:tests.py

示例6: reg_service

def reg_service(request):
    if request.method == "GET":
        raise Http404("Wrong URL")

    try:
        name = request.POST["name"]
        email = request.POST["email"]
        password = request.POST["password"]

        if not (
            re.match(r"^.{2,15}$", name)
            or re.match(r"^[a-zA-Z0-9.-_]{2,50}@[a-zA-Z0-9]{2,30}.[a-zA-Z0-9]{1,10}$", email)
            or re.match(r"^.{6,20}$", password)
        ):
            return HttpResponse("false")

        try:
            # If email has been registered, return 'register'
            # Or continue
            if Account.objects.get(email=email):
                return HttpResponse("registered")
        except:
            pass

        salt = generate_salt()
        encrypted_password = encrypt_pwd(password, salt)
        user = Account(name=name, email=email, pwd=encrypted_password, salt=salt, last_ip=request.META["REMOTE_ADDR"])
        user.save()
        request.session["user_id"] = user.id
        return HttpResponse("true")
    except:
        return HttpResponse("false")
开发者ID:yangcheng470,项目名称:ewu-v4,代码行数:32,代码来源:account_service.py

示例7: setUp

 def setUp(self):
     self.client = Client()
     Account.register("bobthebuilder", "[email protected]", "password", "password")
     self.client.login(username="bobthebuilder", password="password")
     self.account_id = Account.objects.get(username="bobthebuilder").id
     self.file_dir = os.path.join(settings.MEDIA_ROOT, files.models.rel_local_file_dir(self.account_id))
     if not os.path.isdir(self.file_dir):
         os.makedirs(self.file_dir)
开发者ID:noriakioji,项目名称:QADDA,代码行数:8,代码来源:testLinearReg.py

示例8: setUp

    def setUp(self):
        PlotTest.files = []

        # used for tests that use fake requests
        self.client = Client()
        Account.register("brobot2", "[email protected]", "password", "password")
        self.account_id = Account.objects.get(username="brobot2").id
        self.client.login(username="brobot2", password="password")
开发者ID:noriakioji,项目名称:QADDA,代码行数:8,代码来源:testPlots.py

示例9: registerUser

def registerUser(request):
	rtn_dict = {'success': False, "msg": ""}

	login_failed = False

	if request.method == 'POST':
		try:
			new_user = User(username=request.POST.get("username"))
			new_user.is_active = True
			new_user.password = make_password(request.POST.get('password1'))
			new_user.email = request.POST.get('email')
			new_user.save()
			user = authenticate(username=request.POST.get("username"), password=request.POST.get("password1"))

			if user is None:
				login_failed = True
				status = 401

			else:
				auth_login(request, user)
				account = Account(user=user)
				account.email = user.email
				account.user_name = user.username
				account.save()

				rtn_dict['success'] = True
				rtn_dict['msg'] = 'Successfully registered new user'
				rtn_dict['user'] = new_user.id
				rtn_dict['account'] = account.id
				return HttpResponse(json.dumps(rtn_dict, cls=DjangoJSONEncoder), content_type="application/json", status=status)

			'''
			r = R.r
			#PUSH NOTIFICATIONS
			token = request.POST.get('device_token', None)
			if token is not None:
				try:
					# Strip out any special characters that may be in the token
					token = re.sub('<|>|\s', '', token)
					registerDevice(user, token)
					device_token_key = 'account.{0}.device_tokens.hash'.format(account.id)
					token_dict = {str(token): True}
					r.hmset(device_token_key, token_dict)
				except Exception as e:
					print 'Error allowing push notifications {0}'.format(e)
			
			user_key = 'account.{0}.hash'.format(account.id)
			r.hmset(user_key, model_to_dict(account))
			'''
		except Exception as e:
			print 'Error registering new user: {0}'.format(e)
			logger.info('Error registering new user: {0}'.format(e))
			rtn_dict['msg'] = 'Error registering new user: {0}'.format(e)

	else:
		rtn_dict['msg'] = 'Not POST'

	return HttpResponse(json.dumps(rtn_dict, cls=DjangoJSONEncoder), content_type="application/json")
开发者ID:JasonTsao,项目名称:MeepPythonServer,代码行数:58,代码来源:api.py

示例10: TestAnAccountWithFunds

class TestAnAccountWithFunds(TestCase):

    def setUp(self):
        self.account = Account()
        self.account.balance = D('100.00')

    def test_cannot_be_closed(self):
        with self.assertRaises(exceptions.AccountNotEmpty):
            self.account.close()
开发者ID:a-musing-moose,项目名称:django-oscar-accounts,代码行数:9,代码来源:model_tests.py

示例11: test_double_amount

 def test_double_amount(self):
     user = get_user_model().objects.create(
         username='test',
     )
     # Transaction.objects.create(account_from='test', account_to='test', user=user)
     acc = Account(name='qwe', user=user)
     acc.save()
     trans2 = Transaction(account_from=acc, account_to=acc, user=user)
     self.assertRaisesMessage(ValidationError, 'Accounts must differ', trans2.clean)
开发者ID:Tauders,项目名称:MoneyTalks,代码行数:9,代码来源:tests.py

示例12: test_get_samples

	def test_get_samples(self):
		acc = Account()
		acc.user = self.user
		fake_task_id = str(uuid4())
		run = ScanRun.objects.create_pending_scan_run(self.inert, fake_task_id)
		sample = acc.get_samples()
		# sample = [<FileSample: 4>]
		self.assertTrue(isinstance(sample[0], FileSample),
		                msg='Sample object is not instance of FileSample: {0}'.format(sample[0]))
开发者ID:MarlonNakouzi,项目名称:phagescan,代码行数:9,代码来源:tests.py

示例13: setUp

 def setUp(self):
     self.client = Client()
     Account.register(HistogramTest.username, "[email protected]", "password", "password")
     self.account_id = Account.objects.get(username="foo").id
     self.client.login(username="foo", password="password")
     self.title = 'HISTOGRAM TEST TITLE'
     self.file_dir = os.path.join(settings.MEDIA_ROOT, files.models.rel_local_file_dir(self.account_id))
     if not os.path.isdir(self.file_dir):
         os.makedirs(self.file_dir)
开发者ID:noriakioji,项目名称:QADDA,代码行数:9,代码来源:testHistogram.py

示例14: test_get_pending_scans_not_empty

	def test_get_pending_scans_not_empty(self):
		acc = Account()
		acc.user = self.user

		fake_task_id = str(uuid4())
		run = ScanRun.objects.create_pending_scan_run(self.inert, fake_task_id)
		pending = acc.get_pending_scans()
		#  pending == ['<ScanRun: 3 2013-08-19 14:37:56.165701+00:00>']
		self.assertTrue(isinstance(pending[0], ScanRun),
		                msg='Pending scan object is not of instance of ScanRun: {0}'.format(pending[0]))
开发者ID:MarlonNakouzi,项目名称:phagescan,代码行数:10,代码来源:tests.py

示例15: setUp

    def setUp(self):
        django.setup()
        self.client = Client()
        Account.register(FilesTest.username, "[email protected]", "password", "password")
        self.account_id = Account.objects.get(username="brobot").id
        self.client.login(username="brobot", password="password")

        self.file_dir = os.path.join(settings.MEDIA_ROOT, files.models.rel_local_file_dir(self.account_id))
        if not os.path.isdir(self.file_dir):
            os.makedirs(self.file_dir)
开发者ID:noriakioji,项目名称:QADDA,代码行数:10,代码来源:testFile.py


注:本文中的accounts.models.Account类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。