当前位置: 首页>>代码示例>>Python>>正文


Python User.find_one方法代码示例

本文整理汇总了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))
开发者ID:Alpani,项目名称:osf.io,代码行数:28,代码来源:populate_conferences.py

示例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))
开发者ID:Kimberly-Yang,项目名称:osf.io,代码行数:27,代码来源:populate_conferences.py

示例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))
开发者ID:atelic,项目名称:osf.io,代码行数:47,代码来源:populate_conferences.py

示例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()
开发者ID:GageGaskins,项目名称:osf.io,代码行数:22,代码来源:dev_populate_conferences.py


注:本文中的framework.auth.core.User.find_one方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。