本文整理汇总了Python中models.profile.Profile.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.get_by_id方法的具体用法?Python Profile.get_by_id怎么用?Python Profile.get_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.profile.Profile
的用法示例。
在下文中一共展示了Profile.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from models.profile import Profile [as 别名]
# 或者: from models.profile.Profile import get_by_id [as 别名]
def delete(self, id):
editor = Profile.get_by_id(int(id))
if not editor or not editor.is_editor:
self.session.add_flash(messages.EDITOR_NOT_FOUND, level='error')
return self.redirect_to('editors.list')
editor.delete()
self.session.add_flash(messages.EDITOR_DELETE_SUCCESS)
return self.redirect_to('editors.list')
示例2: update
# 需要导入模块: from models.profile import Profile [as 别名]
# 或者: from models.profile.Profile import get_by_id [as 别名]
def update(self, id):
editor = Profile.get_by_id(int(id))
if not editor or not editor.is_editor:
self.session.add_flash(messages.EDITOR_NOT_FOUND, level='error')
self.redirect_to('editors.list')
form = ProfileUpdateForm(self.request.POST, obj=editor)
form.user_id = editor.key().id()
if self.request.method == 'GET':
names = editor.name.split(' ')
form.first_name.data = names[0]
form.last_name.data = names[1]
form.profile_id = editor.key().id()
if self.request.method == 'POST' and form.validate():
# Access to the user model is only needed in this section.
user = editor.get_auth_user()
editor.name = ' '.join([form.first_name.data, form.last_name.data])
if form.email.data != editor.email:
user.auth_ids.remove(editor.email)
user.auth_ids.append(form.email.data)
editor.email = form.email.data
if form.password.data:
user.password = security.generate_password_hash(form.password.data,
length=12)
editor.put()
user.put()
# Force reload of profile object
Profile.get(editor.key())
self.session.add_flash(messages.EDITOR_UPDATE_SUCCESS)
return self.redirect_to('editors.list')
return self.render_to_response('editors/form.haml', {'form': form})