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


Python User.one方法代码示例

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


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

示例1: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
    def post(self, username):
        user = User.one({'username': username})
        action = self.get_argument('action', 'follow')
        _ = self._
        
        OK = False
        if user:
            follower = self.current_user['username']
            dbaction = '$push' if action == 'follow' else '$pull'
            try:
                User.collection.update({'username': username}, {dbaction: {'followers': follower}})
                User.collection.update({'username': follower}, {dbaction:{'following': username}})
                msg = _('You are now following that user') if action == 'follow' \
                        else _('You are not following that user again.')
                OK = True
            except:
                msg = _('Error. Your admin has been notified. Please try again later.')

            if self.is_xhr():
                user = User.one({'username': username}) # reload user
                html = self.render_string('statics/follow-button', user=user)
                return self.json_response(msg, 'OK' if OK else 'ERROR',\
                            {'html': html, 'target':'#followButton'})
            else:
                self.set_flash(msg)
        self.redirect(self.get_argument('next'))
开发者ID:apit,项目名称:rinjani,代码行数:28,代码来源:profile.py

示例2: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
    def post(self):
        f = register_form()
        captcha_html = captcha.displayhtml(self.settings.CAPTCHA_PUBLIC_KEY, True)
        captcha_error = ''
        data = self.get_arguments()
        _ = self._
        if False and data.has_key('username'):
            existing_user = User.one({'username': data['username']})
            f.add_notnull_validator(not existing_user, "The username you wanted is already taken.")

        try:
            if f.validates(Storage(data)):
                #todo use async call 
                captcha_resp = captcha.submit(
                                    self.get_argument('recaptcha_challenge_field'),
                                    self.get_argument('recaptcha_response_field'),
                                    self.settings.CAPTCHA_PRIVATE_KEY,
                                    self.request.remote_ip
                                )
                if captcha_resp.is_valid:
                    new_user = User()
                    data['is_admin'] = False
                    data['password_hashed'] = unicode(hashlib.sha1(data['password']).hexdigest(), 'utf-8')
                    data['auth_provider'] = u'form'
                    new_user.save(data)
                    self.set_flash(_("You have been successfully registered. "))
                    self.redirect("/")
                    return
                captcha_error = captcha_resp.error_code
                raise Exception("Invalid captcha code") 
            raise InvalidFormDataError(_("Form still have errors."))
        except Exception, e:
            f.note = f.note if f.note else e
            self.render("register", f=f, captcha_html=captcha_html, captcha_error=captcha_error)
开发者ID:apit,项目名称:rinjani,代码行数:36,代码来源:auth.py

示例3: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
 def get(self, username, type):
     user = User.one({'username': username})
     if not user:
         raise tornado.web.HTTPError(404)
     ctype = type[:-1] # articles, pages, projects, posts
     ctype = getattr(CONTENT_TYPE, ctype.upper())
     spec = {'type': ctype, 'status':'published', 'author': DBRef(User.collection_name, user._id)}
     pagination = Pagination(self, Content, spec)
     self.render('profile/items', pagination=pagination, user=user, type=type)
开发者ID:apit,项目名称:rinjani,代码行数:11,代码来源:profile.py

示例4: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
 def get(self, username):
     user = User.one({'username': username})
     if user != self.current_user:
         self.set_flash(self._("You are not allowed to view that page"))
         self.redirect("/")
         return
     donations = [{}, {}]
     if not donations:
         raise tornado.web.HTTPError(404)
     self.render("profile/donations", user=user, donations=donations)
开发者ID:apit,项目名称:rinjani,代码行数:12,代码来源:donation.py

示例5: _on_auth

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
    def _on_auth(self, user):
        peduli_user =  User.one({'uid': user['uid'], 'auth_provider': user['auth_provider']})
        if not peduli_user:
            """ New user """
            self.set_secure_cookie("user", tornado.escape.json_encode(user))
            self.set_flash(self._("You have been succefully authenticated. In order to be member, you need complete form shown below."))
            self.redirect("/new-user")
            return

        self.set_secure_cookie("username", peduli_user['username'])
        self.redirect(self.get_argument("next", "/"))
开发者ID:apit,项目名称:rinjani,代码行数:13,代码来源:auth.py

示例6: user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
 def user(self, *args):
     user = User.one({'username': args[0]})
     if not user:
         raise tornado.web.HTTPError(404)
         return
     accounts = user.get_bank_accounts()
     accounts = BankAccount.listify(accounts) if accounts.count() else []
     user.formify()
     f = profile_form()
     f.fill(user)
     self.render("admin/user", user=user, accounts=accounts, f=f)
     
开发者ID:apit,项目名称:rinjani,代码行数:13,代码来源:admin.py

示例7: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
    def post(self):
        username = self.get_argument('username', None)
        password = self.get_argument('password', None)
        confirm_password = self.get_argument('confirm_password', None)

        first_name = self.get_argument('first_name', None)
        last_name = self.get_argument('last_name', None)

        messages = []

        if not username:
            messages.append("Username is empty")

        if not password:
            messages.append("Password is empty")

        if not first_name:
            messages.append("First name is empty")

        if not last_name:
            messages.append("Last name is empty")
  
        if password != confirm_password:
            messages.append("Passwords are not equal")

        if len(password) < 6:
            messages.append("Password length must be bigger than 6 chars")

        user = User.one({'username': username})

        if user:
            messages.append('Username must be unique. %s is already take' % username)

        if len(messages) != 0:
            self.render("register.html", error_messages=messages, username=username, first_name=first_name, last_name=last_name)
            return

        user = User()
        user.username = username
        user.first_name = first_name
        user.last_name = last_name
        user.set_password(password)

        user.save(validate=True)

        self.redirect("/")
开发者ID:fernandotakai,项目名称:questions,代码行数:48,代码来源:main.py

示例8: test_get_unanswered_questions

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
def test_get_unanswered_questions():
    user = User()
    user.username = u"test"
    user.set_password("test123")

    assert user.save()
    assert user._id

    q = Question()
    q.question = u"test"
    q.author = u"anon"
    q.user = user.username

    assert q.save(validate=True)
    assert q._id
     
    user_from_db = User.one({'username': 'test'})

    assert user_from_db.unanswered_questions().count() == 1
开发者ID:fernandotakai,项目名称:questions,代码行数:21,代码来源:user_tests.py

示例9: get_current_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import one [as 别名]
 def get_current_user(self):
     username = self.get_secure_cookie('username')
     if not username: return None
     return User.one({'username': username})
开发者ID:apit,项目名称:rinjani,代码行数:6,代码来源:main.py


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