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


Python models.User类代码示例

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


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

示例1: register

def register(request):
    user = None
    # checks if the http request is POST
    if request.method == 'POST':
        form = UserForm(request.POST)
        # form validation
        if form.is_valid():
            #Uses stripe API to create a customer in stripe
            # update based on your billing method (subscription vs one time)
            # pdb.set_trace()
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                # card=form.cleaned_data['stripe_token'],
                card={
                    'number': '4242424242424242',
                    'exp_month': 10,
                    'exp_year': 2018,
                },
                plan="gold",
            )

            # customer = stripe.Charge.create(
                # description = form.cleaned_data['email'],
                # card = form.cleand_data['stripe_token'],
                # amount = "5000"
                # currency = "usd"
            # )
            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )
            # set_password takes care of password hasing
            # ensure encrypted password
            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + ' is already a member')
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')
    else:
        form = UserForm()

    return render_to_response(
        'register.html',
        {
            'form': form,
            'months': range(1, 13),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2037),
        },
        context_instance=RequestContext(request)
    )
开发者ID:hooliooo,项目名称:django_ecommerce,代码行数:60,代码来源:views.py

示例2: test_index_handles_logged_in_user

def test_index_handles_logged_in_user(self):

	# create user for lookup and index

	from payments.models import User
	user = User(
		name = 'jj',
		email = '[email protected]',
		)

	user.save()

	# code snippet

	# verify that the response returns the page for the logged in user
	request_factory = RequestFactory()
	request = request_factory('/')

	# create session that appears to have user logged in
	request.session = {"user" : "1"}

	#request the index page
	resp = index(request)

	# verify it returns the page for the logged in user
	self.assertEquals(
		resp.content, render_to_response('user.html'), {"user" : user}).content



	self.assertTemplateUsed(resp, 'user.htlm')
开发者ID:hnejadi,项目名称:django_ecommerce-10,代码行数:31,代码来源:tests.py

示例3: test_index_handles_logged_in_user

    def test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user": "1"}

        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u = User(email="[email protected]")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            #tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            #run the test
            resp = index(self.request)

            #ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            #we are now sending a lot of state for logged in users, rather than
            #recreating that all here, let's just check for some text
            #that should only be present when we are logged in.
            self.assertContains(resp, "Report back to base")
开发者ID:chrisbeedie,项目名称:MEC,代码行数:26,代码来源:testMainPageView.py

示例4: register

def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        print(request)
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        print(form)
        if form.is_valid():
            #update based on your billing method (subscription vs one time)
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",

            )
            # customer = stripe.Charge.create(
            #     description = form.cleaned_data['email'],
            #     card = form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd"
            # )

            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )

            #ensure encrypted password
            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + ' is already a member')
            else:
                request.session['user'] = user.pk
                return redirect('/')

    else:
        form = UserForm()


    return render(
        request,
        'register.html',
        {
            'form': form,
            'months': range(1, 12),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2036),
        },
    )
开发者ID:Pac23,项目名称:book2-exercises,代码行数:58,代码来源:views.py

示例5: test_create_user_function_throws_Integrity_error

	def test_create_user_function_throws_Integrity_error(self):
		try:
			with trans.atomic(): # Helps fix troubles with databse transaction managment
				User.create('test_user','[email protected]','pass','1234','11').save()

		except IntegrityError:
			pass

		else:
			raise Exception('Exception was`t trown') 
开发者ID:hnejadi,项目名称:django-ecommerce,代码行数:10,代码来源:testModels.py

示例6: test_registering_user_twice_cause_error_msg

  def test_registering_user_twice_cause_error_msg(self):

    # create a user with same email so we get an integrity error
    user = User(name='test_user', email='[email protected]')
    user.save()

    # now create the request used to test the view
    self.request.session = {}
    self.request.method = 'POST'
    self.request.POST = {
        'email': '[email protected]',
        'name': 'test_user',
        'stripe_token': '4242424242424242',
        'last_4_digits': '4242',
        'password': '123456',
        'ver_password': '123456',
    }

    # create our expected form
    expected_form = UserForm(self.request.POST)
    expected_form.is_valid()

    expected_form.addError('[email protected] is already a member')

    # create the expected html
    html = render_to_response(
        'register.html',
        {
          'form': expected_form,
          'months': range(1, 12),
          'publishable': settings.STRIPE_PUBLISHABLE,
          'soon': soon(),
          'user': None,
          'years': range(2011, 2036),
        }
    )

    # mock out stripe so we don't hit their server
    with mock.patch('stripe.Customer') as stripe_mock:
      config = {'create.return_value': mock.Mock()}
      stripe_mock.configure_mock(**config)

      # run the test
      resp = register(self.request)

      # verify that we did things correctly
      self.assertEquals(resp.status_code, 200)
      self.assertEquals(self.request.session, {})

      # assert there is only one record in the database.
      users = User.objects.filter(email='[email protected]')
      #self.assertEquals(len(users), 1)

      # check actual return
      self.assertEquals(resp.content, html.content)
