def load_from_db(self): sessions = Session.all().filter('event_key =', str(self.id)) # I have to manually sort them, sorry... try: self.entity_collection = sorted(sessions, key=lambda x: CSlot(x.slot_key).get().start) except: self.entity_collection = sessions
def load_from_db(self): self.entity_collection = None try: data = Session.get(self.id) if isinstance(data, Session): self.entity_collection = data except: pass
def load_from_db(self): self.entity_collection = {} sessions = Session.all().filter('event =', CEvent(self.event_id).get()) # list of all rooms per day room_list = {} # list of all sessions, first per day, then organized by slot by_slot = {} # list of all sessions, first per day, then organized by room by_room = {} # list of all sessions, first by day, then by slot then by room by_slot_room = {} for session in sessions: # empty room? make a " " out of it. if not session.room: session.room = " " # get the day for the session day = session.slot.day.date # is day known? if not day in room_list: room_list[day] = [] by_slot[day] = {} by_room[day] = {} by_slot_room[day] = {} # is the slot already known? session.slot_key = self.key_for_slot(session.slot) if session.slot_key not in by_slot[day]: by_slot[day][session.slot_key] = [] by_slot_room[day][session.slot_key] = {} # is the room already known? if session.room and (session.room not in room_list[day]): room_list[day].append(session.room) by_room[day][session.room] = [] # append the session to the three lists by_slot[day][session.slot_key].append(session) by_room[day][session.room].append(session) # we want only one session at one time in one room by_slot_room[day][session.slot_key][session.room] = session # list of all slots - even empty ones. we add an element count # for the number of sessions slot_list = {} date_list = [] for s in CSlotList(self.event_id).get(): s.date = s.day.date s.slot_key = self.key_for_slot(s) if by_slot.has_key(s.date): if s.slot_key in by_slot[s.date]: s.sessioncount = len(by_slot[s.date][s.slot_key]) else: s.sessioncount = 0 else : s.sessioncount = 0 if s.date not in date_list: date_list.append(s.date) slot_list[s.date] = [] slot_list[s.date].append(s) # store the data! self.entity_collection['room_list'] = room_list self.entity_collection['slot_list'] = slot_list self.entity_collection['date_list'] = date_list self.entity_collection['by_slot'] = by_slot self.entity_collection['by_room'] = by_room self.entity_collection['by_slot_room'] = by_slot_room
def load_from_db(self): sessions = Session.all().filter('event =', CEvent(self.id).get()) # I have to manually sort them, sorry... self.entity_collection = sorted(sessions, key=lambda x: x.slot.start)
def load_from_db(self): self.entity_collection = {} sessions = Session.all().filter('event_key =', str(self.event_id)) # list of all rooms per day room_list = {} # list of all sessions, first per day, then organized by slot by_slot = {} # list of all sessions, first per day, then organized by room by_room = {} # list of all sessions, first by day, then by slot then by room by_slot_room = {} for session in sessions: # empty room? make a " " out of it. if not session.room: session.room = " " # get the slot from the slot_key try: slot = CSlot(session.slot_key).get() if not slot: continue except: # we won't be able to display this session anyway continue # get the day for the session day = slot.day.date # is day known? if not day in room_list: room_list[day] = [] by_slot[day] = {} by_room[day] = {} by_slot_room[day] = {} # is the slot already known? session.slot_txtkey = self.txtkey_for_slot(session.slot_key) if session.slot_txtkey not in by_slot[day]: by_slot[day][session.slot_txtkey] = [] by_slot_room[day][session.slot_txtkey] = {} # is the room already known? if session.room and (session.room not in room_list[day]): room_list[day].append(session.room) by_room[day][session.room] = [] # append the session to the three lists by_slot[day][session.slot_txtkey].append(session) by_room[day][session.room].append(session) # we want only one session at one time in one room by_slot_room[day][session.slot_txtkey][session.room] = session # list of all slots - even empty ones. we add an element count # for the number of sessions slot_list = {} date_list = [] for s in CSlotList(self.event_id).get(): s.date = s.day.date s.slot_txtkey = self.txtkey_for_slot(str(s.key())) if by_slot.has_key(s.date): if s.slot_txtkey in by_slot[s.date]: s.sessioncount = len(by_slot[s.date][s.slot_txtkey]) else: s.sessioncount = 0 else: s.sessioncount = 0 date_entry = {"date":s.date, "description":s.day.description} if date_entry not in date_list: date_list.append(date_entry) slot_list[s.date] = [] slot_list[s.date].append(s) # store the data! self.entity_collection['room_list'] = room_list self.entity_collection['slot_list'] = slot_list self.entity_collection['date_list'] = date_list self.entity_collection['by_slot'] = by_slot self.entity_collection['by_room'] = by_room self.entity_collection['by_slot_room'] = by_slot_room
def show_post(self): self.template = 'sessions_edit' user = users.get_current_user() event_id = self.request.get('event') event = CEvent(event_id).get() form = SessionsTracksForm(self.request.POST) # check permissions... if user and event and (user in event.organizers or users.is_current_user_admin()): # add the speakers for validation speakers = CSpeakerList(event_id).get() SessionFormHelper.add_speakers(form,speakers) slots = CSlotList(event_id).get() SessionFormHelper.add_slots(form, slots) tracks = CTrackList(event_id).get() for t in tracks: t.track = str(t.key()) SessionFormHelper.add_tracks(form, tracks) if form.validate(): # start with the tracks as they are used by sessions for i in range(0,1024): prefix = 'tracks-' + str(i) + '-' if self.request.get(prefix + 'name'): # is this a modification of an existing track or a new one? track_id = self.request.get(prefix + 'track') if track_id in [t.track for t in tracks]: track = [t for t in tracks if t.track == track_id][0] # delete from old_session tracks = [t for t in tracks if t.track != track_id] else: track = Track() # fill in values for old/new session track.name = self.request.get(prefix + 'name') track.color = self.request.get(prefix + 'color') track.abstract = self.request.get(prefix + 'abstract') upload_files = self.get_uploads(prefix + 'icon') if len(upload_files) > 0: blob_info = upload_files[0] track.icon = '%s' % blob_info.key() track.event_key = event_id # update track track.put() # end for # now delete all tracks not mentioned yet for t in tracks: t.delete() CTrackList.remove_from_cache(event_id) # now the sessions... sessions = CSessionList(event_id).get() for s in sessions: s.session = s.key() for i in range(0,1024): prefix = 'sessions-' + str(i) + '-' if self.request.get(prefix + 'title'): # is this a modification of an existing session or a new one? session_id = self.request.get(prefix + 'session') if session_id in [s.session for s in sessions]: session = [s for s in sessions if s.session == session_id][0] # delete from session sessions = [s for s in sessions if s.session != session_id] else: session = Session() # fill in values for old/new session session.title = self.request.get(prefix + 'title') session.abstract = self.request.get(prefix + 'abstract') session.slot_key = self.request.get(prefix + 'slot_key') session.level = self.request.get(prefix + 'level') session.room = self.request.get(prefix + 'room') session.track_key = self.request.get(prefix + 'track_key') session.live_url = self.request.get(prefix + 'live_url') session.youtube_url = self.request.get(prefix + 'youtube_url') session.event_key = event_id session.speakers_key = self.request.get_all(prefix + 'speakers_key') # update session session.put() # end for # now delete all sessions not mentioned yet for s in sessions: s.delete() # set info that modification was successful self.values['modified_successful'] = True # clear the cache for the event CSessionList.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/sessions/edit/" + event_id)) else: return self.redirect("/event/create"); self.values['current_navigation'] = 'sessions' self.values['form_url'] = blobstore.create_upload_url('/event/sessiontrack/upload') self.values['form'] = form