本文整理汇总了Python中db.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
if not self.request.headers.get("Cookie"):
self.render("require_enable_cookie.html")
return
name = self.get_argument("name",'')
password = self.get_argument("password",'')
password = hashlib.md5(password).hexdigest()
email = self.get_argument("email",'')
domain = self.get_argument("domain",'')
try:
user = User.get(user_email = email)
except:
u = User.create(user_name = name,
user_pass = password,
user_email = email,
user_domain = domain,
)
user = {'user_id':u.id,
'user_name':u.user_name,
'user_email':u.user_email,
'user_domain':u.user_domain}
self.set_secure_cookie("user", tornado.escape.json_encode(user))
self.redirect(self.get_argument("next", "/"))
else:
self.write('用户已经存在,请重新注册或直接登录')
示例2: get_enterprise_detail
def get_enterprise_detail(user_id, html):
user = User(user_id)
user.follows_num = enterprise.get_friends(html)
user.fans_num = enterprise.get_fans(html)
user.wb_num = enterprise.get_status(html)
user.description = enterprise.get_description(html).encode('gbk', 'ignore').decode('gbk')
return user
示例3: post
def post(self):
name = self.get_argument("name", None)
city = self.get_argument("city", None)
say = self.get_argument("say", None)
User.update(
user_name=name,
user_city=city,
user_say=say).where(id=self.current_user["user_id"]).execute()
self.redirect("/setting")
示例4: post
def post(self):
id = self.get_argument("id", None)
title = self.get_argument("title")
tag = self.get_argument("tag", None)
markdown = self.get_argument("markdown")
sharetype = self.get_argument("type")
if id:
try:
share = Share.get(id=id)
except:
self.redirect("/404")
share = Share.update(title=title,
markdown=markdown,
sharetype=sharetype,
updated=datetime.datetime.now()).where(
id=id).execute()
else:
share = Share.create(title=title,
markdown=markdown,
sharetype=sharetype,
user_id=self.current_user["user_id"], )
user = User.update(
user_leaf=F('user_leaf') + 10).where(
id=self.current_user["user_id"]).execute()
id = str(share.id)
self.redirect("/share/" + str(id))
示例5: get
def get(self, name):
try:
user = User.get(user_domain = name)
except:
self.redirect("/404")
user.user_say = markdown.markdown(user.user_say)
likenum = Like.select().where(user_id=user.id).count()
user.gravatar = get_avatar(user.user_email,100)
self.render("userhome.html", user = user,likenum = likenum)
示例6: get
def get(self, node):
page = self.get_argument("page", "1")
realpage = int(page)
shares = Share.select().where(
sharetype=node).order_by('id').paginate(realpage, 10)
sharesum = shares.count()
pagesum = (sharesum + 9) / 10
for share in shares:
user = User.get(id=share.user_id)
share.name = user.user_name
share.domain = user.user_domain
share.markdown = filter_tags(share.markdown)[:100]
share.gravatar = get_avatar(user.user_email, 16)
members = User.select().order_by('id').paginate(1, 20)
for member in members:
user = User.get(id=member.id)
member.gravatar = get_avatar(user.user_email, 35)
self.render(
"node.html", shares=shares, members=members,
pagesum=pagesum, page=page, node=node)
示例7: get
def get(self):
page = self.get_argument("page", "1")
realpage = int(page)
shares = Share.select().order_by(('id', 'desc')).paginate(realpage, 10)
sharesum = shares.count()
pagesum = (sharesum + 9) / 10
for share in shares:
user = User.get(id=share.user_id)
share.name = user.user_name
share.domain = user.user_domain
share.markdown = filter_tags(
markdown.markdown(share.markdown))[:100]
share.gravatar = get_avatar(user.user_email, 16)
members = User.select().order_by(('id', 'desc')).paginate(1, 20)
for member in members:
user = User.get(id=member.id)
member.gravatar = get_avatar(user.user_email, 25)
Share.select().order_by(
('status', 'desc'), ('id', 'desc')).limit(5)
node = 'home'
node_about = options.node_about[node]
self.render(
"node.html", shares=shares, members=members,
pagesum=pagesum, page=page, node=node, node_about=node_about)
示例8: find
def find(id):
from db.models import DiscuzMember, User
from sqlalchemy.orm import joinedload
s = current_session()
try:
uid = int(id)
uid = uid if uid < 500000 else None
except ValueError:
uid = None
q = s.query(DiscuzMember).options(joinedload('ucmember'))
if uid:
dz_member = q.filter(DiscuzMember.uid == uid).first()
else:
dz_member = q.filter(DiscuzMember.email == id).first()
dz_member = dz_member or q.filter(DiscuzMember.username == id).first()
if not dz_member:
return None
uid = dz_member.uid
user = s.query(User).filter(User.id == uid).first()
if not user:
user = User()
s.add(user)
user.dz_member = dz_member
# sync
user.games = dz_member.member_count.games
user.drops = dz_member.member_count.drops
user.jiecao = dz_member.member_count.jiecao
return user
示例9: user_exist
def user_exist(login, password):
"""
Check if User exist in db. Raises AuthError exception if something goes wrong
:param login: string
:param password: string
:return: User object
:raise AuthError:
"""
try:
user = User.get(User.login == login)
except User.DoesNotExist:
raise AuthError(u"Пользователь с логином {} не найден в базе данных".format(login))
if create_hash(login, password) == user.password:
return user
else:
raise AuthError(u"Логин не соответствует паролю")
示例10: authenticate
def authenticate(cls, username, password):
from db.models import User
try:
uid = int(username)
except:
return None
user = cls.find(username)
if not user:
s = current_session()
user = User()
user.id = uid
user.username = str(username)
user.email = str(username)
user.credits = 998
user.games = 1
user.drops = 0
s.add(user)
s.flush()
return cls()._fill_account(user)
示例11: get_detail
def get_detail(html):
user = User()
cont = public.get_right(html)
if cont == '':
return None
soup = BeautifulSoup(cont, 'html.parser')
basic_modules = soup.find_all(attrs={'class': 'WB_cardwrap S_bg2'})
basic_info = soup.find_all(attrs={'class': 'li_1 clearfix'})
for each_module in basic_modules:
try:
basic_str = each_module.find(attrs={'class': 'main_title W_fb W_f14'}).get_text()
if '基本信息' in basic_str:
for each in basic_info:
each_str = each.get_text()
if '昵称:' in each_str:
user.name = each.find(attrs={'class': 'pt_detail'}).get_text()
elif '所在地:' in each_str:
user.location = each.find(attrs={'class': 'pt_detail'}).get_text()
elif '性别:' in each_str:
gender = each.find(attrs={'class': 'pt_detail'}).get_text()
if gender == '男':
user.gender = 1
elif gender == '女':
user.gender = 2
else:
user.gender = 0
elif '生日:' in each_str:
user.birthday = each.find(attrs={'class': 'pt_detail'}).get_text()
elif '简介:' in each_str:
description = each.find(attrs={'class': 'pt_detail'}).get_text()
user.description = description.encode('gbk', 'ignore').decode('gbk')
elif '注册时间:' in each_str:
user.register_time = each.find(attrs={'class': 'pt_detail'}).get_text().replace('\t', '').replace(
'\r\n', '')
if '标签信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
for each in basic_info:
if '标签:' in each.get_text():
user.tags = each.find(attrs={'class': 'pt_detail'}).get_text().replace('\t', '').replace(
'\n\n\n', '') .strip().replace('\r\n', ';')
if '教育信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
for each in basic_info:
if '大学:' in each.get_text():
user.education_info = each.find(attrs={'class': 'pt_detail'}).get_text().replace('\r\n', ',') \
.replace('\t', '').replace('\n', ';').lstrip(';').rstrip(';')
if '工作信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
jobs_info = []
for each in basic_info:
if '公司:' in each.get_text():
jobs = each.find_all(attrs={'class': 'pt_detail'})
for job in jobs:
jobs_info.append(job.get_text().replace('\r\n', '').replace('\t', '').replace('\n', ''))
user.work_info = ';'.join(jobs_info)
if '联系信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
contact_info = []
for each in basic_info:
if 'QQ:' in each.get_text():
contact_info.append(
'qq:' + each.find(attrs={'class': 'pt_detail'}).get_text().replace('\n', ''))
if '邮箱:' in each.get_text():
contact_info.append('email:' + each.find(attrs={'class': 'pt_detail'}).get_text())
if 'MSN:' in each.get_text():
contact_info.append('msn:' + each.find(attrs={'class': 'pt_detail'}).get_text())
user.contact_info = ';'.join(contact_info)
except Exception as why:
print('解析出错,具体原因为{why}'.format(why=why))
return user
示例12: addUser
def addUser(name, username):
user = User()
user.name = name
user.username = username
user.save()
return {'user_id': user.pk, 'success':True}