本文整理汇总了Python中account.models.Account类的典型用法代码示例。如果您正苦于以下问题:Python Account类的具体用法?Python Account怎么用?Python Account使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Account类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')
if not setting('SOCIAL_AUTH_CREATE_USERS', True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details)
return None
email = details.get('email')
request = kwargs["request"]
user = User.objects.create_user(username=username, email=email)
Account.create(request=request, user=user)
EmailAddress.objects.add_email(user, user.email, primary=True)
return {
'user': user,
'is_new': True
}
示例2: account
def account(request):
# Get an account object
account = request.account
if not account:
account = Account(user=request.user)
account.put()
# Setup the form
initial = {
"photo_backend": account.photo_backend,
"site_title": account.site_title,
"site_header": account.site_header,
"thumb_size": account.thumb_size,
"thumb_cropped": account.thumb_cropped,
"full_size": account.full_size,
"homepage_size": account.homepage_size,
"homepage_album": account.homepage_album,
"featured_albums": account.featured_albums,
"service_username": account.service_username,
"merchant_id": account.merchant_id,
"analytics_id": account.analytics_id,
}
backend = account.backend
try:
albums = backend.get_all_albums()
except Exception, e:
# raise e
albums = []
示例3: forwards
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: create
def create(request):
if request.method == 'POST':
# save new evento
title = request.POST['title']
description = request.POST['description']
date_start = request.POST['date_start']
date_end = request.POST['date_end']
lat = request.POST['lat']
lng = request.POST['lng']
#image = request.FILES['image']
event = Event(title=title)
event.last_update = datetime.datetime.now()
event.description = description
event.date_start = datetime.datetime.strptime(date_start, '%d/%m/%Y %H:%M')
if not date_end:
event.date_end = None
else:
event.date_end = datetime.datetime.strptime(date_end, '%d/%m/%Y %H:%M')
event.location = [float(lat),float(lng)]
user_id = request.session.get('userid')
user = Account.objects(id=user_id)[0]
event.user = user
event.user_going = [user]
#im = Image.open(image)
#event.image.put(open(im))
event.save()
Account.objects(id=user_id).update_one(push__event_going=event)
return HttpResponseRedirect(reverse('event-list'))
return render_to_response('event/event_create.html',{
'request':request},
context_instance=RequestContext(request))
示例5: __create_new_account__
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
示例6: import_banquepopulaire
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()
示例7: delete
def delete(request, event_id):
user_id = request.session.get('userid')
user = Account.objects(id=user_id)[0]
event = get_document_or_404(Event, id=event_id, user=user)
Account.objects().update(pull__event_going=event)
Account.objects().update(pull__event_maybe=event)
event.delete()
return HttpResponseRedirect(reverse('event-list'))
示例8: get_account
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}
示例9: import_oney
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()
示例10: login_to_account
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'))
示例11: regist
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))
示例12: user_post_save
def user_post_save(sender, **kwargs):
"""
After User.save is called we check to see if it was a created user. If so,
we check if the User object wants account creation. If all passes we
create an Account object.
We only run on user creation to avoid having to check for existence on
each call to User.save.
"""
user, created = kwargs["instance"], kwargs["created"]
disabled = getattr(user, "_disable_account_creation", not settings.ACCOUNT_CREATE_ON_SAVE)
if created and not disabled:
from account.models import Account
Account.create(user=user)
示例13: tweets
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)
示例14: account
def account(request):
ctx = {
"account": Account.for_request(request),
"ACCOUNT_OPEN_SIGNUP": settings.ACCOUNT_OPEN_SIGNUP,
"ACCOUNT_CONTACT_EMAIL": settings.ACCOUNT_CONTACT_EMAIL,
}
return ctx
示例15: get_context_data
def get_context_data(self, **kwargs):
context = super(self.__class__, self).get_context_data(**kwargs)
account = Account.get_account(self.request)
prayerbook = account.prayerbook
context['account'] = account
context['pray_in_my_praybook'] = prayerbook.pray_added(super(self.__class__, self).get_object())
return context