本文整理汇总了Python中models.Session.from_form方法的典型用法代码示例。如果您正苦于以下问题:Python Session.from_form方法的具体用法?Python Session.from_form怎么用?Python Session.from_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Session
的用法示例。
在下文中一共展示了Session.from_form方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import from_form [as 别名]
def _update(self, old_session, session_form, speakers=None):
"""
Update an existing Session using the new SessionForm message
:param old_session: old Session instance
:param session_form: SessionForm with updates
:param speakers:
:return: updated Session
"""
if not isinstance(old_session, Session):
raise TypeError('expecting %s but got %s' % (Session, old_session))
new_session = Session.from_form(session_form)
# deal with decrementing the old ones that aren't on the session anymore
new_keys = [speaker.key for speaker in speakers]
for old_key in old_session.speakerKeys:
if old_key not in new_keys:
# decrement old speaker's sesssion count. if 0, just delete.
old_speaker = old_key.get()
old_speaker.numSessions -= 1
if old_speaker.numSessions == 0:
old_key.delete()
else:
old_speaker.put()
# put speaker changes for new ones and append their keys
for speaker in speakers:
new_session.speakerKeys.append(speaker.put())
# since session key's use the session name, need to delete the old one
old_session.key.delete()
new_session.put()
return new_session
示例2: __prep_new_session
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import from_form [as 别名]
def __prep_new_session(session_form):
"""
Prepare a new Session instance, validating Conference and User details
:param session_form:
:return: Session ready for processing of speakers
"""
if not isinstance(session_form, SessionForm):
raise TypeError('expected SessionForm')
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = get_user_id(user)
if not session_form.name:
raise endpoints.BadRequestException("Session 'name' field required")
# fetch the key of the ancestor conference
conf_key = ndb.Key(urlsafe=session_form.websafeConfKey)
conf = conf_key.get()
if not conf:
raise endpoints.NotFoundException(
'No conference found with key: %s' % session_form.websafeConfKey
)
# check that user is conference owner
if user_id != conf.organizerUserId:
raise endpoints.ForbiddenException(
'Only the conference owner can create sessions.')
# create Session and set up the parent key
return Session.from_form(session_form)