本文整理匯總了Python中accounts.models.Account.user方法的典型用法代碼示例。如果您正苦於以下問題:Python Account.user方法的具體用法?Python Account.user怎麽用?Python Account.user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類accounts.models.Account
的用法示例。
在下文中一共展示了Account.user方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
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")
示例2: test_get_samples
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
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]))
示例3: test_get_pending_scans_not_empty
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
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]))
示例4: create_account
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
def create_account(user):
try:
account = Account.objects.get(user=user)
# print "Account already exists"
except:
account = Account()
account.user = User.objects.get(pk=user.id)
account.created_by = user
try:
account.save()
return True
except Exception as e:
print "Unable to save account..."
print e
return False
return True
示例5: checkout
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
def checkout(request, cart, order):
"""Handle checkout process - if the order is completed, show the success
page, otherwise show the checkout form.
"""
# if the cart is already linked with an order, show that order
if not order and cart.order_obj:
return redirect(cart.order_obj)
if order and order.status >= Order.STATUS_PAID:
if cart.order_obj == order:
cart.clear()
return {
"template": "success",
"order": order,
}
if request.user.is_authenticated():
account = Account.objects.for_user(request.user)
get_user_form = lambda *a: None
else:
account = Account()
get_user_form = partial(CheckoutUserForm)
if order:
get_form = partial(OrderForm, instance=order)
get_gift_form = partial(GiftRecipientForm, prefix='gift',
instance=order.get_gift_recipient())
def sanity_check():
return 0
new_order = False
else:
# set initial data from the user's account, the shipping
# options, and any saved session data
initial = {}
if account.pk and not initial:
initial.update(account.as_dict())
shipping_module = get_shipping_module()
if shipping_module:
initial.update(shipping_module.get_session(request))
initial.update(request.session.get(CHECKOUT_SESSION_KEY, {}))
get_form = partial(OrderForm, initial=initial)
get_gift_form = partial(GiftRecipientForm, prefix='gift')
sanity_check = lambda: cart.subtotal
new_order = True
# Add in any custom cart verification here
cart_errors = []
if request.method == 'POST':
form = get_form(request.POST, sanity_check=sanity_check())
user_form = get_user_form(request.POST)
save_details = not account.pk and request.POST.get('save-details')
if save_details and user_form:
# if creating a new user, the email needs to be unused
form.require_unique_email = True
user_form_valid = user_form.is_valid()
else:
user_form_valid = True
gift_form = get_gift_form(request.POST)
is_gift = request.POST.get('is_gift')
gift_form_valid = gift_form.is_valid() if is_gift else True
if form.is_valid() and (order or not cart.empty()) and \
user_form_valid and gift_form_valid and not len(cart_errors):
# save the order obj to the db...
order = form.save(commit=False)
order.currency = cart.currency
# save details to account if requested
if save_details:
account.from_obj(order)
if user_form:
user = user_form.save(email=order.email, name=order.name)
account.user = user
auth_user = authenticate(
username=user.email,
password=user_form.cleaned_data['password1'])
login(request, auth_user)
account.save()
if account.pk:
order.account = account
order.save()
if is_gift:
recipient = gift_form.save(commit=False)
recipient.order = order
recipient.save()
elif gift_form.instance and gift_form.instance.pk:
gift_form.instance.delete()
# save any cart lines to the order, overwriting existing lines, but
#.........這裏部分代碼省略.........
示例6: test_get_pending_scans_empty
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
def test_get_pending_scans_empty(self):
acc = Account()
acc.user = self.user
pending = acc.get_pending_scans()
self.assertQuerysetEqual(pending, [])
示例7: test_api_key
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import user [as 別名]
def test_api_key(self):
acc = Account()
acc.user = self.user
key = acc.get_api_key()
self.assertIsNotNone(key, msg="API key is none.")