當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。