本文整理汇总了Python中auth.models.User.update_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python User.update_or_create方法的具体用法?Python User.update_or_create怎么用?Python User.update_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.update_or_create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import update_or_create [as 别名]
def process(self):
self.processing_started_at = datetime.datetime.utcnow()
self.save()
election = self.election
reader = unicode_csv_reader(open(self.voter_file.path, "rU"))
last_alias_num = election.last_alias_num
num_voters = 0
voter_uuids = []
for voter in reader:
# bad line
if len(voter) < 1:
continue
num_voters += 1
voter_id = voter[0]
name = voter_id
email = voter_id
if len(voter) > 1:
email = voter[1]
if len(voter) > 2:
name = voter[2]
# create the user
user = User.update_or_create(
user_type="password",
user_id=voter_id,
info={"password": heliosutils.random_string(10), "email": email, "name": name},
)
user.save()
# does voter for this user already exist
voter = Voter.get_by_election_and_user(election, user)
# create the voter
if not voter:
voter_uuid = str(uuid.uuid4())
voter = Voter(uuid=voter_uuid, voter_type="password", voter_id=voter_id, name=name, election=election)
voter_uuids.append(voter_uuid)
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, voter_uuid in enumerate(voter_uuids):
voter = Voter.get_by_election_and_uuid(election, voter_uuid)
voter.alias = "V%s" % voter_alias_integers[i]
voter.save()
self.num_voters = num_voters
self.processing_finished_at = datetime.datetime.utcnow()
self.save()
return num_voters
示例2: create_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import update_or_create [as 别名]
def create_user(username, password, name = None):
from 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()
示例3: process
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import update_or_create [as 别名]
def process(self):
self.processing_started_at = datetime.datetime.utcnow()
self.save()
election = self.election
reader = unicode_csv_reader(self.voter_file)
num_voters_before = election.num_voters
num_voters = 0
voter_uuids = []
for voter in reader:
# bad line
if len(voter) < 1:
continue
num_voters += 1
voter_id = voter[0]
name = voter_id
email = voter_id
if len(voter) > 1:
email = voter[1]
if len(voter) > 2:
name = voter[2]
# create the user
user = User.update_or_create(user_type='password', user_id=voter_id, info = {'password': heliosutils.random_string(10), 'email': email, 'name': name})
user.save()
# does voter for this user already exist
voter = Voter.get_by_election_and_user(election, user)
# create the voter
if not voter:
voter_uuid = str(uuid.uuid1())
voter = Voter(uuid= voter_uuid, voter_type = 'password', voter_id = voter_id, name = name, election = election)
voter_uuids.append(voter_uuid)
voter.save()
if election.use_voter_aliases:
voter_alias_integers = range(num_voters_before+1, num_voters_before+1+num_voters)
random.shuffle(voter_alias_integers)
for i, voter_uuid in enumerate(voter_uuids):
voter = Voter.get_by_election_and_uuid(election, voter_uuid)
voter.alias = 'V%s' % voter_alias_integers[i]
voter.save()
self.num_voters = num_voters
self.processing_finished_at = datetime.datetime.utcnow()
self.save()
return num_voters