开发者ID:ddrsmile,项目名称:django-ecommerce,代码行数:55,代码来源:testViews.py

示例7: test_registering_user_twice_cause_error_msg

	def test_registering_user_twice_cause_error_msg(self):

		try:
			with transaction.atomic():

				user = User(name = 'pyRock', email = '[email protected]')
				user.save()

				self.request.session = {}
				self.request.method = 'POST'
				self.request.POST = {
					'email': '[email protected]',
					'name': 'pyRock',
					'stripe_token': '...',
					'last_4_digits': '4242',
					'password': 'bad_password',
					'ver_password': 'bad_password',
				}

				expected_form = UserForm(self.request.POST)
				expected_form.is_valid()
				expected_form.addError('[email protected] is already a member')

				html = render_to_response(
					'register.html',
					{
						'form': expected_form,
						'months': list(range(1, 12)),
						'publishable': settings.STRIPE_PUBLISHABLE,
						'soon': soon(),
						'user': None,
						'years': list(range(2011, 2036)),
					}
				)

				with mock.patch('stripe.Customer') as stripe_mock:


					config = {'create.return_value': mock.Mock()}
					stripe_mock.configure_mock(**config)

					resp = register(self.request)
					users = User.objects.filter(email = '[email protected]')
					#self.assertEquals(len(users), 1)
					self.assertEqual(resp.status_code, 200)
					self.assertEqual(self.request.session, {})
					


					
					
		except IntegrityError:
			pass
开发者ID:0cN,项目名称:django_ecommerce,代码行数:53,代码来源:tests.py

示例8: register

def register(request):
    print "USERFORM = " + str(UserForm)
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            # subscription billing

            print "YO!"
            print "STRIPE_PUBLISHABLE = " + str(settings.STRIPE_PUBLISHABLE)
            print "stripe_token = " + form.cleaned_data['stripe_token']
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )

            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )

            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                print "Already a member bro!"
                form.addError(user.email + ' is already a member')
            else:
                print "Save user payment profile"
                request.session['user'] = user.pk
                print request.session['user']
                return HttpResponseRedirect('/')
    else:
        form = UserForm()

    return render_to_response(
        'register.html',
        {
            'form': form,
            'months': range(1, 12),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2036),
        },
        context_instance=RequestContext(request)
    )
开发者ID:ShermanMorrison,项目名称:django_ecommerce,代码行数:53,代码来源:views.py

示例9: test_index_handles_logged_in_user

 def test_index_handles_logged_in_user(self):
     user = User(
         name='jj',
         email='[email protected]',
     )
     user.save()
     self.request.session = {'user': "1"}
     resp = index(self.request)
     self.request.session = {}
     expected_html = render_to_response('user.html',
                                       {'user': user}).content
     self.assertEqual(resp.content, expected_html)
开发者ID:hemepositive,项目名称:django_ecommerce,代码行数:12,代码来源:tests.py

示例10: register

def register(request):
    user = None
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():

            # update based on your billing method (subscription vs one time)
            customer = stripe.Customer.create(
                email=form.cleaned_data["email"],
                description=form.cleaned_data["name"],
                card=form.cleaned_data["stripe_token"],
                plan="gold",
            )

            # customer = stripe.Charge.create(
            #   description=form.cleaned_data['email'],
            #  card=form.cleaned_data['stripe_token'],
            # amount="5000",
            # currency="usd"
            # )
            user = User(
                name=form.cleaned_data["name"],
                email=form.cleaned_data["email"],
                last_4_digits=form.cleaned_data["last_4_digits"],
                stripe_id=customer.id,
            )

            # ensure encrypted password
            user.set_password(form.cleaned_data["password"])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + " is already a member")
            else:
                request.session["user"] = user.pk
                return HttpResponseRedirect("/")

    else:
        form = UserForm()

    return render_to_response(
        "register.html",
        {
            "form": form,
            "months": range(1, 13),
            "publishable": settings.STRIPE_PUBLISHABLE,
            "soon": soon(),
            "user": user,
            "years": range(2015, 2041),
        },
        context_instance=RequestContext(request),
    )
