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


Python User.by_name方法代码示例

本文整理汇总了Python中user.User.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_name方法的具体用法?Python User.by_name怎么用?Python User.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


在下文中一共展示了User.by_name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: give_all_packages_default_user_roles

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
def give_all_packages_default_user_roles():
    # if this command gives an exception, you probably
    # forgot to do 'paster db init'
    pkgs = Session.query(Package).all()

    for pkg in pkgs:
        print pkg
        # weird - should already be in session but complains w/o this
        Session.add(pkg)
        if len(pkg.roles) > 0:
            print 'Skipping (already has roles): %s' % pkg.name
            continue
        # work out the authors and make them admins
        admins = []
        revs = pkg.all_revisions
        for rev in revs:
            if rev.revision.author:
                # rev author is not Unicode!!
                user = User.by_name(unicode(rev.revision.author))
                if user:
                    admins.append(user)
        # remove duplicates
        admins = list(set(admins))
        # gives default permissions
        print 'Creating default user for for %s with admins %s' % (pkg.name, admins)
        setup_default_user_roles(pkg, admins)
开发者ID:pombredanne,项目名称:ckan,代码行数:28,代码来源:authz.py

示例2: done

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
 def done(self):
     u = User.by_name(self.username)
     if u:
         msg = 'This username already exists'
         self.render("register.html", error_username=msg)
     else:
         u = User.register(self.username, self.password, self.email)
         u.put()
         self.login(u)
         self.redirect('/')
开发者ID:manishbisht,项目名称:Udacity,代码行数:12,代码来源:main.py

示例3: init_const_data

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
 def init_const_data(self):
     """Creates 'constant' objects that should always be there in
     the database. If they are already there, this method does nothing."""
     for username in (PSEUDO_USER__LOGGED_IN, PSEUDO_USER__VISITOR):
         if not User.by_name(username):
             user = User(name=username)
             meta.Session.add(user)
     meta.Session.flush()  # so that these objects can be used
     # straight away
     init_authz_const_data()
开发者ID:robert-chiniquy,项目名称:ckan,代码行数:12,代码来源:__init__.py

示例4: setup_user_roles

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
def setup_user_roles(domain_object, visitor_roles, logged_in_roles, admins=[]):
    '''NB: leaves caller to commit change'''
    assert type(admins) == type([])
    admin_roles = [Role.ADMIN]
    visitor = User.by_name(PSEUDO_USER__VISITOR)
    assert visitor
    for role in visitor_roles:
        add_user_to_role(visitor, role, domain_object)
    logged_in = User.by_name(PSEUDO_USER__LOGGED_IN)
    assert logged_in
    for role in logged_in_roles:
        add_user_to_role(logged_in, role, domain_object)
    for admin in admins:
        # not sure if admin would reasonably by None
        if admin is not None:
            assert isinstance(admin, User), admin
            if admin.name in (PSEUDO_USER__LOGGED_IN, PSEUDO_USER__VISITOR):
                raise NotRealUserException('Invalid user for domain object admin %r' % admin.name)
            for role in admin_roles:
                add_user_to_role(admin, role, domain_object)
开发者ID:pombredanne,项目名称:ckan,代码行数:22,代码来源:authz.py

示例5: done

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
    def done(self):
        u = User.by_name(self.username)
        if u:
            msg = 'That user already exists.'
            self.render('register-form.html', error_username = msg)
        else:
            u = User.register(self.username, self.password, self.email)
            u.put()

            self.login(u)
            self.redirect('/blog')
开发者ID:YouYue123,项目名称:Fullstack-Udacity,代码行数:13,代码来源:main.py

示例6: done

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
    def done(self):
        #make sure the user doesn't already exist
        u = User.by_name(self.username)
        if u:
            msg = u'Tento uživatel už existuje.'
            self.render('signup-form.html', error_username = msg)
        else:
            u = User.register(self.username, self.password, self.email)
            u.put()

            self.login(u)
            self.redirect('/vitejte')
开发者ID:werterber,项目名称:blog,代码行数:14,代码来源:main.py

示例7: done

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import by_name [as 别名]
    def done(self):

        # Make sure the user doesn't already exist

        u = User.by_name(self.username)
        if u:
            msg = 'That user already exists.'
            self.render('signup.html', error_username=msg)
        else:
            u = User.register(self.username, self.password, self.email)
            u.put()

            self.login(u)
            self.redirect('/')
开发者ID:Ahmed-elsayed-mahmoud,项目名称:Project-3_Multi-User-Blog,代码行数:16,代码来源:blog.py


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