本文整理汇总了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'))
示例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)
示例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)
示例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)
示例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", "/"))
示例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)
示例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("/")
示例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
示例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})