本文整理汇总了Python中models.SessionForm类的典型用法代码示例。如果您正苦于以下问题:Python SessionForm类的具体用法?Python SessionForm怎么用?Python SessionForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SessionForm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _copySessionToForm
def _copySessionToForm(self, sess):
"""
Copy relevant fields from Session to SessionForm.
:param sess: Session object
:return: SessionForm
"""
# Get empty SessionForm
sf = SessionForm()
# Copy fields from Session to SessionForm
for field in sf.all_fields():
if hasattr(sess, field.name):
# Convert data into appropriate format
if field.name == 'sess_time':
setattr(sf, 'sess_time',
str(getattr(sess, 'sess_time'))[:5])
elif field.name == 'sess_date':
setattr(sf, 'sess_date',
str(getattr(sess, 'sess_date'))[:10])
else:
setattr(sf, field.name, getattr(sess, field.name))
sf.check_initialized()
return sf
开发者ID:sikegame,项目名称:udacity-p4,代码行数:25,代码来源:conference.py
示例2: _copySessionToForm
def _copySessionToForm(self, session):
"""
Input:
session: Session object
Returns:
SessionForm
Description:
This method takes a session object with values defined from client
side and returns the SessionFrom after copying the relevant fields in
it which can be returned to client as ProRPC Message.
"""
sessionform = SessionForm()
for field in sessionform.all_fields():
if hasattr(session, field.name):
# convert Date to date string; just copy others
if field.name.endswith("date"):
setattr(sessionform, field.name, str(getattr(session, field.name)))
else:
setattr(sessionform, field.name, getattr(session, field.name))
# Checks if the field is websafeSessionKey, then converts it into
# urlsafe key
elif field.name == "websafeSessionKey":
setattr(sessionform, field.name, session.key.urlsafe())
sessionform.check_initialized()
return sessionform
开发者ID:zeeshaanahmad,项目名称:fsnd-p4-conference-central,代码行数:26,代码来源:conference.py
示例3: _copySessionToForm
def _copySessionToForm(self, sess):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(sess, field.name):
if field.name == 'speaker':
sf.speaker = SpeakerForm(
name=sess.speaker.name,
email=sess.speaker.email,
websafeSpeakerKey=sess.speaker.websafeSpeakerKey,
)
# convert sessionType string to Enum
elif field.name == 'sessionType':
setattr(
sf,
field.name,
getattr(SessionType, getattr(sess, field.name))
)
# convert Date to date string
elif field.name == 'date':
setattr(sf, field.name, str(getattr(sess, field.name)))
# just copy others
else:
setattr(sf, field.name, getattr(sess, field.name))
# get the websafe session key
elif field.name == 'websafeKey':
setattr(sf, field.name, sess.key.urlsafe())
sf.check_initialized()
return sf
开发者ID:iliketomatoes,项目名称:conference-app,代码行数:30,代码来源:conference.py
示例4: _copySessionToForm
def _copySessionToForm(self, sess):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(sess, field.name):
# Convert Date to string
# Convert Time to string in HH:MM only
# else convert others as is
if field.name.endswith('date'):
setattr(sf, field.name, str(getattr(sess, field.name)))
elif field.name.endswith('Time'):
setattr(sf, field.name,
str(getattr(sess, field.name).strftime("%H:%M")))
else:
setattr(sf, field.name, getattr(sess, field.name))
elif field.name == "sessionWebSafeKey":
setattr(sf, field.name, sess.key.urlsafe())
elif field.name == "speakerName":
try:
speaker = sess.speaker.get()
speakerName = "%s %s" % (getattr(speaker, "firstName"),
getattr(speaker, "lastName"))
setattr(sf, 'speakerName', speakerName)
except:
pass
sf.check_initialized()
return sf
开发者ID:skibster,项目名称:conference_central,代码行数:27,代码来源:conference.py
示例5: _copySessionToForm
def _copySessionToForm(self, session):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(session, field.name):
# convert date and time to strings;
if field.name.endswith('date'):
setattr(sf, field.name, str(getattr(session, field.name)))
elif field.name.endswith('startTime'):
setattr(sf, field.name, str(getattr(session, field.name)))
# convert Speaker url safe key to speaker name
elif field.name.endswith('speaker'):
speaker_key = getattr(session, field.name)
if speaker_key is not None:
speaker = speaker_key.get()
setattr(sf, field.name, speaker.name)
else:
setattr(sf, field.name, None)
# just copy others
else:
setattr(sf, field.name, getattr(session, field.name))
# convert key to urlsafe
elif field.name == "websafeConferenceKey":
setattr(sf, field.name, session.key.parent().urlsafe())
elif field.name == "websafeKey":
setattr(sf, field.name, session.key.urlsafe())
sf.check_initialized()
return sf
开发者ID:supermanrising,项目名称:Conference-Central,代码行数:28,代码来源:conference.py
示例6: _copySessionToForm
def _copySessionToForm(self, sess):
"""Sets the fields from Session to SessionForm"""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(sess, field.name):
# If the field is the session date 'stringity' it's value
if field.name.endswith('date'):
setattr(sf, field.name, str(getattr(sess, field.name)))
elif field.name.endswith('startTime') and getattr(sess, field.name):
# Transform the float type of the startTime field into a
# string
if not type(getattr(sess, field.name)) is str:
time = str(getattr(sess, field.name)).split('.')
startTime = str(int((float(time[1]) / 100) * 60))[:2]
setattr(sf, field.name, str(time[0] + ':' + startTime))
else:
setattr(sf, field.name, str(getattr(sess, field.name)))
else:
setattr(sf, field.name, getattr(sess, field.name))
elif field.name == "websafeKey":
# If the name is websakeKey set the urlsafe
setattr(sf, field.name, sess.key.urlsafe())
sf.check_initialized()
return sf
开发者ID:JuanCam,项目名称:ConferenceApp,代码行数:25,代码来源:conference.py
示例7: _copySessionToForm
def _copySessionToForm(self, session):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(session, field.name):
# convert Date to date string; just copy others
if field.name.endswith('Date') or \
field.name.endswith('Time') or \
field.name == 'duration':
setattr(sf, field.name, str(getattr(session, field.name)))
elif field.name == 'typeOfSession':
value = getattr(session, field.name)
if value:
value = str(getattr(session, field.name))
else:
value = 'NOT_SPECIFIED'
setattr(sf, field.name, getattr(SessionType, value))
else:
setattr(sf, field.name, getattr(session, field.name))
elif field.name == 'websafeKey':
setattr(sf, field.name, session.key.urlsafe())
elif field.name == 'conferenceWebsafeKey':
key = session.key.parent()
if key:
setattr(sf, field.name, key.urlsafe())
sf.check_initialized()
return sf
开发者ID:barefootlance,项目名称:udacity-fullstack-p4,代码行数:27,代码来源:conference.py
示例8: _copySessionToForm
def _copySessionToForm(self, session, name=None):
"""Copy fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(session, field.name):
# convert typeOfSession to enum SessionTypes; just copy others
if field.name == 'typeOfSession':
setattr(sf, field.name, getattr(SessionTypes,
str(getattr(session, field.name))))
else:
setattr(sf, field.name, getattr(session, field.name))
elif field.name == "websafeKey":
setattr(sf, field.name, session.key.urlsafe())
elif field.name == "speakerDisplayName":
setattr(sf, field.name, name)
# convert startDateTime from session
# model to date and startTime for session Form
startDateTime = getattr(session, 'startDateTime')
if startDateTime:
if field.name == 'date':
setattr(sf, field.name, str(startDateTime.date()))
str_dt = startDateTime.time().strftime('%H:%M')
f_nam = field.name
if hasattr(session, 'startDateTime') and f_nam == 'startTime':
setattr(sf, field.name, str(str_dt))
sf.check_initialized()
return sf
开发者ID:mvkrishna,项目名称:udacity-full-stack,代码行数:28,代码来源:conference.py
示例9: _createSessionObject
def _createSessionObject(self, request):
"""Create or update 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)
# get 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 a create session.')
if not request.name:
raise BadRequestException("Session 'name' field required")
# generate Conference Key based on conference ID and Session
# ID based on Profile key get Conference key from ID
c_key = ndb.Key(Conference, request.websafeConferenceKey)
s_id = Session.allocate_ids(size=1, parent=c_key)[0]
s_key = ndb.Key(Session, s_id, parent=c_key)
# copy SessionForm/ProtoRPC Message into dict
sf = SessionForm()
data = {}
data['key'] = s_key
setattr(sf, 'sessionKey', s_key.urlsafe())
for field in sf.all_fields():
if hasattr(request, field.name):
attribute = getattr(request, field.name)
if field.name == 'date':
try:
datetime.strptime(attribute, "%Y-%m-%d")
except:
raise BadRequestException(
"Session 'date' format is 'yyyy-mm-dd'")
elif field.name == 'startTime':
try:
datetime.strptime(attribute, "%H:%M")
except:
raise BadRequestException(
"Session 'startTime' format is 'hh:mm' (24-hour clock)")
setattr(sf, field.name, attribute)
data[field.name] = attribute
del data["sessionKey"]
Session(**data).put()
taskqueue.add(params={'speaker': data['speaker']},
url='/tasks/update_featured_speaker')
return sf
开发者ID:bh-chaker,项目名称:cbh-conference,代码行数:60,代码来源:conference.py
示例10: _copySessionToForm
def _copySessionToForm(self, session, name=None):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(session, field.name):
if field.name == "dateTime":
s_date = getattr(session,field.name)
if s_date:
setattr(sf, 'dateTime', s_date.strftime('%y-%m-%d'))
setattr(sf, 'startTime', s_date.strftime('%H:%M'))
elif field.name == "speaker":
speakerID = getattr(session,field.name)
# get speaker object if there is one assigend
if speakerID == None:
setattr(sf, 'speakerDisplayName', 'NONE ASSIGNED')
else:
speak = Speaker.get_by_id(speakerID)
setattr(sf, 'speakerDisplayName', speak.name)
#set typeOfSession
#if there is no typeOfSession then set it to 'NOT_SPECIFIED'
elif field.name == "typeOfSession":
currentType = getattr(session,field.name)
if currentType:
setattr(sf, field.name, getattr(SessionType,
str(currentType)))
else:
setattr(sf, field.name, getattr(SessionType,
'NOT_SPECIFIED'))
else:
setattr(sf, field.name, getattr(session,field.name))
sf.check_initialized()
return sf
开发者ID:melliss67,项目名称:lively-oxide-104800,代码行数:32,代码来源:conference.py
示例11: _copySessionToForm
def _copySessionToForm(self, session):
""" Copy relevant fields from Session to SessionForm
"""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(session, field.name):
# XXX Save an endTime when startTime and duration is
# both given
if field.name in ('date', 'startTime'):
# convert Date and Time to date and time string
setattr(sf, field.name, str(getattr(session, field.name)))
elif field.name == 'typeOfSession':
# convert typeOfSession string to Enum
setattr(sf, field.name, getattr(SessionType,
getattr(session, field.name)))
elif field.name == 'speakers':
setattr(sf, field.name, [str(speaker)
for speaker in getattr(session, field.name)])
else:
# just copy the others
setattr(sf, field.name, getattr(session, field.name))
elif field.name == "websafeKey":
setattr(sf, field.name, session.key.urlsafe())
sf.check_initialized()
return sf
开发者ID:adarsh0806,项目名称:udacity-nd004-p4-conference-organization-app,代码行数:25,代码来源:conference.py
示例12: _copySessionToForm
def _copySessionToForm(self, sess):
"""Copy relevant fields from sessions to SessionsForm."""
sf = SessionForm()
s_key = sess.key.urlsafe()
c_key = ""
if sess.key.parent():
c_key = sess.key.parent().urlsafe()
for field in sf.all_fields():
if hasattr(sess, field.name):
# convert Date to date string; just copy others
if field.name.endswith('date'):
# convert Date object to string
date = str(getattr(sess, field.name))
setattr(sf, field.name, date)
elif field.name.endswith('startTime'):
# convert Time object to string
time = str(getattr(sess, field.name))
setattr(sf, field.name, time)
elif field.name.endswith('duration'):
# convert duration to string
duration = str(getattr(sess, field.name))
setattr(sf, field.name, duration)
else:
setattr(sf, field.name, getattr(sess, field.name))
elif field.name == "websafeConferenceKey":
setattr(sf, field.name, c_key)
elif field.name == "websafeSessionKey":
setattr(sf, field.name, s_key)
sf.check_initialized()
return sf
开发者ID:silveruby,项目名称:udacity-full-stack-p4,代码行数:30,代码来源:conference.py
示例13: _copySessionToForm
def _copySessionToForm(self, sess):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(sess, field.name):
# convert Date to date string; just copy others
if field.name in ["startTime", "date"]:
setattr(sf, field.name, str(getattr(sess, field.name)))
# get the websafe key from session to display
elif field.name == "speakerKeys":
spkrs = getattr(sess, field.name)
spkrs = [s.urlsafe() for s in spkrs]
setattr(sf, field.name, spkrs)
else:
setattr(sf, field.name, getattr(sess, field.name))
# show's the speaker's names
if field.name == "speakerNames":
spkrs = getattr(sess, "speakerKeys")
spkrs = [s.get().name for s in spkrs]
setattr(sf, field.name, spkrs)
if field.name == "websafeSessionKey":
webKey = sess.key.urlsafe()
setattr(sf, field.name, webKey)
sf.check_initialized()
return sf
开发者ID:jdvalera,项目名称:Udacity-Full-Stack,代码行数:26,代码来源:conference.py
示例14: _copySessionToForm
def _copySessionToForm(self, session, conf):
""" Copy items from the Session object to the SessionForm object """
sf = SessionForm()
speaker = ndb.Key(urlsafe=session.speaker_key).get()
print "This is the session's speaker: ", speaker
for field in sf.all_fields():
print "This is the field: ", field.name
if hasattr(session, field.name):
# convert t-shirt string to Enum; just copy others
if field.name == 'date':
setattr(sf, field.name, getattr(session, field.name).strftime("%Y-%m-%d"))
elif field.name == 'start_time':
setattr(sf, field.name, getattr(session, field.name).strftime("%H:%M"))
elif field.name == 'type_of_session':
try:
setattr(sf, field.name, getattr(TypeOfSession, getattr(session, field.name)))
except AttributeError:
setattr(sf, field.name, getattr(TypeOfSession, 'NOT_SPECIFIED'))
else:
setattr(sf, field.name, getattr(session, field.name))
elif field.name == "conf_websafekey":
setattr(sf, field.name, conf.key.urlsafe())
elif field.name == "sess_websafekey":
setattr(sf, field.name, session.key.urlsafe())
elif field.name == 'speaker_name':
setattr(sf, field.name, speaker.name)
elif field.name == 'speaker_email':
setattr(sf, field.name, speaker.email)
elif field.name == 'speaker_speciality':
setattr(sf, field.name, speaker.speciality)
sf.check_initialized()
return sf
开发者ID:pshevade,项目名称:Conference-Central-App,代码行数:32,代码来源:conference.py
示例15: _copySessionToForm
def _copySessionToForm(self, session):
"""Copy relevant fields from Session to SessionForm."""
# copy relevant fields from Session to SessionForm
form = SessionForm()
setattr(form, 'websafeKey', session.key.urlsafe())
for field in form.all_fields():
if hasattr(session, field.name):
# convert session type enum to string; just copy others
if field.name == 'typeOfSession':
if getattr(session, field.name) == '' or getattr(session, field.name) is None:
setattr(form, field.name, 'Other')
else:
setattr(form, field.name, getattr(SessionType,
getattr(session, field.name)))
elif field.name == 'conferenceKey' or field.name == 'speakerKey':
value = getattr(session, field.name)
if value is not None:
setattr(form, field.name,
getattr(session, field.name).urlsafe())
else:
setattr(form, field.name, '')
elif field.name == 'startTime' or field.name == 'date':
setattr(form, field.name,
str(getattr(session, field.name)))
else:
setattr(form, field.name,
getattr(session, field.name))
form.check_initialized()
return form
开发者ID:cpwhidden,项目名称:Conference-Central,代码行数:29,代码来源:conference.py
示例16: _copyConferenceSessionToForm
def _copyConferenceSessionToForm(self, session):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(session, field.name):
# Convert date and startTime fields to strings
if field.name == 'date' or field.name == 'startTime':
setattr(sf, field.name, str(getattr(session, field.name)))
# Convert typeOfSession to enum
elif field.name == 'typeOfSession':
# set typeOfSession equal to enum
setattr(
sf, field.name, getattr(
SessionType, getattr(session, field.name)))
else:
setattr(sf, field.name, getattr(session, field.name))
# Convert DataStore keys to URLSafe keys
elif field.name == 'parentKey' or field.name == 'speakerKey':
setattr(sf, field.name, session.key.urlsafe())
sf.check_initialized()
return sf
开发者ID:DavidANegrete,项目名称:Conference_Central,代码行数:34,代码来源:conference.py
示例17: _copySessionToForm
def _copySessionToForm(self, session):
"""Copy relevant fields from Session to SessionForm."""
sform = SessionForm()
print session
setattr(sform, 'sessionWebsafeKey', session.key.urlsafe() )
# get speaker properties
speaker = getattr(session, 'speakerKey').get()
if speaker:
setattr(sform, 'speakerName', str(speaker.fullname) )
setattr(sform, 'speakerProfession', str(speaker.profession) )
else:
setattr(sform, 'speakerName', "None" )
setattr(sform, 'speakerProfession', "None" )
for field in sform.all_fields():
if hasattr(session, field.name):
if field.name.endswith('date') or field.name.endswith('startTime'):
setattr(sform, field.name, str(getattr(session, field.name)))
elif field.name.endswith('speakerKey'):
# extract the name entity to string
print "Speaker KEy found"
fullname = session.speakerKey.get().fullname
profession = session.speakerKey.get().profession
setattr(sform, 'speakerName', "Test1234")
setattr(sform, 'speakerProfession', str(getattr(session, profession)))
else:
setattr(sform, field.name, getattr(session, field.name))
sform.check_initialized()
return sform
开发者ID:Tukie,项目名称:P4_Fullstack,代码行数:31,代码来源:conference.py
示例18: _copySessionToForm
def _copySessionToForm(self, session):
"""Copies relevant fields from a Session to a SessionForm.
"""
# copy relevant fields from Session to SessionForm
session_form = SessionForm()
for field in session_form.all_fields():
if hasattr(session, field.name):
if field.name in ('date', 'startTime', 'duration'):
setattr(session_form, field.name,
str(getattr(session, field.name)))
elif field.name == 'typeOfSession':
setattr(session_form, field.name,
getattr(SessionType, getattr(session, field.name)))
elif field.name == 'speakers':
setattr(session_form, field.name,
[str(s.get().name) for s in session.speakers])
else:
setattr(session_form, field.name,
getattr(session, field.name))
elif field.name == "websafeKey":
setattr(session_form, field.name,
session.key.urlsafe())
elif field.name == "websafeConferenceKey":
setattr(session_form, field.name,
session.key.parent().urlsafe())
session_form.check_initialized()
return session_form
开发者ID:juanchopanza,项目名称:ConferenceOrganizer,代码行数:29,代码来源:conference.py
示例19: _copySessionToForm
def _copySessionToForm(self, session):
""" Copy relevant fields from Session to SessionForm."""
sessionForm = SessionForm()
for field in sessionForm.all_fields():
if field.name == "speakerKey":
speaker = session.speaker.get()
if speaker:
setattr(sessionForm, "speakerKey", speaker.key.urlsafe())
elif field.name == "date":
setattr(sessionForm, "date", str(session.date.date()))
elif field.name == "startTime":
setattr(sessionForm, "startTime", str(session.startTime.time()))
elif field.name == "endTime":
setattr(sessionForm, "endTime", str(session.endTime.time()))
elif field.name == "duration":
setattr(sessionForm, "duration", duration(session.startTime, session.endTime))
elif field.name == "websafeKey":
setattr(sessionForm, field.name, session.key.urlsafe())
elif hasattr(session, field.name):
setattr(sessionForm, field.name, getattr(session, field.name))
sessionForm.check_initialized()
return sessionForm
开发者ID:mimi149,项目名称:p4_Conference_APIs,代码行数:32,代码来源:conference.py
示例20: _copySessionToForm
def _copySessionToForm(self, _session):
"""Copy relevant fields from Session to SessionForm."""
sf = SessionForm()
for field in sf.all_fields():
if hasattr(_session, field.name):
if (field.name == 'date' or field.name == 'startTime'):
setattr(sf, field.name, str(getattr(_session, field.name)))
elif (field.name == 'speaker'):
if (getattr(_session, 'speaker')):
speaker = getattr(_session, 'speaker').get()
setattr(sf, 'speakerName', speaker.displayName)
setattr(
sf,
field.name,
getattr(_session, 'speaker').urlsafe()
)
else:
setattr(sf, 'speakerName', 'TBA')
setattr(sf, field.name, None)
else:
setattr(sf, field.name, getattr(_session, field.name))
elif field.name == "websafeKey":
setattr(sf, field.name, _session.key.urlsafe())
sf.check_initialized()
return sf
开发者ID:chriswilley,项目名称:conference-central,代码行数:25,代码来源:conference.py
注:本文中的models.SessionForm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论