def show_post(self):
   self.template = 'speakers_edit'
   user = users.get_current_user()
   event_id = self.request.get('event')
   event = CEvent(event_id).get()
   form = SpeakersForm(self.request.POST)
   # check permissions...
   if user and event and (user in event.organizers or users.is_current_user_admin()):
     if form.validate():
       old_speakers = CSpeakerList(event_id).get()
       for i in range(0,1024):
         prefix = 'speakers-' + str(i) + '-'
         if self.request.get(prefix + 'first_name'):
           # is this a modification of an existing speaker or a new one?
           speaker_id = self.request.get(prefix + 'speaker')
           if speaker_id in [str(s.key()) for s in old_speakers]:
             speaker = [s for s in old_speakers if str(s.key()) == speaker_id][0]
             # delete from old_speaker
             old_speakers = [s for s in old_speakers if str(s.key()) != speaker_id]
           else:
             speaker = Speaker()
           # fill in values for old/new speaker
           speaker.first_name = self.request.get(prefix + 'first_name')
           speaker.last_name = self.request.get(prefix + 'last_name')
           speaker.gplus_id = self.request.get(prefix + 'gplus_id')
           speaker.short_bio = self.request.get(prefix + 'short_bio')
           upload_files = self.get_uploads(prefix + 'thumbnail')
           if len(upload_files) > 0:
             blob_info = upload_files[0]
             speaker.thumbnail = '%s' % blob_info.key()
           speaker.event = event
           # update speaker
           speaker.put()
       # end for
       # now delete all speakers not mentioned yet
       for s in old_speakers:
         s.delete()
       # set info that modification was successful
       self.values['modified_successful'] = True
       # clear cache
       CSpeakerList.remove_from_cache(event_id)
     # set event into form object
     self.values['event'] = event
   elif not user:
     return self.redirect(
                  users.create_login_url("/event/speakers/edit/" + event_id))
   else:
     return self.redirect("/event/create");
   self.values['current_navigation'] = 'speakers'
   self.values['form_url'] = blobstore.create_upload_url(
                                   '/event/speakers/upload')
   self.values['form'] = form
Beispiel #2
0
 def load_from_db(self):
   self.entity_collection = Speaker.all().filter('event =', CEvent(self.id).get())