本文整理汇总了Python中helios_auth.models.User.update_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python User.update_or_create方法的具体用法?Python User.update_or_create怎么用?Python User.update_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helios_auth.models.User
的用法示例。
在下文中一共展示了User.update_or_create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import update_or_create [as 别名]
def process(self):
self.processing_started_at = datetime.datetime.utcnow()
self.save()
election = self.election
last_alias_num = election.last_alias_num
num_voters = 0
new_voters = []
for voter in self.itervoters():
# does voter for this user already exist
existing_voter = Voter.get_by_election_and_voter_id(election, voter['voter_id'])
# create the voter
if not existing_voter:
num_voters += 1
user = None
if 'user_type' in voter.keys():
if 'email' in voter.keys():
user = User.update_or_create(voter['user_type'], voter['voter_id'], voter['name'], {'email': voter['email']})
else:
user = User.update_or_create(voter['user_type'], voter['voter_id'], voter['name'], {})
voter_uuid = str(uuid.uuid4())
if 'email' in voter.keys():
new_voter = Voter(uuid=voter_uuid, user=user, voter_name=voter['name'], voter_email=voter['email'], election=election)
else:
new_voter = Voter(uuid=voter_uuid, user=user, voter_name=voter['name'], election=election)
new_voter.voter_login_id = voter['voter_id']
if not user:
new_voter.generate_password()
new_voters.append(new_voter)
new_voter.save()
if election.use_voter_aliases:
voter_alias_integers = range(last_alias_num + 1, last_alias_num + 1 + num_voters)
random.shuffle(voter_alias_integers)
for i, new_voter in enumerate(new_voters):
new_voter.alias = 'V%s' % voter_alias_integers[i]
new_voter.save()
self.num_voters = num_voters
self.processing_finished_at = datetime.datetime.utcnow()
self.save()
return num_voters
示例2: load_eligible_voters
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import update_or_create [as 别名]
def load_eligible_voters(self):
"""
try to load voters by eligibility constraints
"""
if self.eligibility == None:
return
if self.openreg == False:
return
total_load = True
for eligibility_case in self.eligibility:
print eligibility_case
auth_system = eligibility_case['auth_system']
if not eligibility_case.has_key('constraint'):
total_load = False
else:
if hasattr(AUTH_SYSTEMS[auth_system], 'can_list_category_members'):
for constraint in eligibility_case['constraint']:
category_id = AUTH_SYSTEMS[auth_system].eligibility_category_id(constraint)
for u in AUTH_SYSTEMS[auth_system].list_category_members(category_id):
user = User.update_or_create(user_type = u['type'], user_id = u['id'], name = u['name'], info = u['info'], token = u['token'])
Voter.register_user_in_election(user, self)
else:
total_load = False
if total_load:
self.openreg = False
示例3: login_view
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import update_or_create [as 别名]
def login_view(request):
# imports are here because putting them in the header prevents
# initialization of the database
from helios_auth.view_utils import render_template
from helios_auth.views import after
from helios_auth.models import User
if request.method == "GET":
form = LoginForm()
else:
form = LoginForm(request.POST)
request.session['auth_system_name'] = 'dummy'
if request.POST.has_key('return_url'):
request.session['auth_return_url'] = request.POST.get('return_url')
if form.is_valid():
name = form.cleaned_data['username'].strip()
admin_p = form.cleaned_data['admin_p']
user_obj = User.update_or_create(user_type='dummy', user_id=name, name=name, info={})
if user_obj.admin_p != admin_p:
user_obj.admin_p = admin_p
user_obj.save()
request.session['dummy_user'] = name
return HttpResponseRedirect(reverse(after))
return render_template(request, 'dummy/login', {'form': form})
示例4: create_user
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import update_or_create [as 别名]
def create_user(username, password, name = None):
from helios_auth.models import User
user = User.get_by_type_and_id('password', username)
if user:
raise Exception('user exists')
info = {'password' : password, 'name': name}
user = User.update_or_create(user_type='password', user_id=username, info = info)
user.save()
示例5: create_user
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import update_or_create [as 别名]
def create_user(username, password, name = None):
from helios_auth.models import User
from django.db import models
try:
user = User.get_by_type_and_id('password', username)
raise Exception('user exists')
except User.DoesNotExist:
pass
info = {'password' : password, 'name': name}
user = User.update_or_create(user_type='password', user_id=username, info = info)
user.save()