本文整理汇总了Python中database.User.get方法的典型用法代码示例。如果您正苦于以下问题:Python User.get方法的具体用法?Python User.get怎么用?Python User.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adminActionRoute
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def adminActionRoute(action=None, id=None):
if not loggedIn():
return flashy('/', 'You must be logged in to do that!', 'error')
if not action:
return flashy('/', 'There was an error processing your request!', 'error')
if not request.form.get('isact') and not id or id and not id.isdigit(): #Best ifstatement EVAR
return flashy('/', 'Invalid or maliformed request!', 'error')
if action == 'delete_proj':
q = [i for i in Project.select().where(Project.id == int(id))]
if not len(q):
return flashy('/', 'Invalid Project ID (%s)' % id, 'error')
q[0].delete_instance()
return flashy('/', 'Deleted Project #%s!' % id, 'success')
elif action == 'add_proj':
q = [i for i in Project.select().where(Project.name == request.form.get('pname'))]
if len(q): return flashy('/admin', 'There is already a project with the name "%s"' % request.form.get('pname'), 'error')
p = Project(
name=request.form.get('pname'),
author=User.get(User.id==session.get('uid')),
desc=request.form.get('pdesc'),
url=request.form.get('purl'),
repo_type=request.form.get('repotype'),
repo_name=request.form.get('pgitname').lower(),
repo_url=request.form.get('giturl'))
p.save()
return flashy('/admin', 'Added project "%s" (ID #%s)' % (p.name, p.id), 'success')
示例2: get_user_exercises
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def get_user_exercises(user_id, ex_id):
if Token.invalid(user_id, request.path, request.json):
abort(403)
user = User.get(user_id)
if user == None:
abort(404)
exercise = user.getExercise(ex_id)
if exercise == None:
abort(404)
return jsonify(exercise)
示例3: get_token_by_id
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def get_token_by_id(user_id):
try :
password = request.json['password']
except Exception:
abort(400)
user = User.get(user_id)
if user == None:
abort(404)
if user.checkPassword(password):
token = Token.add(user.id)
return jsonify({'user': user.id, 'token': token.token}), 201
else:
abort(403)
示例4: star_post
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def star_post(id):
if not g.db.doc_exist(id):
abort(404)
post = Post.get(id)
uid = session.get('uid')
user = User.get(uid)
if uid not in post.stars:
post.stars.add(uid)
user.starred.add(post._id)
else:
post.stars.remove(uid)
user.starred.remove(post._id)
post.save()
user.save()
return 'OK', 200, {'Content-Type': 'text/plain'}
示例5: user_list_exercises
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def user_list_exercises(user_id):
begin = 0
length = 25
try:
if request.json != None:
begin = int(request.json.get('begin', 0))
length = int(request.json.get('length', 25))
except:
abort(403)
try :
user = User.get(user_id)
if user == None:
abort(404)
except Exception:
abort(404);
exerciseList = user.getExerciseList(begin, length);
if exerciseList == None:
abort(400)
return jsonify({
'user': user_id,
'exercises': exerciseList,
'begin': begin,
'length': length})
示例6: get_user
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def get_user(user_id):
""" Retrieves user <user_id> data """
user = User.get(user_id)
if user == None:
abort(404)
return jsonify({'user': user.output()})
示例7: show_posts_starred
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def show_posts_starred():
# I think it's not a good idea to use such implementation.
user = User.get(session.get('uid'))
posts = [elem for elem in Post.view('posts/by_date') if elem._id in user.starred]
return render_template('posts.html', posts = posts)
示例8: get
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get [as 别名]
def get(self, *args, **kwargs):
domains_list = DomainLogs.select().where(DomainLogs.user_id == self.current_user).order_by(
DomainLogs.created_time.desc())
user = User.get(User.id == self.current_user)
self.render("list.html", domains_list=domains_list, user=user)