本文整理汇总了Python中accounts.models.Account.save方法的典型用法代码示例。如果您正苦于以下问题:Python Account.save方法的具体用法?Python Account.save怎么用?Python Account.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.Account
的用法示例。
在下文中一共展示了Account.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_new_user
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def register_new_user(request):
json_obj=json.loads(request.body)
json_obj=json_obj['userInfo']
if User.objects.filter(username = json_obj['userName']).exists():
print "Username already Exist."
return HttpResponse(json.dumps({"validation":"Username is already exist.","status":False}), content_type="application/json")
username = json_obj['userName']
first_name = json_obj['firstName']
last_name = json_obj['lastName']
password = json_obj['password']
password1 = json_obj['confirmPassword']
if password != password1:
print "Passwords Are not Matching"
return HttpResponse(json.dumps({"validation":"Passwords are not Matched","status":False}), content_type="application/json")
email = validateEmail(json_obj['email'])
if email != True:
print "Email is already Exist."
return HttpResponse(json.dumps({"validation":"Email is already exist.Try with another Email.","status":False}), content_type="application/json")
else:
email = json_obj['email']
if json_obj['addressLine1'] is None:
return HttpResponse(json.dumps({"validation":"Please Enter Your Address...!","status":False}), content_type="application/json")
else:
address_line1 = json_obj['addressLine1']
address_line2 = json_obj['addressLine2']
contact_no = json_obj['mobileNo0']
contact_no = int(contact_no)
contact_no = validate_mobile(str(contact_no))
if contact_no == False:
return HttpResponse(json.dumps([{"validation": "This mobile number is already used..please try with another one.", "status": False}]), content_type = "application/json")
else:
contact_no1 = json_obj['mobileNo1']
city = json_obj['city']
state = json_obj['state']
country = json_obj['country']
pin_code = json_obj['pincode']
accounttype_obj = AccountType(optionType=1)
accounttype_obj.save()
group_obj_for_bank_acc = Group(optionType=0)
group_obj_for_bank_acc.save()
group_obj_for_cash_acc = Group(optionType=4)
group_obj_for_cash_acc.save()
bank_account_name = "My Bank Account"
cash_account_name = "My Cash Account"
bank_account_obj = Account(account_name=bank_account_name,first_name=first_name,last_name=last_name,contact_no=contact_no,address_line1=address_line1,city=city,state=state,country=country,pin_code=pin_code,accounttype=accounttype_obj,group=group_obj_for_bank_acc)
bank_account_obj.save()
cash_account_obj = Account(account_name=cash_account_name,first_name=first_name,last_name=last_name,contact_no=contact_no,address_line1=address_line1,city=city,state=state,country=country,pin_code=pin_code,accounttype=accounttype_obj,group=group_obj_for_cash_acc)
cash_account_obj.save()
user_obj = User(first_name=first_name,last_name=last_name,username=username,email=email,password=password)
user_obj.set_password(password)
user_obj.save()
userdetail_obj = UserDetail(user=user_obj,address_line1=address_line1,address_line2=address_line2,contact_no=contact_no,city=city,
state=state,country=country,pin_code=pin_code,contact_no1=contact_no1,bank_account=bank_account_obj,cash_account=cash_account_obj)
userdetail_obj.save()
print "Registration Successful"
return HttpResponse(json.dumps({"validation":"Registration Successful.","redirecturl":"#/login","status":True}), content_type="application/json")
示例2: reg_service
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
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")
示例3: reg_service
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
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')
示例4: add_dormant_user
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def add_dormant_user(self,user_info):
# create dormant user account
temp_username = user_info['firstName'] + user_info['lastName'] + user_info['id']
temp_username = temp_username[:30]
# self.stdout.write(temp_username)
user = User()
user.username = temp_username
user.save()
# create user profile
user.profile.first_name = user_info['firstName']
user.profile.last_name = user_info['lastName']
if 'headline' in user_info:
user.profile.headline = user_info['headline']
user.profile.status = "dormant"
user.profile.save()
# add pofile picture
if 'pictureUrl' in user_info:
self.add_profile_pic(user,user_info['pictureUrl'])
# create LinkedIn account
acct = Account()
acct.owner = user
acct.service = 'linkedin'
acct.uniq_id = user_info['id']
if 'publicProfileUrl' in user_info:
acct.public_url = user_info['publicProfileUrl']
acct.status = "unlinked"
acct.save()
return user
示例5: hub_add_account
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
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},
)
示例6: process_connection_and_finish_user
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def process_connection_and_finish_user(self, user, user_info):
"""
Delegates to helpers to process rest of User, adds Account, maps positions
Return: User
"""
## add LI account
acct = Account()
acct.owner = user
acct.service = 'linkedin'
acct.uniq_id = user_info['id']
if 'publicProfileUrl' in user_info:
acct.public_url = user_info['publicProfileUrl']
acct.status = 'unlinked'
acct.save()
## Edge case that showed up in production
if 'publicProfileUrl' not in user_info:
return user
## parse public page
self.process_public_page_existing(user_info['publicProfileUrl'], user)
## Map Positions
# match all positions to ideals
for p in user.positions.all():
careerlib.match_position_to_ideals(p)
# process first_ideal_position
user.profile.set_first_ideal_job()
return user
示例7: register
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [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")
示例8: registerUser
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
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")
示例9: test_double_amount
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
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)
示例10: create_account
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def create_account():
act = Account()
act.name = request.form.get('name')
act.provider = request.form.get('provider')
act.provider_id = request.form.get('provider_id')
act.provider_key = request.form.get('provider_key')
act.organization = request.form.get('organization').lower()
act.save()
return redirect(url_for('accounts.accounts'))
示例11: test_linkedin_auth
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def test_linkedin_auth(self):
# create new user
default_user = User.objects.create_user(username="ahamilton",password="aburr")
# add LI info
acct = Account(owner=default_user,service="linkedin",uniq_id="1e3r5y78i!")
acct.save()
# test auth
result = self.c.login(acct_id=acct.uniq_id)
if result is not None:
result = True
self.assertEqual(result,True)
示例12: test_unlinked_process_connections
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def test_unlinked_process_connections(self):
# create new user
default_user = User.objects.create_user(username="ahamilton",password="aburr")
# add bogus LI account
acct = Account(service="linkedin",status="unlinked",owner=default_user)
acct.save()
# ensure that lilib won't process connections
li_cxn_parser = self.lilib.LIConnections(default_user.id,acct.id)
res = li_cxn_parser.process_connections()
self.assertEqual(res,"Error: LI accont is not active, aborting")
示例13: process
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def process(self, uid):
data = self.cleaned_data
name = data['name']
user = User.objects.get(id=uid)
profile = user.get_profile()
accounts = profile.accounts
account = Account(name=name, owner=user)
account.save()
accounts.add(account)
profile.save()
user.save()
示例14: _saveSfdcNewAccount
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
def _saveSfdcNewAccount(sfdc_id, newAccount, relatedLeadList, company_id):
account = Account()
account.sfdc_id = sfdc_id
account.source_name = newAccount['Name']
account.source_source = newAccount['AccountSource']
account.source_industry = newAccount['Industry']
account.source_created_date = newAccount['CreatedDate']
account.accounts = {}
account.accounts["sfdc"] = newAccount
if relatedLeadList is not None:
account.leads = relatedLeadList
account.company_id = company_id
account.opportunities = {}
account.save()
return account
示例15: PostValidLogin
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import save [as 别名]
class PostValidLogin(DjangoHTTPContext):
def setup(self):
self.validUser = Account(username='validuser',password='pass')
self.validUser.save()
def teardown(self):
self.validUser.delete()
def topic(self):
return self.post('/login/',
{'username':self.validUser.username,
'password':self.validUser.password})
def should_return_valid_login(self, (topic,content)):
expect(content).to_equal("Login Succesful")