本文整理汇总了Python中models.Session.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Session.get_by_id方法的具体用法?Python Session.get_by_id怎么用?Python Session.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Session
的用法示例。
在下文中一共展示了Session.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_token
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def login_token(self):
if self.s_id:
sess = Session.get_by_id(self.s_id)
if sess:
return sess.login_token
return None
示例2: _cacheFeaturedSpeaker
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def _cacheFeaturedSpeaker(websafeConferenceKey, sessionId):
"""Search for featured speaker.
"""
# obtainthe conference
c= ndb.Key(urlsafe=websafeConferenceKey)
if c.kind() != 'Conference':
# raising an exception
logging.error("invalid key here %s" %websafeConferenceKey)
return
# verify existence of created session
session = Session.get_by_id(int(sessionId), parent=conf)
if not session:
logging.error("session id not found")
return
# check the speakers in the session
for speaker in session.speaker:
logging.info(speaker.urlsafe())
sessions = Session.query(Session.speaker == speaker).fetch(projection=[Session.name])
logging.info(len(sessions))
if len(sessions) > 1:
speaker = speaker.get()
feature =(speaker.name, ', '.join(sess.name for sess in sessions))
# memcaching
memcache.set(MEMCACHE_FEATUREDSPEAKER_KEY, feature)
return feature
示例3: owner
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def owner(self):
if self.isActive:
if self.s_id:
s = Session.get_by_id(self.s_id)
if s:
return s.owner.get()
return None
示例4: data
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def data(self):
if self.s_id:
s = Session.get_by_id(self.s_id)
if s:
user = s.owner.get()
d = user.toObject(expanded=True)
d["expires"] = time.mktime(self.session.expires.timetuple())
return None
示例5: isActive
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def isActive(self):
if self.s_id:
sess = Session.get_by_id(self.s_id)
if sess:
if sess.status:
return True
return False
示例6: getSession
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def getSession(handler):
try:
session = Session.get_by_id(int(handler.request.get('id')))
if not session:
raise GameError('This session does not exist.')
return session
except ValueError:
raise GameError('Bad session identifier.')
示例7: logout
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def logout(self):
if self._s_id:
s = Session.get_by_id(self._s_id)
if s:
s.status = False
s.put()
from gaesessions import get_current_session
session = get_current_session()
session.terminate()
logging.info("logout")
示例8: _updateSessionObject
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def _updateSessionObject(self, request):
"""Update the session object."""
user_id = get_current_user_id()
# get the conference object
conf = ndb.Key(urlsafe=request.websafeConferenceKey).get()
if conf.kind() != 'Conference':
raise endpoints.BadRequestException(
'Provided conference key is invalid')
# check that user is organizer
if user_id != conf.organizerUserId:
raise endpoints.ForbiddenException(
'Only the owner can update the conference.')
# get the existing session
sess = Session.get_by_id(int(request.sessionId), parent=conf)
# check that session exists
if not sess:
raise endpoints.NotFoundException(
'No session found with id: %s' % request.sessionId)
# Not getting all the fields, so don't create a new object; just
# copy relevant fields from SessionFormIn to Session object
for field in request.all_fields():
data = getattr(request, field.name)
# only copy fields where we get data
if data not in (None, []):
# special handling for dates (convert string to Date)
if field.name in ('date', 'startTime'):
data = datetime.strptime(data, "%Y-%m-%d").date()
# special handling for speaker: convert to key
if field.name == 'speaker':
data2 = []
for speakerform in data:
speaker_key = ndb.Key(urlsafe=speakerform.websafeKey)
if speaker_key.kind() != 'Speaker':
raise endpoints.BadRequestException('Expected Speaker key')
# check if the speaker exists
if speaker_key.get() is None:
raise endpoints.BadRequestException('Could not find speaker')
# set speaker key
data2.append(speaker_key)
# replace speaker forms with speaker key list
data = data2
# special handling for session type
if field.name == 'typeOfSession':
data = getattr(SessionType, data)
# write to Conference object
setattr(conf, field.name, data)
sess.put()
return self._copySessionToForm(sess)
示例9: end_session
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def end_session(session_id):
"""
Ends a session, sets its endtime to database.
Ends file scanner.
:param session: Current session.
:type session: :py:class:`models.Session`
"""
if session_id < 1:
return
session = Session.get_by_id(session_id)
session.endtime = func.now()
session.update()
示例10: getSession
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def getSession(self, request):
"""Return requested session (by websafeConferenceKey and
sessionId)."""
# get the conference key
conf = ndb.Key(urlsafe=request.websafeConferenceKey)
if conf.kind() != 'Conference':
raise endpoints.BadRequestException(
'Provided conference key is invalid')
# get Session object from request; bail if not found
# dumpclean(request)
sess = Session.get_by_id(int(request.sessionId), parent=conf)
if not sess:
raise endpoints.NotFoundException(
'No session found with id %s' % request.sessionId)
# return SessionFormOut
return self._copySessionToForm(sess)
示例11: start_new_session
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def start_new_session(project_id, old_session_id=None):
"""
Creates a session to the database and return a session object.
:param project_id: Project id from database.
:type project_id: Integer
:param old_session_id: A session id of a session which will be continued.
:type old_session_id: Integer
"""
project = Project.get_by_id(project_id)
try:
old_session = Session.get_by_id(old_session_id)
except NoResultFound:
old_session = None
return Session(project, old_session)
示例12: _sessionWishlist
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def _sessionWishlist(self, request, reg=True):
"""Add a session to the wishlist."""
retval = None
prof = self._getProfileFromUser() # get user Profile
# get the conference key
conf = ndb.Key(urlsafe=request.websafeConferenceKey)
if conf.kind() != 'Conference':
raise endpoints.BadRequestException(
'Provided conference key is invalid')
# check if session exists given sessionId
session = Session.get_by_id(int(request.sessionId), parent=conf)
# get session; check that it exists
if not session:
raise endpoints.NotFoundException(
'No session found with id %s' % request.sessionId)
# get web safe session key
wssk = session.key.urlsafe()
# add to wishlist
if reg:
# check if user already has session otherwise add
if wssk in prof.sessionKeysOnWishlist:
raise ConflictException(
"You have already this session in your wishlist")
# add to wishist
prof.sessionKeysOnWishlist.append(wssk)
retval = True
# remove from wishlist
else:
# check if user has entry in wishlist
if wssk in prof.sessionKeysOnWishlist:
# remove session from wishlist
prof.sessionKeysOnWishlist.remove(wssk)
retval = True
else:
retval = False
# write things back to the datastore & return
prof.put()
return BooleanMessage(data=retval)
示例13: _cacheFeaturedSpeaker
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def _cacheFeaturedSpeaker(websafeConferenceKey, sessionId):
"""Search for featured speaker & assign to memcache; used by
main.SearchFeaturedSpeakers
"""
logging.info("_cacheFeaturedSpeaker: Checking for featured speakers in %s %s\n"
% (websafeConferenceKey, sessionId))
# get the conference
conf = ndb.Key(urlsafe=websafeConferenceKey)
if conf.kind() != 'Conference':
# raising an exception causes another attempt at calling the task
logging.error("_cacheFeaturedSpeaker: provided conference key %s invalid"
% websafeConferenceKey)
return
# get the session; check if it exists
session = Session.get_by_id(int(sessionId), parent=conf)
if not session:
# raise endpoints.NotFoundException('Provided session not found')
# raising an exception causes another attempt at calling the task
logging.error("_cacheFeaturedSpeaker: provided session id not found %d"
% sessionId)
return
# Now check the speakers in the session
for speaker in session.speaker:
logging.info("_cacheFeaturedSpeaker: speaker %s in check"
% speaker.urlsafe())
sessions = Session.query(Session.speaker == speaker) \
.fetch(projection=[Session.name])
logging.info("_cacheFeaturedSpeaker: %s sessions found" % len(sessions))
if len(sessions) > 1:
speaker = speaker.get()
# good - let's feature the speaker!
feature = FEATUREDSPEAKER_TPL % (
speaker.name,
', '.join(sess.name for sess in sessions))
# set into memcache
memcache.set(MEMCACHE_FEATUREDSPEAKER_KEY, feature)
# we are done and return already
logging.info("_cacheFeaturedSpeaker: we found something\n%s" % feature)
return feature
示例14: session
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def session(self):
return Session.get_by_id(self.s_id)
示例15: get_current_user
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import get_by_id [as 别名]
def get_current_user(self):
if self.session.has_key("token"):
session = Session.get_by_id(self.session["token"])
return session.user.get()
else:
return None