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


Python User.create方法代码示例

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


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

示例1: test_create_user_function_throws_Integrity_error

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
	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,代码行数:12,代码来源:testModels.py

示例2: register

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
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,代码行数:62,代码来源:views.py

示例3: test_create_user_function_stores_in_database

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
    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,代码行数:9,代码来源:testUserModel.py

示例4: register

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
def register(request):
    user = None
    if request.method == "POST":
        # We only talk AJAX posts now
        if not request.is_ajax():
            return HttpResponseBadRequest("I only speak AJAX nowadays")

        data = json.loads(request.body.decode())
        form = UserForm(data)

        if form.is_valid():
            try:
                customer = Customer.create(
                    "subscription",
                    email=form.cleaned_data["email"],
                    description=form.cleaned_data["name"],
                    card=form.cleaned_data["stripe_token"],
                    plan="gold",
                )
            except Exception as exp:
                form.addError(exp)

            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:
                resp = json.dumps({"status": "fail", "errors": cd["email"] + " is already a member"})
            else:
                request.session["user"] = user.pk
                resp = json.dumps({"status": "ok", "url": "/"})

            return HttpResponse(resp, content_type="application/json")
        else:  # form not valid
            resp = json.dumps({"status": "form-invalid", "errors": form.errors})
            return HttpResponse(resp, content_type="application/json")

    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:Umojivity,项目名称:main27,代码行数:61,代码来源:views.py

示例5: test_create_user_function_stores_in_database

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
    def test_create_user_function_stores_in_database(self):
        """
        Tests User.create method
        """
        new_user = User.create('jean', '[email protected]', 'password',
                               '1234', '1')
        test = User.objects.get(email='[email protected]')

        self.assertEquals(test, new_user)
开发者ID:Alberick0,项目名称:part3_realpython,代码行数:11,代码来源:tests.py

示例6: test_create_user_already_exists_throws_IntegrityError

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
 def test_create_user_already_exists_throws_IntegrityError(self):
     self.assertRaises(
         IntegrityError, 
         User.create(
         "test user",
         "[email protected]",
         "jj",
         "1234",
         89
         )
     )
开发者ID:hnejadi,项目名称:django_ecommerce34,代码行数:13,代码来源:testUserModel.py

示例7: register

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
def register(request):
    user = None
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            if form.cleaned_data["sub_type"] == "monthly":
                # update based on your billing method(subscription vs onetime)
                customer = Customer.create(
                    email=form.cleaned_data["email"],
                    description=form.cleaned_data["name"],
                    card=form.cleaned_data["stripe_token"],
                    plan="gold",
                )
            else:
                customer = Customer.create(
                    email=form.cleaned_data["email"],
                    description=form.cleaned_data["name"],
                    card=form.cleaned_data["stripe_token"],
                    plan="Platinum",
                )

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

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

            except IntegrityError:
                form.addError(cd["email"] + " is already a member")
            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:joelstanner,项目名称:realpython---django-mvp,代码行数:55,代码来源:views.py

示例8: register

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
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"
			#)

			
			cd = form.cleaned_data
			try:
				user = User.create(
					cd['name'],
					cd['email'],
					cd['password'],
					cd['last_4_digits'],
					customer.id
				)

			except IntegrityError:
				form.addError(user.email + ' is already a member')
				user = None
			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(2011, 2036),
		},
		context_instance=RequestContext(request)
	)
开发者ID:betolarios,项目名称:django_ecommerce,代码行数:55,代码来源:views.py

示例9: register

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            #update based on billing method (subscrip vs one time[add appropriate code for one time])
            customer = Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
            
            cd = form.cleaned_data
            try:
                user = User.create(
                    cd['name'],
                    cd['email'],
                    cd['password'],
                    cd['last_4_digits'],
                    customer.id
                )
            except IntegrityError:
                form.addError(cd['email'] + ' is already a member')
                user = None
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')

    else:
        form = UserForm()

    return render_to_response(
        '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:Scientist94,项目名称:g_for_geek,代码行数:47,代码来源:views.py

示例10: register

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
def register(request):
    user = None
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():

            # update based on 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"
            # )

            cd = form.cleaned_data
            try:
                user = User.create(cd["name"], cd["email"], cd["password"], cd["last_4_digits"], customer.id)
            except IntegrityError:
                form.addError(cd["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(2011, 2036),
        },
        context_instance=RequestContext(request),
    )
开发者ID:hnejadi,项目名称:django-ecommerce-8,代码行数:45,代码来源:views.py

示例11: post_user

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
def post_user(request):
    form = UserForm(request.DATA)

    print("in post user")
    if form.is_valid():
        try:
            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                "subscription",
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
        except Exception as exp:
            form.addError(exp)

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

                if customer:
                    user.stripe_id = customer.id
                    user.save()
                else:
                    UnpaidUsers(email=cd['email']).save()
        except IntegrityError as e:
            print("----------Integristy error")
            print(e)
            form.addError(cd['email'] + ' is already a member')
        else:
            request.session['user'] = user.pk
            resp = {"status": "ok", "url": '/'}
            return Response(resp, content_type="application/json")

        resp = {"status": "fail", "errors": form.non_field_errors()}
        return Response(resp)
    else:  # for not valid
        resp = {"status": "form-invalid", "errors": form.errors}
        return Response(resp)
开发者ID:Munk801,项目名称:book3-exercises,代码行数:45,代码来源:json_views.py

示例12: setUp

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
 def setUp(self):
     self.valid_test_user = User.create(
         "tester", "[email protected]", "test", 1234)
     self.sign_in_page = SignInPage(self.browser, "http://"+SERVER_ADDR)
开发者ID:Munk801,项目名称:book3-exercises,代码行数:6,代码来源:testPage.py

示例13: test_create_user_function_stores_in_database

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
 def test_create_user_function_stores_in_database(self):
     user=User.create('test','[email protected]','tt','1234','22')
     self.assertEquals(User.objects.get(email='[email protected]'),user)
开发者ID:ujrc,项目名称:Realpython_book3,代码行数:5,代码来源:testUserModel.py

示例14: setUp

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
	def setUp(self):
		self.test_user = User.create('test_user','[email protected]','pass','1234','11')
		self.test_user.save()
开发者ID:hnejadi,项目名称:django-ecommerce,代码行数:5,代码来源:testModels.py

示例15: test_create_user_function_stores_in_database

# 需要导入模块: from payments.models import User [as 别名]
# 或者: from payments.models.User import create [as 别名]
 def test_create_user_function_stores_in_database(self):
     user = User.create("test", "[email protected]","tt","1234","22")
     self.assertEqual(User.objects.get(email="[email protected]"), user)
开发者ID:ANB2,项目名称:book3-exercises,代码行数:5,代码来源:testUserModel.py


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