本文整理汇总了Python中framework.auth.core.User.find_one方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_one方法的具体用法?Python User.find_one怎么用?Python User.find_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类framework.auth.core.User
的用法示例。
在下文中一共展示了User.find_one方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate_conferences
# 需要导入模块: from framework.auth.core import User [as 别名]
# 或者: from framework.auth.core.User import find_one [as 别名]
def populate_conferences():
for meeting, attrs in MEETING_DATA.iteritems():
meeting = meeting.strip()
admin_emails = attrs.pop('admins', [])
admin_objs = []
for email in admin_emails:
try:
user = User.find_one(Q('username', 'iexact', email))
admin_objs.append(user)
except ModularOdmException:
raise RuntimeError('Username {0!r} is not registered.'.format(email))
conf = Conference(
endpoint=meeting, admins=admin_objs, **attrs
)
try:
conf.save()
except ModularOdmException:
conf = Conference.find_one(Q('endpoint', 'eq', meeting))
for key, value in attrs.items():
setattr(conf, key, value)
conf.admins = admin_objs
changed_fields = conf.save()
if changed_fields:
print('Updated {}: {}'.format(meeting, changed_fields))
else:
print('Added new Conference: {}'.format(meeting))
示例2: populate_conferences
# 需要导入模块: from framework.auth.core import User [as 别名]
# 或者: from framework.auth.core.User import find_one [as 别名]
def populate_conferences():
for meeting, attrs in MEETING_DATA.iteritems():
meeting = meeting.strip()
admin_emails = attrs.pop("admins")
admin_objs = []
for email in admin_emails:
try:
user = User.find_one(Q("username", "iexact", email))
admin_objs.append(user)
except ModularOdmException:
raise RuntimeError("Username {0!r} is not registered.".format(email))
conf = Conference(endpoint=meeting, admins=admin_objs, **attrs)
try:
conf.save()
except ModularOdmException:
print("{0} Conference already exists. Updating existing record...".format(meeting))
conf = Conference.find_one(Q("endpoint", "eq", meeting))
for key, value in attrs.items():
setattr(conf, key, value)
conf.admins = admin_objs
changed_fields = conf.save()
if changed_fields:
print("Changed: {}".format(changed_fields))
else:
print("Added new Conference: {}".format(meeting))
示例3: populate_conferences
# 需要导入模块: from framework.auth.core import User [as 别名]
# 或者: from framework.auth.core.User import find_one [as 别名]
def populate_conferences(dev=False):
if dev:
Conference.remove()
date_format = '%b %d %Y'
for meeting, attrs in MEETING_DATA.iteritems():
meeting = meeting.strip()
admin_emails = attrs.pop('admins', [])
admin_objs = []
if not dev:
for email in admin_emails:
try:
user = User.find_one(Q('username', 'iexact', email))
admin_objs.append(user)
except ModularOdmException:
raise RuntimeError('Username {0!r} is not registered.'.format(email))
# Convert string into datetime object
try:
attrs['end_date'] = datetime.strptime(attrs.get('end_date'), date_format)
attrs['start_date'] = datetime.strptime(attrs.get('start_date'), date_format)
except TypeError:
print '** Meeting {} does not have a start or end date. **'.format(meeting)
custom_fields = attrs.pop('field_names', {})
conf = Conference(
endpoint=meeting, admins=admin_objs, **attrs
)
conf.field_names.update(custom_fields)
try:
conf.save()
except ModularOdmException:
conf = Conference.find_one(Q('endpoint', 'eq', meeting))
for key, value in attrs.items():
if isinstance(value, dict):
current = getattr(conf, key)
current.update(value)
setattr(conf, key, current)
else:
setattr(conf, key, value)
conf.admins = admin_objs
changed_fields = conf.save()
if changed_fields:
print('Updated {}: {}'.format(meeting, changed_fields))
else:
print('Added new Conference: {}'.format(meeting))
示例4: populate_conferences
# 需要导入模块: from framework.auth.core import User [as 别名]
# 或者: from framework.auth.core.User import find_one [as 别名]
def populate_conferences(email):
for meeting, attrs in MEETING_DATA.iteritems():
admin_objs = []
try:
user = User.find_one(Q('username', 'iexact', email))
admin_objs.append(user)
except ModularOdmException:
raise RuntimeError('Username {0!r} is not registered.'.format(email))
conf = Conference(
endpoint=meeting, admins=admin_objs, **attrs
)
try:
conf.save()
except ModularOdmException:
print('{0} Conference already exists. Updating existing record...'.format(meeting))
conf = Conference.find_one(Q('endpoint', 'eq', meeting))
for key, value in attrs.items():
setattr(conf, key, value)
conf.admins = admin_objs
conf.save()