本文整理汇总了Python中models.Speaker.urlsafe方法的典型用法代码示例。如果您正苦于以下问题:Python Speaker.urlsafe方法的具体用法?Python Speaker.urlsafe怎么用?Python Speaker.urlsafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Speaker
的用法示例。
在下文中一共展示了Speaker.urlsafe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createSpeaker
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import urlsafe [as 别名]
def createSpeaker(self, request):
"""Create a new speaker object"""
if not request.email or not request.name or not request.surname:
raise endpoints.BadRequestException(
"Required field (name, surname and/or email) missing"
)
data = {field.name: getattr(request, field.name)
for field in request.all_fields()}
# set the created date/time stamp
data['created'] = datetime.now()
data['modified'] = data['created']
# store in Datastore
speakerKey = Speaker(**data).put()
speakerKeyForm = SpeakerKeyForm()
speakerKeyForm.key = speakerKey.urlsafe()
speakerKeyForm.email = request.email
return speakerKeyForm
示例2: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import urlsafe [as 别名]
def _createSpeakerObject(self, request):
"""
Creates a Speaker entity in datastore based on the information provided
by client.
Sends a confirmation email after adding the new Speaker
"""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException(
"Speaker 'name' \
field required"
)
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data["websafeSpeakerKey"]
# create Speaker & return (modified) SpeakerForm
speaker_key = Speaker(**data).put()
taskqueue.add(
params={"email": user.email(), "speakerInfo": repr(request)}, url="/tasks/send_speaker_confirmation_email"
)
# Return data as SpeakerForm
speakerform = SpeakerForm()
for field in speakerform.all_fields():
if data.has_key(field.name):
setattr(speakerform, field.name, data[field.name])
# Checks if the field is websafeSpeakerKey, then converts it into
# urlsafe key
elif field.name == "websafeSpeakerKey":
setattr(speakerform, field.name, speaker_key.urlsafe())
speakerform.check_initialized()
return speakerform
示例3: _addSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import urlsafe [as 别名]
def _addSpeakerObject(self, request):
"""Create Speaker object, returning SpeakerForm/request."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
if not request.speakerFirst or not request.speakerLast:
raise endpoints.BadRequestException("Speaker 'name' fields are required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name)\
for field in request.all_fields()}
# creation of Speaker with key & return (modified) SpeakerForm
speaker_key = Speaker(**data).put()
wsk = speaker_key.urlsafe()
speaker = speaker_key.get()
speaker.speakerWSK = wsk
speaker.put()
return request