本文整理汇总了Python中models.Account.save方法的典型用法代码示例。如果您正苦于以下问题:Python Account.save方法的具体用法?Python Account.save怎么用?Python Account.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Account
的用法示例。
在下文中一共展示了Account.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_model_liability
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def test_model_liability(self):
"Test liability model"
contact_type = ContactType(name='test')
contact_type.save()
contact = Contact(name='test', contact_type=contact_type)
contact.save()
currency = Currency(code="GBP",
name="Pounds",
symbol="L",
is_default=True)
currency.save()
account = Account(
name='test', owner=contact, balance_currency=currency)
account.save()
obj = Liability(name='test',
source=contact,
target=contact,
account=account,
value=10,
value_currency=currency)
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
示例2: save
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def save(self, role=1):
user = Account(**self.data)
user.role=role
user.save()
stuusr=Student(stuid=user.username,grade="20"+user.username[0:2])
stuusr.save()
return user
示例3: callback
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def callback(request):
oauth_token = request.GET.get('oauth_token')
oauth_verifier = request.GET.get('oauth_verifier')
oauth = OAuth1(settings.CONSUMER_KEY,
client_secret=settings.CONSUMER_SECRET,
resource_owner_key = request.session['key'],
resource_owner_secret = request.session['secret'],
verifier=oauth_verifier)
r = requests.post(TWITTER_BASE + 'oauth/access_token', auth=oauth)
credentials = parse_qs(r.content)
oauth_token = credentials.get('oauth_token')[0]
oauth_token_secret = credentials.get('oauth_token_secret')[0]
user_id = credentials.get('user_id')[0]
screen_name = credentials.get('screen_name')[0]
account = Account(
oauth_token=oauth_token,
oauth_token_secret=oauth_token_secret,
user_id=user_id,
screen_name=screen_name)
account.save()
d = {
'oauth_token': oauth_token,
'oauth_token_secret': oauth_token_secret,
'user_id': user_id,
'screen_name': screen_name,
}
return render_to_response('callback.html', d)
示例4: cw_register
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def cw_register(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
email = request.POST.get('email', '')
first_name = request.POST.get('first_name', '')
last_name = request.POST.get('last_name', '')
zip_code = request.POST.get('zip', '')
if User.objects.filter(email=email).exists():
return HttpResponseBadRequest(reason='An account exists for this email address.')
if User.objects.filter(username=username).exists():
return HttpResponseBadRequest(reason='Sorry, this username is taken.')
try:
User.objects.create_user(username, email, password)
user = authenticate(username=username, password=password)
user.is_active = False
user.save()
except Exception as e:
return HttpResponseServerError(reason=str(e))
try:
account = Account(user=user, email=email, first_name=first_name, last_name=last_name, zip_code=zip_code)
account.save()
login(request, user)
return HttpResponse()
except Exception as e:
user.delete()
return HttpResponseServerError(reason=str(e))
示例5: test_basic_addition
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def test_basic_addition(self):
"""
Test roles on Django model classes.
"""
src = Account(balance=1000)
dst = Account(balance=0)
src.save()
dst.save()
accounts = Account.objects.all()
assert len(accounts) == 2
assert accounts[0].balance == 1000, accounts[0].balance
assert accounts[1].balance == 0, accounts[1].balance
ctx = TransferMoney(src, dst)
ctx.transfer_money(amount=100)
print src, src.balance
assert src.balance == 900
print dst, dst.balance
assert dst.balance == 100
accounts = Account.objects.all()
assert accounts[0].balance == 900, accounts[0].balance
assert accounts[1].balance == 100, accounts[1].balance
示例6: register_page
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def register_page(request):
if request.method == 'POST':
form = FormularzRejestracji(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
password=form.cleaned_data['password1'],
)
user.save()
acc = Account()
acc.owner = user.username
acc.balance = 0
acc.save()
if form.cleaned_data['log_on']:
user = authenticate(username=form.cleaned_data['username'],password=form.cleaned_data['password1'])
login(request,user)
return HttpResponseRedirect("/blog/")
else:
template = get_template("registration/register_success.html")
variables = RequestContext(request,{'username':form.cleaned_data['username']})
output = template.render(variables)
return HttpResponse(output)
else:
form = FormularzRejestracji()
template = get_template("registration/register.html")
variables = RequestContext(request,{'form':form})
output = template.render(variables)
return HttpResponse(output)
示例7: create_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def create_account(email, password):
"""No API endpoint calls this method - it's meant to be used via CLI"""
AuthController.validate_email(email)
try:
account = Account(email, password)
account.save()
except Exception as e:
logger.error(e)
raise Error(FATAL)
示例8: save
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def save(self, user):
cd = self.cleaned_data
account = Account(
number=cd['number'],
bank=cd['bank'],
balance=cd['balance'],
nominal=cd['nominal'],
user=user
)
account.save()
示例9: save
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def save(self):
user = Account(**self.data)
user.save()
if self.role.data == 1:
stuusr = Student(stuid=self.username.data)
stuusr.save()
if self.role.data == 3:
teausr = Teacher(teaid=self.username.data)
teausr.save()
return self.username.data, self.role.data
示例10: accountcreate_create
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def accountcreate_create(request):
try:
person_show=name = request.session["Uid"]
except:
return render_to_response( "login.html",{'nameerror':'非法'})
account=request.GET["account"]
kindname=request.GET["kindname"]
sum1=string.atof(request.GET["sum1"])
proid=request.GET["proid"]
firstm=string.atof(request.GET["firstm"])
accid = request.GET["accid"]
d1=Project.objects.get(pid = proid)
str1=kindname
str2=account
s1 = str1.split(',')
s2 = str2.split(',')
if d1.iscreate == False:
for i in range(0,len(s1)-1):
c1=s1[i]
c2=string.atof(s2[i])
b=Prokindaccount( proid = d1,payname = c1,money_sum = (c2 * 10000),money_cost = 0,buff = 0,)
b.save()
d1.iscreate=True
d1.save()
a=Account(project_id=d1,money_sum = (sum1 * 10000),money_act = (firstm * 10000),money_cost = 0,account_id = accid,)
a.save()
e=Accountadd_record(project_id = d1,time = datetime.datetime.now(),money_add = (firstm * 10000),)
e.save()
else:
Prokindaccount.objects.filter(proid = proid).delete()
for i in range(0,len(s1)-1):
c1=s1[i]
c2=string.atof(s2[i])
b=Prokindaccount( proid = d1,payname = c1,money_sum = (c2*10000),money_cost = 0,buff = 0,)
b.save()
Accountadd_record.objects.get(project_id = proid).delete()
e=Accountadd_record(project_id = d1,time = datetime.datetime.now(),money_add = (firstm * 10000),)
e.save()
a=Account.objects.get(project_id = proid)
a.money_sum= (sum1 * 10000)
a.money_act = (firstm * 10000)
a.account_id = accid
a.save()
alldata=[]
onedata = [0,0]
onedata[0] = "1"
onedata[1] = '2'
alldata.append(onedata)
data = simplejson.dumps(alldata)
return HttpResponse(data, 'application/javascript')
示例11: get_or_create_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def get_or_create_account(protocol, uid, owner_account = None):
user_accounts = Account.objects.filter(uid=uid).filter(protocol=protocol)
if len(user_accounts) == 0:
user_account = Account()
if owner_account is not None:
if owner_account == uid:
user_account.owned = True
user_account.protocol = protocol
user_account.uid = uid
user_account.save()
else:
user_account = user_accounts[0]
return user_account
示例12: callback
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def callback(request):
error = False
token = request.session.get('token', None)
if not token: error = True
token = oauth.OAuthToken.from_string(token)
if token.key != request.GET.get('oauth_token', 'no-token'): error = True
token = get_authorized_token(token)
# Actually login
obj = is_authorized(token)
if obj is None: error = True
if error:
return HttpResponseRedirect('/?msg=2')
username_twitter = obj['screen_name']
try: # Connexion au compte existant
u = User.objects.get(username=username_twitter)
user = Account.objects.get(user=u)
new_id = u.id
password_value = user.password
except User.DoesNotExist: # Creation du compte
password_value = makePassword(39,40)
new_user = User.objects.create_user(username=username_twitter, email='[email protected]', password=password_value)
new_user.first_name = obj['name']
new_user.is_staff = False
new_user.is_superuser = False
new_user.save()
usermod = new_user
new_id = new_user.id
user = Account(user=new_user)
user.password = password_value
user.oauth_token = token.key
user.oauth_token_secret = token.secret
user.url = obj['url']
user.location = obj['location']
user.description = obj['description']
user.avatar_url = obj['profile_image_url']
user.save()
userco = authenticate(username=username_twitter, password=password_value)
if userco is not None:
login(request, userco)
return HttpResponseRedirect('/?msg=2')
else:
return HttpResponseRedirect('/?msg=1')
示例13: save
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def save(self, commit=True):
item = super(customerForm, self).save(commit=False)
item.set_password(self.cleaned_data["password"])
account = Account(name=self.cleaned_data["name"], access=self.cleaned_data["access"],
args2=self.cleaned_data["args2"], num_threads=self.cleaned_data["num_threads"])
purchase = Purchase(startDate=self.cleaned_data["startDate"], endDate=self.cleaned_data["endDate"],
initial=self.cleaned_data["initial"], available=self.cleaned_data["initial"])
if commit:
item.save()
self.save_m2m()
account.customer = item
account.save()
purchase.account = account
purchase.save()
return item
示例14: index
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def index(request):
user, email, usernum = request.user.username.split("|")[:]
result = Account.objects.filter(user=user).count()
now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(time.time())))
if result:
Account.objects.filter(user=user).update(last_login_time=now)
else:
a = Account(
user = user,
email = email,
usernum = usernum,
is_supper_user = 0,
last_login_time = now,
)
a.save()
Account.objects.filter(user=user).update(usernum=usernum, last_login_time=now)
return HttpResponseRedirect("/task/list/1/")
示例15: register
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import save [as 别名]
def register(request):
register = Customer(firstname = request.POST.get('firstName'),
lastname = request.POST.get('lastName'),
username = request.POST.get('userName'),
password = request.POST.get('password'),
contactno = request.POST.get('contactNo'))
register.save()
custId = register.custid
addAccount = Account(customerid = custId,
balance= request.POST.get('balance'))
addAccount.save()
# cust_id = res[0].id
# return HttpResponse(cust_id)
#return render(request,"myprojects/welcome.html")
t = get_template("myprojects/sucess.html")
text = 'Registered Sucessfully'
c = RequestContext(request, { 'text' : text } )
return HttpResponse(t.render(c))