本文整理汇总了Python中account.models.Account.save方法的典型用法代码示例。如果您正苦于以下问题:Python Account.save方法的具体用法?Python Account.save怎么用?Python Account.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.models.Account
的用法示例。
在下文中一共展示了Account.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __create_new_account__
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def __create_new_account__(self,email,user_data):
"""
We found a new account that does not exist in our database.
Create a Django User from user email and the associated Account object.
Password is automatically generated for the user.
"""
try:
id = self.__extract_account_id__(user_data["resource_uri"])
new_user = Account.create_user(email,email,
user_data["first_name"],
user_data["last_name"],
generate_password=True
)
new_account = Account(ip_address=user_data[u'tr_ip_address'],
email=email,
imported=True,
synched=False,
name = "%s %s" % (user_data["first_name"],user_data["last_name"]),
user = new_user,
imported_date = dt.utcnow().replace(tzinfo=utc),
external_id = id
)
new_account.save()
return True
except Exception,e :
print "Exception %s" % e
return False
示例2: import_banquepopulaire
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def import_banquepopulaire(data):
""" Parsing des données Banque Populaire au format CSV
Le format du fichier CSV proposé par la Banque Populaire est le suivant:
Le séparateur par défaut est ';' (point virgule)
Les champs disponibles sont:
- N° du compte
- Date de comptabilisation (au format JJ/MM/AAAA)
- Date de l'opération (au format JJ/MM/AAAA)
- Libellé
- Référence
- Date valeur (au format JJ/MM/AAAA)
- Montant
"""
# Traitement par lignes des données
for line in StringIO.StringIO(data):
# Découpage des champs CSV
csvdata = line.split(";")
if len(csvdata) < 7:
continue
# On ignore la ligne d'en-tête du CSV (si il y en a une)
if csvdata[0].isdigit() == False:
continue
# Date de l'opération
date = datetime.datetime.strptime(csvdata[2], "%d/%m/%Y").date()
# Montant de l'opération
try:
expense = float(csvdata[6])
except ValueError:
expense = float(csvdata[6].replace(",", "."))
# Description de l'opération et catégorisation
description = csvdata[3]
subcategory = settings.subcategory_default
# Modifications automatiques de la description et de la subcategory
description = change_description(description)
subcategory = change_subcategory(subcategory, description)
# halve or not
halve = halve_or_not("banquepopulaire", description)
if halve is True:
expense = expense / 2
account = Account(
date=date,
description=description,
expense=expense,
subcategory=subcategory,
bank="banquepopulaire",
check=False,
halve=halve,
)
account.save()
示例3: forwards
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def forwards(self, orm):
# we need to associate each user to an account object
for user in User.objects.all():
a = Account()
a.user = user
a.language = 'en' # default language
a.save()
示例4: get_account
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def get_account(request):
if request.user and request.user.is_authenticated():
try:
account = request.user.account_set.get() #get_profile()
except ObjectDoesNotExist:
user = request.user
account = Account(user=user, name='%s %s' % (user.first_name,
user.last_name))
account.save()
return {'account' : account}
return {'account' : None}
示例5: import_oney
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def import_oney(data):
""" Parsing des données pour Oney """
form_list = []
# creation liste avec une ligne une dépense
list_data = data.split("\n")
for e in list_data:
# une liste de chacun ligne est faite
e_list = e.split("\t")
# format_ex : [u'26/02/2015', u'PAYPAL - 0800 942 890 - traite le 27/02', u' ', u'45,80', u' \r']
if len(e_list) < 4: # si e_list a moins de 4 éléments dernier élément
continue
description = e_list[1].encode("utf-8")
if "Solde initial" in description:
continue
if "Prélèvement mensualité" in description:
continue
if "Intérêts" in description:
continue
# on definit chaque valeur d'un objet Account
# on définit la date comme un objet datetime
date = datetime.datetime.strptime(e_list[0], "%d/%m/%Y").date()
# l'id = la date + la depense ex: 201502264580
# description
description = re.sub(r" - traité le .*$", "", description)
description = re.sub(r" - [0-9 ]*PARIS[0-9 ]*$", "", description)
# modification description
description = change_description(description)
# definition de subcategory
subcategory = settings.subcategory_default
subcategory = change_subcategory(subcategory, description)
# expense : on récupère la dépense positive ou négtive
if e_list[2] == " ":
expense = float("-" + e_list[3].replace(",", "."))
elif e_list[3] == " ":
expense = float(e_list[2].replace(",", "."))
# halve or not
halve = halve_or_not("oney", description)
if halve is True:
expense = expense / 2
account = Account(
date=date,
description=description.decode("utf-8"),
expense=expense,
subcategory=subcategory,
bank="oney",
check=False,
halve=halve,
)
account.save()
示例6: regist
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def regist(request):
if request.method == 'POST':
form = SigninForm(request.POST)
if form.is_valid():
value = form.cleaned_data
user = User(email=value['email'],username = value['email'],password = value['password'])
user.save()
account = Account(user=user,nickname = value['nickname'])
account.save()
request.session['usr'] = account
return render_to_response('account/welcome.html',{'nickname':value['nickname']},context_instance=RequestContext(request))
else:
form = SigninForm()
return render_to_response('account/regist.html',{'form':form},context_instance=RequestContext(request))
示例7: login_to_account
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def login_to_account(request):
user = users.get_current_user()
if user:
request.session['user_email'] = user._User__email
a = Account.objects.filter(email = user._User__email)
if a.count()==0:
a = Account(username = user.nickname(), email = user._User__email)
a.save()
else:
a=a[0]
request.session['user'] = a.id
return HttpResponseRedirect('/')
else:
return HttpResponseRedirect(users.create_login_url('/accounts/login'))
示例8: test_accounts_list
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def test_accounts_list(self):
"""
If no polls exist, an appropriate message should be displayed.
"""
account = Account(email='[email protected]', password='password')
account.first_name = 'user1'
account.last_name = 'mail'
account.is_active = True
now = datetime.datetime.now()
account.created_at = now
account.updated_at = now
account.save()
response = self.client.get(reverse('account-list'))
self.assertEqual(response.status_code, 200)
示例9: account_registration
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def account_registration(request):
# if request.user.is_authenticated():
# return HttpResponseRedirect("/profile/")
if request.method == "POST":
form = RegistrationForm(request.POST)
if form.is_valid():
password = form.cleaned_data["password"]
logger.info( "Password is %s" % password )
username = form.cleaned_data["email"]
if len(username)>30:
username = username[:30]
user,success = Account.create_user(
email=form.cleaned_data["email"],
username= username,
password= password,
generate_password=False
)
acc = Account(user=user)
acc.email = form.cleaned_data["email"]
acc.name = form.cleaned_data["name"]
acc.synched = False
acc.ip_address = get_client_ip(request)
acc.save()
request.session[session_account_id_key] = acc.id
return HttpResponseRedirect("/profile/")
else:
response_data = {
"success":False,
"errors": [(k, v[0]) for k, v in form.errors.items()]
}
return HttpResponse(json.dumps(response_data),mimetype="application/json")
# return render_to_response("register.html",{"form":form},context_instance=RequestContext(request))
else:
"""user not submit"""
form = RegistrationForm
context = {"form":form}
return render_to_response("register.html",context,context_instance=RequestContext(request))
示例10: tweets
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def tweets():
tweets = []
for tweet in tweepy.Cursor(api.search, q='ISIS', rpp=100).items(100):
latitude = None
longitude = None
if tweet.geo:
latitude = None
longitude = None
#latitude = tweet.geo.latitude
#longitude = tweet.geo.longitude
print dir(tweet)
print '='*80
print dir(tweet.author)
print '='*80
accounts = Account.objects.filter(account_id=tweet.author.id_str)
if accounts.count():
account = accounts.first()
else:
tAccount = tweet.author
account = Account(
account_id=tAccount.id_str,
description=tAccount.description,
favourites_count=tAccount.favourites_count,
followers_count=tAccount.followers_count,
geo_enabled=tAccount.geo_enabled,
location=tAccount.location,
name=tAccount.name,
screen_name=tAccount.screen_name,
url=tAccount.url,
verified=tAccount.verified
)
account.save()
tweets.append(Tweet(
tweet_id=tweet.id_str,
place=tweet.place,
latitude=latitude,
longitude=longitude,
created_at=tweet.created_at,
text=tweet.text,
retweet_count=tweet.retweet_count,
retweeted=tweet.retweeted,
favorite_count=tweet.favorite_count,
favorited=tweet.favorited,
account=account
))
Tweet.objects.bulk_create(tweets)
示例11: post
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def post(self, request, *args, **kwargs):
account_form = AccountForm(request.POST)
if account_form.is_valid():
#user = account_form.cleaned_data['user']
#user = self.request.user
name = account_form.cleaned_data['name']
amount = account_form.cleaned_data['amount']
active = account_form.cleaned_data['active']
#account = Account(user=user, name=name, amount=amount, active=active)
account = Account(user=self.request.user, name=name, amount=amount, active=active)
account.save()
return HttpResponseRedirect('/')
else:
context = {'account_form': account_form}
return render(request, self.template_name, context)
示例12: make_account
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def make_account(self, level=1, people=1):
"""
Utility method: creates an account with
a specific subscription level and # people
"""
account = Account(
subscription_level_id = level,
)
account.save()
for i in range(people):
account.person_set.create(
username = 'person %i' % i,
password = 'password %i' % i,
first_name = 'first_name %i' % i,
last_name = 'last_name %i' % i,
email = 'email_%[email protected]' % i,
)
return account
示例13: login_return
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def login_return(request, backend_name):
backend = get_backend(backend_name)
redirect_url = request.session.get('post_login_redirect', '/')
return_url = "http://%s%s" % (settings.MAIN_HOST,
reverse('login_return', args=[backend_name]))
try:
access_token = backend.get_token(request, return_url)
except DenyException:
return HttpResponseRedirect(redirect_url)
except:
return _error_page(request)
user_data = backend.get_user_data(access_token)
account = Account.objects.filter(id_from_backend=user_data['id'],
backend=backend_name,
)
if account.count():
account = account[0]
user = account.user
user = authenticate(username=user.username, password=2)
login(request, user)
return HttpResponseRedirect(redirect_url)
if not request.user.is_authenticated():
un = "%s - %s" % (user_data['screen_name'], user_data['id'])
un = un[:30]
user, created = User.objects.get_or_create(username=un)
if created:
temp_password = User.objects.make_random_password(length=12)
user.set_password(temp_password)
user.first_name = user_data['name']
user.save()
user = authenticate(username=user.username, password=2)
else:
user = request.user
account = Account(user=user,
name=user.first_name,
img_url=user_data['picture'],
backend=backend_name,
id_from_backend=user_data['id'],
)
account.save()
login(request, user)
return HttpResponseRedirect(redirect_url)
示例14: import_boobank
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def import_boobank(data, bank):
""" Parsing des données Boobank
Le format die boobank est le suivant:
Le séparateur par défaut est ' ' (point virgule)
Les champs disponibles sont:
- Date de l'opération (au format AAAA-MM-JJ) : 1-10 champs
- Category : 14-25
- Label : 27-78
- Montant : 80-89
"""
# Traitement par lignes des données
for line in StringIO.StringIO(data):
# Date de l'opération
try:
date = datetime.datetime.strptime(line[1:11], "%Y-%m-%d").date()
except:
continue
# Montant de l'opération
expense = float(line[80:90])
# Description de l'opération et catégorisation
description = line[27:79]
# Modifications automatiques de la description et de la subcategory
description = change_description(description)
subcategory = categories.utils.autoset_category(description)
# halve or not
halve = halve_or_not(bank, description)
if halve is True:
expense = expense/2
account = Account( date = date,
description = description,
expense = expense,
category = subcategory,
bank = bank,
check = False,
halve = halve )
account.save()
示例15: register
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import save [as 别名]
def register(req):
errors = {}
if req.method == 'POST':
d = req.POST
un = d['username']
pi = d['pin']
p1 = d['password1']
p2 = d['password2']
valid = True
if User.objects.filter(username=un).count() > 0:
valid = False
errors['username'] = 'Must be unique.'
if len(pi) < 4 or len(pi) > 6:
valid = False
errors['pin'] = 'Must be between 4 and 6 characters.'
if p1 != p2:
valid = False
m = 'Passwords must match.'
errors['password1'] = m
errors['password2'] = m
if valid:
new = User.objects.create_user(un,"%[email protected]%s.io"%(un,un),p1)
new.save()
acc = Account(user=new,pin=pi)
acc.save()
user = authenticate(username=un, password=p1)
if user != None:
_login(req,user)
return HttpResponseRedirect('/account/')
else:
return HttpResponseRedirect('/')
return render(req, 'account/register.html', {
'errors': errors
})