本文整理汇总了Python中models.SpeakerForm类的典型用法代码示例。如果您正苦于以下问题:Python SpeakerForm类的具体用法?Python SpeakerForm怎么用?Python SpeakerForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpeakerForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFeaturedSpeaker
def getFeaturedSpeaker(self, request):
"""Returns the sessions of the featured speaker"""
data = memcache.get("featured_speaker")
from pprint import pprint
pprint(data)
sessions = []
sessionNames = []
speaker = None
if data and data.has_key("speaker") and data.has_key("sessionNames"):
speaker = data["speaker"]
sessionNames = data["sessionNames"]
else:
upcoming_session = (
Session.query(Session.date >= datetime.now()).order(Session.date, Session.startTime).get()
)
if upcoming_session:
speaker = upcoming_session.speaker
sessions = Session.query(Session.speaker == speaker)
sessionNames = [session.name for session in sessions]
# create speaker form
sf = SpeakerForm()
for field in sf.all_fields():
if field.name == "sessionNames":
setattr(sf, field.name, sessionNames)
elif field.name == "speaker":
setattr(sf, field.name, speaker)
sf.check_initialized()
return sf
示例2: getFeaturedSpeaker
def getFeaturedSpeaker(self,request):
""" Returns a featured speaker and his/her sessions """
sessions = []
sessionNames = []
speaker = None
# look for data in memcache
memcache_data = memcache.get(MEMCACHE_SPEAKER_KEY)
if memcache_data:
speaker = memcache_data['speaker']
sessionNames = memcache_data['sessionNames']
else:
speaker = sessionNames = None
sf = SpeakerForm()
for field in sf.all_fields():
if field.name == 'speaker':
setattr(sf, field.name, speaker)
elif field.name == 'sessionNames':
setattr(sf, field.name, sessionNames)
sf.check_initialized()
return sf
示例3: sample_form
def sample_form(request):
if request.method == 'POST':
sf = None
instance_id = request.GET.get(u'speaker')
if instance_id is not None:
instance = get_object_or_404(Speaker, pk=instance_id)
sf = SpeakerForm(request.POST, instance=instance)
else:
sf = SpeakerForm(request.POST)
if sf.is_valid():
speaker = sf.save()
return http.HttpResponseRedirect(reverse("sampleformok", args=[speaker.pk]))
else:
return render_to_response('test/form.html', {'form': sf}, context_instance=RequestContext(request))
elif request.method == 'GET':
form = None
instance_id = request.GET.get(u'speaker')
if instance_id is not None:
instance = get_object_or_404(Speaker, pk=instance_id)
form = SpeakerForm(instance=instance)
else:
form = SpeakerForm(initial={u'languages': [1, 2], u'group': 1})
return render_to_response('test/form.html', {'form': form}, context_instance=RequestContext(request))
else:
return http.HttpResponseNotAllowed(['GET', 'POST'])
示例4: getFeaturedSpeaker
def getFeaturedSpeaker(self, request):
"""Returns the sessions of the featured speaker"""
# try to get data from memcache
data = memcache.get(MEMCACHE_FEATURED_SPEAKER_KEY)
sessions = []
sessionNames = []
speaker = None
if data and data.has_key('speaker') and data.has_key('sessionNames'):
speaker = data['speaker']
sessionNames = data['sessionNames']
# if data is not on memcache, get speaker from upcoming session
else:
nextSession = Session.query(Session.date >= datetime.now()).order(Session.date, Session.startTime).get()
if nextSession:
speaker = nextSession.speaker
sessions = Session.query(Session.speaker == speaker)
sessionNames = [session.name for session in sessions]
# fill speaker form
speaker_form = SpeakerForm()
for field in speaker_form.all_fields():
if field.name == 'sessionNames':
setattr(speaker_form, field.name, sessionNames)
elif field.name == 'speaker':
setattr(speaker_form, field.name, speaker)
speaker_form.check_initialized()
return speaker_form
示例5: _copySpeakerToForm
def _copySpeakerToForm(self, speak):
"""Copy relevant fields from Speaker to SpeakerForm."""
sp = SpeakerForm()
for field in sp.all_fields():
setattr(sp, field.name, getattr(speak, field.name))
sp.check_initialized()
return sp
示例6: _copySpeakerToForm
def _copySpeakerToForm(self, speaker):
sf = SpeakerForm()
for field in sf.all_fields():
if hasattr(speaker, field.name):
setattr(sf, field.name, str(getattr(speaker, field.name)))
sf.check_initialized()
return sf
示例7: getFeaturedSpeaker
def getFeaturedSpeaker(self, request):
"""Returns the sessions of the featured speaker"""
# attempt to get data from memcache
data = memcache.get('featured_speaker')
from pprint import pprint
pprint(data)
sessions = []
sessionNames = []
speaker = None
if data and data.has_key('speaker') and data.has_key('sessionNames'):
speaker = data['speaker']
sessionNames = data['sessionNames']
# if memcache fails or is empty, pull speaker from upcoming session
else:
upcoming_session = Session.query(Session.date >= datetime.now())\
.order(Session.date, Session.startTime).get()
if upcoming_session:
speaker = upcoming_session.speaker
sessions = Session.query(Session.speaker == speaker)
sessionNames = [session.name for session in sessions]
# populate speaker form
sf = SpeakerForm()
for field in sf.all_fields():
if field.name == 'sessionNames':
setattr(sf, field.name, sessionNames)
elif field.name == 'speaker':
setattr(sf, field.name, speaker)
sf.check_initialized()
return sf
示例8: getFeaturedSpeaker
def getFeaturedSpeaker(self, request):
"""Returns the sessions of the featured speaker"""
# try to get the speaker related data from memcache that was storied earlier
data = memcache.get('featured_speaker')
from pprint import pprint
pprint(data)
sessionNames = []
speaker = None
if data and data.has_key('speaker') and data.has_key('sessionNames'):
speaker = data['speaker']
sessionNames = data['sessionNames']
# if the memcache fails or is found to be empty, then display a message accordingly
else:
raise endpoints.NotFoundException(
'Failed to retrieve data related to the speaker.')
# populate the speaker form appropriately in case the speaker data is sucessfully retrieved
sf = SpeakerForm()
for field in sf.all_fields():
if field.name == 'sessionNames':
setattr(sf, field.name, sessionNames)
elif field.name == 'speaker':
setattr(sf, field.name, speaker)
sf.check_initialized()
return sf
示例9: _copySpeakerToForm
def _copySpeakerToForm(self, speaker):
"""Copy relevant fields from Speaker to SpeakerForm."""
sf = SpeakerForm()
for field in sf.all_fields():
if hasattr(speaker, field.name):
setattr(sf, field.name, getattr(speaker, field.name))
sf.check_initialized()
return sf
示例10: _copySpeakerToForm
def _copySpeakerToForm(self, speaker):
'''Copy relevant fields from Speaker to SpeakerForm'''
speaker_form = SpeakerForm()
for field in speaker_form.all_fields():
if hasattr(speaker, field.name):
setattr(speaker_form, field.name, getattr(speaker, field.name))
speaker_form.check_initialized()
return speaker_form
示例11: _copySpeakerToForm
def _copySpeakerToForm(self, spkr):
"""Copy relevant fields from Speaker to SpeakerForm."""
sf = SpeakerForm()
setattr(sf, "name", getattr(spkr, "name"))
setattr(sf, "websafeKey", spkr.key.urlsafe())
sf.check_initialized()
return sf
示例12: _copySpeakerToForm
def _copySpeakerToForm(self, speak):
"""Copy relevant fields from Speaker to SpeakerForm."""
sp = SpeakerForm()
for field in sp.all_fields():
if hasattr(speak, field.name):
setattr(sp, field.name, getattr(speak, field.name))
elif field.name == "speakerWebSafeKey":
setattr(sp, field.name, speak.key.urlsafe())
sp.check_initialized()
return sp
示例13: _copySpeakerToForm
def _copySpeakerToForm(self, speaker):
"""Copy relevant fields from Speaker to SpeakerForm"""
sf = SpeakerForm()
for field in sf.all_fields():
if hasattr(speaker, field.name):
setattr(sf, field.name, getattr(speaker, field.name))
elif field.name == "websafeKey":
setattr(sf, field.name, speaker.key.urlsafe())
sf.check_initialized()
return sf
示例14: _copySpeakerToForm
def _copySpeakerToForm(self, speaker):
# Get empty SessionForm
sf = SpeakerForm()
# Copy fields from Session to SessionForm
for field in sf.all_fields():
if hasattr(speaker, field.name):
setattr(sf, field.name, getattr(speaker, field.name))
sf.check_initialized()
return sf
示例15: _copySpeakerToForm
def _copySpeakerToForm(self, speaker):
"""Copy speaker to form"""
sp = SpeakerForm()
for field in sp.all_fields():
if hasattr(speaker, field.name):
setattr(sp, field.name, getattr(speaker, field.name))
elif field.name == "websafeKey":
setattr(sp, field.name, speaker.key.urlsafe())
sp.check_initialized()
return sp