本文整理汇总了Python中utils.getUserId函数的典型用法代码示例。如果您正苦于以下问题:Python getUserId函数的具体用法?Python getUserId怎么用?Python getUserId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getUserId函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: addWishList
def addWishList(self, request):
"""Adds a session to a user wishlist"""
user = endpoints.get_current_user()
# User is logged in
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# Check if parameters were provided
if not request.websafeSessionKey:
raise endpoints.BadRequestException('websafeSessionKey are required')
# check that session exists
session_key = ndb.Key(urlsafe=request.websafeSessionKey)
session = session_key.get()
if not session:
raise endpoints.NotFoundException('No session found with key: %s' % request.websafeSessionKey)
new_wishlist_session = UserWishList(
userId=getUserId(user),
websafeSessionKey=session_key.urlsafe()
)
new_wishlist_session.put()
return UserWishListForm(
userId=getUserId(user),
websafeSessionKey=session_key.urlsafe()
)
开发者ID:lyoshida,项目名称:conference-central,代码行数:28,代码来源:conference.py
示例2: editprofile
def editprofile():
error = ""
userid = utils.getUserId(session['user'])
profile = utils.getProfile(userid)
if request.method == 'POST':
if request.form['picsource'] != "" and request.form['age'] != "" and request.form['color'] != "":
utils.writeProfile(utils.getUserId(session['user']), request.form['picsource'], int(request.form['age']), request.form['color'])
return redirect(url_for('user', username=session['user']))
else:
error = "Error: Missing fields"
return render_template("editprofile.html", error = error, profile = profile)
else:
return render_template("editprofile.html", error = error, profile = profile)
开发者ID:snady,项目名称:blag,代码行数:13,代码来源:app.py
示例3: getConferencesCreated
def getConferencesCreated(self, request):
"""Return user created conferences."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
# query conferences
conferences = Conference.query(ancestor=ndb.Key(Profile, getUserId(user)))
# profile key
prof = ndb.Key(Profile, getUserId(user)).get()
# return conf form obj
return ConferenceForms(
items=[self._copyConferenceToForm(conf, getattr(prof, "displayName")) for conf in conferences]
)
开发者ID:jlcjensen,项目名称:classworkp4-udacity,代码行数:14,代码来源:conference.py
示例4: _createSessionObject
def _createSessionObject(self,request):
"""Create Session Object, returning SessionForm/request"""
# 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(
"Session 'name' field required")
#Get conference key
wsck = request.websafeConferenceKey
#Get conference object
c_key = ndb.Key(urlsafe = wsck)
conf = c_key.get()
#check if conf exist
if not conf:
raise endpoints.NotFoundException(
'No conference found with key: %s' % wsck)
#check if user is the creator of the conference
if conf.organizerUserId != getUserId(endpoints.get_current_user()):
raise endpoints.ForbiddenException(
'You must be the organizer to create a session.')
#copy Session/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name)
for field in request.all_field()}
#convert date and time from strings to Date objects;
if data['date']:
data['date'] = datetime.strptime(
data['data'][:10], "%Y-%m-%d".date())
if data['startTime']:
datat['startTime'] = datetime.strptime(
data['startTime'][:10], "%H,%M").time()
# Allocate new Session ID with Conference key as the parent
session_id = Session.allocate_ids(size = 1, parent = c_key)[0]
# Make Session key from ID
session_key = ndb.Key(Session, session_id, parent = c_key)
data['key'] = session_key
#Save session into database
Session(**data).put()
# Taskque for featuredSpeaker endpoint
#check for featured speaker in conference:
taskqueue.add(params={'speaker': data['speaker'],
'websafeConferenceKey': wsck
},
url='/tasks/check_featured_speaker')
session = session_key.get()
return self._copySessionToForm(session)
开发者ID:minjiecode,项目名称:fullstack-nanodegree-vm,代码行数:50,代码来源:conference.py
示例5: user
def user(username=""):
error=""
profile = []
if username == "":
return redirect("/login")
else:
if request.method == 'POST':
return redirect("/editprofile")
else:
if utils.getUserId(username) == None:
error = "User does not exist!"
else:
userid = utils.getUserId(username)
profile = utils.getProfile(userid)
return render_template("myprofile.html", profile = profile, error = error)
开发者ID:snady,项目名称:blag,代码行数:15,代码来源:app.py
示例6: _createSessionObject
def _createSessionObject(self, request):
"""Create or update Conference object, returning SessionForm/request."""
# 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("Session 'name' field required")
#get cinference key
wsck = request.websafeConferenceKey
# get conference object
c_key = ndb.Key(urlsafe=wsck)
conf = c_key.get()
# check that conference exists or not
if not conf:
raise endpoints.NotFoundException(
'No conference found with key: %s' % wsck)
# check that user is owner
if conf.organizerUserId != getUserId(endpoints.get_current_user()):
raise endpoints.ForbiddenException(
'You must be the organizer to create a session.')
# copy SessionForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# convert date and time from strings to Date objects;
if data['date']:
data['date'] = datetime.strptime(data['date'][:10], "%Y-%m-%d").date()
if data['startTime']:
data['startTime'] = datetime.strptime(data['startTime'][:10], "%H, %M").time()
# allocate new Session ID with Conference key as parent
s_id = Session.allocate_ids(size=1, parent=c_key)[0]
# make Session key from ID
s_key = ndb.Key(Session, s_id, parent=c_key)
data['key'] = s_key
data['websafeConferenceKey'] = wsck
del data['sessionSafeKey']
# save session into database
Session(**data).put()
# This task wil send a confirmation email to the owner
taskqueue.add(params={'email': user.email(),
'conferenceInfo': repr(request)},
url='/tasks/send_confirmation_session_email'
)
return request
开发者ID:kongling893,项目名称:Conference-Organization-APP-UDACITY,代码行数:48,代码来源:conference.py
示例7: getSessionsBySpeaker
def getSessionsBySpeaker(self, request):
"""Return sessions having the same speaker across conferences."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# create ancestor query for all key matches for this conference
first = request.speakerFirst
last = request.speakerLast
fullname = str(first)+" "+str(last)
# query all sessions by speaker names
sessions = Session.query()
sessions = sessions.filter(Session.speakerLast==last)
sessions = sessions.filter(Session.speakerFirst==first)
if not sessions:
raise endpoints.NotFoundException(
'No sessions found for speaker with name: %s' % fullname)
# return set of SessionForm objects per Session
return SessionForms(
items=[self._copySessionToForm(sess, "") for sess in sessions]
)
开发者ID:erooma,项目名称:ud858,代码行数:26,代码来源:conference.py
示例8: getSessionsInWishlistByConference
def getSessionsInWishlistByConference(self, request):
""" List the wishlist items for the specified conference. """
# validate the websafe conference key
conference_key = validate_websafe_key(request.websafeConferenceKey,
'Conference')
# confirm the user
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required.')
user_id = getUserId(user)
user_key = ndb.Key(Profile, user_id)
# get the user's wishlist sessions as a projection
q_wishlist = WishList.query(ancestor=user_key)
# wl_sessions = q_wishlist.fetch(1, projection=[WishList.sessions])
wishlist = q_wishlist.fetch(1)[0]
wishlist_session_keys = []
# for session in wl_sessions:
for session in wishlist.sessions:
wishlist_session_keys.append(ndb.Key(urlsafe=session))
# query Sessions where the specified Conference is the ancestor
session_q = Session.query(ancestor=conference_key)
# filter the Sessions to include only the sessions in the wishlist
session_q = session_q.filter(Session.key.IN(wishlist_session_keys))
# get the keys of those sessions, which are the ones we're looking for
conf_session_keys = session_q.fetch(keys_only=True)
# create a wishlist
short_wishlist = WishList()
# copy the found Session keys into the wishlist as websafe keys
for key in conf_session_keys:
short_wishlist.sessions.append(key.urlsafe())
# return the reduced wishlist as a message
return self._copyWishListToForm(short_wishlist)
开发者ID:kirklink,项目名称:udacity-fullstack-p4,代码行数:32,代码来源:conference.py
示例9: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# TODO 1 X
# step 1. copy utils.py from additions folder to this folder
# and import getUserId from it
# step 2. get user id by calling getUserId(user)
# step 3. create a new key of kind Profile from the id
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
# TODO 3 X
# get the entity from datastore by using get() on the key
profile = p_key.get()
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
# TODO 2 X
# save the profile to datastore
profile.put()
return profile # return Profile
开发者ID:ransomw,项目名称:udacity,代码行数:30,代码来源:conference.py
示例10: _updateConferenceObject
def _updateConferenceObject(self, request):
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
# copy ConferenceForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# update existing conference
conf = ndb.Key(urlsafe=request.websafeConferenceKey).get()
# check that conference exists
if not conf:
raise endpoints.NotFoundException("No conference found with key: %s" % request.websafeConferenceKey)
# check that user is owner
if user_id != conf.organizerUserId:
raise endpoints.ForbiddenException("Only the owner can update the conference.")
# Not getting all the fields, so don't create a new object; just
# copy relevant fields from ConferenceForm to Conference 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 ("startDate", "endDate"):
data = datetime.strptime(data, "%Y-%m-%d").date()
if field.name == "startDate":
conf.month = data.month
# write to Conference object
setattr(conf, field.name, data)
conf.put()
prof = ndb.Key(Profile, user_id).get()
return self._copyConferenceToForm(conf, getattr(prof, "displayName"))
开发者ID:omh11,项目名称:Conference-Organization-App,代码行数:35,代码来源:conference.py
示例11: addSessionToWishlist
def addSessionToWishlist(self, request):
#TASK 2
"""Adds sessions to a user wishlist & returns the sessions added"""
#Check if the user is logged in
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization Required')
user_id = getUserId(user)
#Validate that the SessionKey (urlsafe key) is provided
if not request.SessionKey:
raise endpoints.BadRequestException("SessionKey field required")
#Validate whether the requested SessionKey is already in the user's wishlist
q = SessionWishlist.query()
if (q.filter(SessionWishlist.sessionKey == request.SessionKey).count() > 0):
raise endpoints.BadRequestException("SessionKey is already in %s's wishlist" % user)
#Generate a Wishlist key to store the user wishlist. The wishlist will be created as
#a child of Profile
p_key = ndb.Key(Profile, user_id)
w_id = SessionWishlist.allocate_ids(size=1, parent=p_key)[0]
w_key = ndb.Key(SessionWishlist, w_id, parent=p_key)
#Add the wishlist to the DS
wishlist = SessionWishlist( key = w_key, sessionKey = request.SessionKey)
wl_key = wishlist.put()
#Return the session associated with the created entry
session = ndb.Key(urlsafe=request.SessionKey).get()
return self._copySessionToForm(session)
开发者ID:yamrock,项目名称:confcentral,代码行数:26,代码来源:conference.py
示例12: getSessionsBySpeaker
def getSessionsBySpeaker(self, request):
"""Given a speaker, return all sessions given by this particular speaker, across all conferences"""
# make sure user is logged in
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
# get speaker value from form request
sessionSpeakerOfInterest = request.speaker
# store all session objects across all conferences where this speaker is presenting
all_sessions = []
# query for conferences
conferences = Conference.query()
for conf in conferences:
ck = getattr(conf, "key")
wsck = ck.urlsafe()
# For each conference, get Sessions for the Conference filtered by Speaker
sessions = Session.query(Session.websafeConferenceKey == wsck)
sessions = sessions.filter(Session.speaker == sessionSpeakerOfInterest)
for session in sessions:
all_sessions.append(session)
# return sessions in all conferences
return SessionForms(items=[self._copySessionToForm(session) for session in all_sessions])
开发者ID:twhetzel,项目名称:ud858-scalable-apps,代码行数:29,代码来源:conference.py
示例13: _createSessionObject
def _createSessionObject(self, request):
"""Create or update Session object, returning SessionForm/request."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException("Session 'name' field required")
# copy SessionForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
# del data['organizerDisplayName']
# add default values for those missing (both data model & outbound Message)
for df in DEFAULTS_SESSION:
if data[df] in (None, []):
data[df] = DEFAULTS_SESSION[df]
setattr(request, df, DEFAULTS_SESSION[df])
# Getting a TEMP conference key for the moment
q = Conference.query()
cons = q.get()
c_key = cons.key
s_id = Session.allocate_ids(size=1, parent=c_key)[0]
s_key = ndb.Key(Session, s_id, parent=c_key)
data['key'] = s_key
Session(**data).put()
return request
开发者ID:dchilders21,项目名称:Udacity_P4_ConferenceCentral,代码行数:32,代码来源:conference.py
示例14: getAvailableSessions
def getAvailableSessions(self, request):
"""Return sessions having spots available in a conference."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# create ancestor query for all key matches for this conference
wsk = request.websafeConferenceKey
conf = ndb.Key(urlsafe=wsk).get()
sessions = Session.query(ancestor=ndb.Key(urlsafe=wsk))
if not sessions:
raise endpoints.NotFoundException(
'No sessions found for this conference.')
# check if available sessions exist
# query by number of spots available
sessions = sessions.filter(Session.spotsAvailable > 0)
if not sessions:
raise endpoints.NotFoundException(
'No available sessions are found for this conference.')
# return set of SessionForm objects per Session
return SessionForms(
items=[self._copySessionToForm(sess, "") for sess in sessions]
)
开发者ID:erooma,项目名称:Conference-Application,代码行数:31,代码来源:conference.py
示例15: getConferenceSessionsByType
def getConferenceSessionsByType(self, request):
"""Return sessions of a conference of a particular type."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# create ancestor query for all key matches for this conference
wsk = request.websafeConferenceKey
sessionType = request.typeOfSession
conf = ndb.Key(urlsafe=wsk).get()
# query all sessions in this conference of a particular type
sessions = Session.query(ancestor=ndb.Key(urlsafe=wsk))
sessions = sessions.filter(Session.typeOfSession==sessionType)
if not sessions:
raise endpoints.NotFoundException(
'No sessions found for conference with key: %s and type: %s'\
% wsk % sessionType)
# return set of SessionForm objects per Session
return SessionForms(
items=[self._copySessionToForm(sess, wsk) for sess in sessions]
)
开发者ID:erooma,项目名称:Conference-Application,代码行数:26,代码来源:conference.py
示例16: addSessionToWishlist
def addSessionToWishlist(self, request):
"""Adds the session to the user's list of sessions they are interested in attending."""
session_key = ndb.Key(urlsafe=request.sessionWSKey)
# print 'session_key.kind(): ' + session_key.kind() + str(type(session_key.kind()))
if session_key.kind() != 'Session':
raise endpoints.BadRequestException("Session key is invalid")
if not session_key.get():
raise endpoints.NotFoundException("Session was not found")
# session = session_key.get()
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
wishlist = self._getWithlistByUserId(getUserId(user))
wishlist.sessionKeysToAttend.append(request.sessionWSKey)
wishlist.put()
return BooleanMessage(data=True)
开发者ID:thiagoh,项目名称:appengine-test,代码行数:25,代码来源:conference.py
示例17: _createSpeakerObject
def _createSpeakerObject(self, request):
"""Create Speaker object, returning SpeakerForm."""
# check for auth'ed and valid user
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# Speaker name must be filled
if not request.name:
raise endpoints.BadRequestException("Field 'name' required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# allocate new Speaker ID
s_id = Speaker.allocate_ids(size=1)[0]
# make Speaker key from ID
s_key = ndb.Key(Speaker, s_id)
data['key'] = s_key
# create Speaker & return SpeakerForm
speaker = Speaker(**data)
speaker.put()
return self._copySpeakerToForm(speaker)
开发者ID:skh,项目名称:skhonference,代码行数:27,代码来源:conference.py
示例18: getConferenceSessions
def getConferenceSessions(self, request):
"""Return all sessions in a given conference."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# sessions belong to conferences, so: websafe conference key given?
if not request.websafeConferenceKey:
raise endpoints.BadRequestException("Field 'websafeConferenceKey' required")
# websafe conference key good?
try:
c_key = ndb.Key(urlsafe=request.websafeConferenceKey)
except Exception:
raise endpoints.BadRequestException("websafeConferenceKey given is corrupted")
if not c_key:
raise endpoints.BadRequestException("websafeConferenceKey given is invalid")
# does the conference (still) exist?
conf = c_key.get()
if not conf:
raise endpoints.NotFoundException("Conference with this key does not exist")
# create ancestor query for all key matches for this user
sessions = Session.query(ancestor=c_key)
# return set of SessionForm objects per Conference
return SessionForms(
items=[self._copySessionToForm(session) for session in sessions]
)
开发者ID:skh,项目名称:skhonference,代码行数:31,代码来源:conference.py
示例19: getSessionsByDate
def getSessionsByDate(self, request):
"""Return sessions having a particular date."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# create date format
if not request.sessionDate:
raise endpoints.UnauthorizedException('A date value is required')
else:
sessionDate = datetime.strptime(request.sessionDate[:10],\
"%Y-%m-%d").date()
# query by date
sessions = Session.query()
sessions = sessions.filter(Session.sessionDate==sessionDate)
if not sessions:
raise endpoints.NotFoundException(
'No sessions found for this date.')
# return set of SessionForm objects per Session
return SessionForms(
items=[self._copySessionToForm(sess, "") for sess in sessions]
)
开发者ID:erooma,项目名称:Conference-Application,代码行数:27,代码来源:conference.py
示例20: _createConferenceObject
def _createConferenceObject(self, request):
"""Create or update Conference object, returning ConferenceForm/request."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException("Conference 'name' field required")
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
del data['organizerDisplayName']
for df in DEFAULTS:
if data[df] in (None, []):
data[df] = DEFAULTS[df]
setattr(request, df, DEFAULTS[df])
if data['startDate']:
data['startDate'] = datetime.strptime(data['startDate'][:10], "%Y-%m-%d").date()
data['month'] = data['startDate'].month
else:
data['month'] = 0
if data['endDate']:
data['endDate'] = datetime.strptime(data['endDate'][:10], "%Y-%m-%d").date()
if data["maxAttendees"] > 0:
data["seatsAvailable"] = data["maxAttendees"]
p_key = ndb.Key(Profile, user_id)
c_id = Conference.allocate_ids(size=1, parent=p_key)[0]
c_key = ndb.Key(Conference, c_id, parent=p_key)
data['key'] = c_key
data['organizerUserId'] = request.organizerUserId = user_id
Conference(**data).put()
taskqueue.add(params={'email': user.email(),
'conferenceInfo': repr(request)},
url='/tasks/send_confirmation_email'
)
return request
开发者ID:Taiyi,项目名称:Conference,代码行数:35,代码来源:conference.py
注:本文中的utils.getUserId函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论