开发者ID:ujrc,项目名称:Realpython_book3,代码行数:53,代码来源:views.py

示例11: test_index_handles_logged_in_user

	def test_index_handles_logged_in_user(self):
		user=User(name='jj', email = '[email protected]',)
		user.save()
		self.request.session={"user":"1"}

		with mock.patch('main.views.User') as user_mock:
			config = {'get.return_value': user}
			user_mock.objects.configure_mock(**config)
			resp = index(self.request)
			self.request.session = {}

			expectedHtml = render_to_response('user.html',{'user':user}).content
			self.assertEquals(resp.content,expectedHtml)
开发者ID:fyasko,项目名称:pythontest,代码行数:13,代码来源:tests.py

示例12: register

def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            
            # Update based on billing method
            customer = stripe.Customer.create(
                            email=form.cleaned_data['email'],
                            description=form.cleaned_data['name'],
                            card=form.cleaned_data['stripe_token'],
                            plan="gold",
                        )
#            customer = stripe.Charge.create(
#                            description=form.cleaned_data['email'],
#                            card=form.cleaned_data['stripe_token']
#                            amount="5000",
#                            currency="usd",
#                        )
            user = User(
                        name=form.cleaned_data['name'],
                        email=form.cleaned_data['email'],
                        last_4_digits=form.cleaned_data['last_4_digits'],
                        stripe_id=customer.id,
                        password=form.cleaned_data['password'],
                    )
            
#            user.set_password(form.cleaned_data['password'])
            
            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + 'is already a member')
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')
    else:
        form = UserForm()
    
    return render_to_response(
                'register.html',
                {
                    'form': form,
                    'months': range(1, 12),
                    'publishable': settings.STRIPE_PUBLISHABLE,
                    'soon': soon(),
                    'user': user,
                    'years': range(2014, 2039),
                },
                context_instance=RequestContext(request),
            )
开发者ID:mikelazzaro,项目名称:real_python,代码行数:51,代码来源:views.py

示例13: register

def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
            # customer = stripe.Charge.create(
            #     description=form.cleaned_data['email'],
            #     card=form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd"
            # )

            cd = form.cleaned_data
            try:
                with transaction.atomic():
                    user = User.create(
                        cd['name'],
                        cd['email'],
                        cd['password'],
                        cd['last_4_digits'],
                        stripe_id=''
                    )

                    if customer:
                        user.stripe_id = customer.id
                        user.save()
                    else:
                        UnpaidUsers(email=cd['email']).save()

            except IntegrityError:
                import traceback
                form.addError(cd['email'] + ' is already a member' + traceback.format_exc())
                user = None
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')

    else:
        form = UserForm()

    return render_to_response(
        'payments/register.html',
        {
            'form': form,
            'months': list(range(1, 12)),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': list(range(2011, 2036)),
        },
        context_instance=RequestContext(request)
    )
开发者ID:jerodestapa,项目名称:django_ecomm_stripe,代码行数:60,代码来源:views.py

示例14: index

def index(request):
    uid = request.session.get('user')
    if uid is None:
        #main landing page
        market_items=MarketingItem.objects.all()
        return render_to_response('main/index.html',
        {'marketing_items': market_items})
    else:
        #membership page
        status=StatusReport.objects.all().order_by('-when')[:20]
        announce_date=date.today()-timedelta(days=30)
        announces=(Announcement.objects.filter(publication_date__gt=announce_date).order_by('-publication_date'))

        usr=User.get_by_id(uid)
        badges=usr.badges.all()

        return render_to_response(
            'main/user.html',
            #{
            # 'marketing_items':market_items,
            #'user': User.get_by_id(uid),'reports':status},

            {
            'user':usr,
            'badges':badges,
            'reports':status,
            'announces':announces
            },
            context_instance=RequestContext(request)
        )
开发者ID:ujrc,项目名称:Realpython_book3,代码行数:30,代码来源:views.py

示例15: test_create_user_function_stores_in_database

    def test_create_user_function_stores_in_database(self):
        """TODO: Docstring for test_create_user_function_stores_in_database.
        :returns: TODO

        """
        user = User.create('test', '[email protected]', 'tt', '1234', '22')
        self.assertEqual(User.objects.get(email='[email protected]'), user)
开发者ID:Copser,项目名称:DjanCommerce,代码行数:7,代码来源:testUserModel.py


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