def update(self, event_id, service_id, data): data = self.validate(data, event_id, check_required=False) data_copy = data.copy() data_copy = self.fix_payload_post(event_id, data_copy) data = self._delete_fields(data) session = DataGetter.get_session( service_id) # session before any updates are made obj = ServiceDAO.update(self, event_id, service_id, data, validate=False) # session after update if 'state' in data: if data['state'] == 'pending' and session.state == 'draft': trigger_new_session_notifications(session.id, event_id=event_id) if (data['state'] == 'accepted' and session.state != 'accepted') \ or (data['state'] == 'rejected' and session.state != 'rejected'): trigger_session_state_change_notifications(obj, event_id=event_id, state=data['state']) if session.start_time != obj.start_time or session.end_time != obj.end_time: trigger_session_schedule_change_notifications(obj, event_id) for f in ['track', 'microlocation', 'speakers', 'session_type']: if f in data_copy: setattr(obj, f, data_copy[f]) obj = save_db_model(obj, SessionModel.__name__, event_id) return obj
def update(self, event_id, service_id, data): data = self.validate(data, event_id, check_required=False) data_copy = data.copy() data_copy = self.fix_payload_post(event_id, data_copy) data = self._delete_fields(data) session = DataGetter.get_session(service_id) # session before any updates are made obj = ServiceDAO.update(self, event_id, service_id, data, validate=False) # session after update if 'state' in data: if data['state'] == 'pending' and session.state == 'draft': trigger_new_session_notifications(session.id, event_id=event_id) if (data['state'] == 'accepted' and session.state != 'accepted') \ or (data['state'] == 'rejected' and session.state != 'rejected') \ or (data['state'] == 'confirmed' and session.state != 'confirmed'): trigger_session_state_change_notifications(obj, event_id=event_id, state=data['state']) if session.start_time != obj.start_time or session.end_time != obj.end_time: trigger_session_schedule_change_notifications(obj, event_id) for f in ['track', 'microlocation', 'speakers', 'session_type']: if f in data_copy: setattr(obj, f, data_copy[f]) obj = save_db_model(obj, SessionModel.__name__, event_id) return obj
def create(self, event_id, data, url): data = self.validate(data, event_id) payload = self.fix_payload_post(event_id, data) session, status_code, location = ServiceDAO.create(self, event_id, payload, url, validate=False) if session.state == 'pending': trigger_new_session_notifications(session.id, event_id=event_id) return session, status_code, location
def create(self, event_id, data, url): data = self.validate(data, event_id) payload = self.fix_payload_post(event_id, data) speakers = payload.pop('speakers', None) session, status_code, location = ServiceDAO.create(self, event_id, payload, url, validate=False) if speakers: session.speakers = speakers save_to_db(session) if not self.is_importing and session.state == 'pending': trigger_new_session_notifications(session.id, event_id=event_id) return session, status_code, location
def edit_session(request, session, speaker=None): with db.session.no_autoflush: form = request.form event_id = session.event_id slide_temp_url = form.get('slides_url') video_temp_url = form.get('video_url') audio_temp_url = form.get('audio_url') slide_file = '' video_file = '' audio_file = '' if slide_temp_url and slide_temp_url != session.slides: slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1]) if video_temp_url and video_temp_url != session.video: video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1]) if audio_temp_url and audio_temp_url != session.audio: audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1]) form_state = form.get('state', 'draft') if slide_temp_url != "" and slide_temp_url != session.slides and slide_file: slide_temp_url = upload(slide_file, UPLOAD_PATHS['sessions']['slides'].format( event_id=int(event_id), id=int(session.id) )) if audio_temp_url != "" and audio_temp_url != session.audio and audio_file: audio_temp_url = upload( audio_file, UPLOAD_PATHS['sessions']['audio'].format( event_id=int(event_id), id=int(session.id) )) if video_temp_url != "" and video_temp_url != session.video and video_file: video_temp_url = upload( video_file, UPLOAD_PATHS['sessions']['video'].format( event_id=int(event_id), id=int(session.id) )) session.slides = slide_temp_url session.audio = audio_temp_url session.video = video_temp_url if form_state == 'pending' and session.state != 'pending' and \ session.state != 'accepted' and session.state != 'rejected' and session.state != 'confirmed': session.state = 'pending' trigger_new_session_notifications(session.id, event_id=event_id) session.title = form.get('title', '') session.subtitle = form.get('subtitle', '') session.long_abstract = form.get('long_abstract', '') session.short_abstract = form.get('short_abstract', '') session.level = form.get('level', '') session.track_id = form.get('track', None) if form.get('track', None) != "" else None session.session_type_id = form.get('session_type', None) if form.get('session_type', None) != "" else None existing_speaker_ids = form.getlist("speakers[]") current_speaker_ids = [] existing_speaker_ids_by_email = [] save_to_db(session, 'Session Updated') if speaker: save_speaker(request, event_id=event_id, speaker=speaker) for existing_speaker in DataGetter.get_speaker_by_email(form.get("email")).all(): existing_speaker_ids_by_email.append(str(existing_speaker.id)) for current_speaker in session.speakers: current_speaker_ids.append(str(current_speaker.id)) for current_speaker_id in current_speaker_ids: if current_speaker_id \ not in existing_speaker_ids and current_speaker_id not in existing_speaker_ids_by_email: current_speaker = DataGetter.get_speaker(current_speaker_id) session.speakers.remove(current_speaker) db.session.commit() for existing_speaker_id in existing_speaker_ids: existing_speaker = DataGetter.get_speaker(existing_speaker_id) if existing_speaker not in session.speakers: session.speakers.append(existing_speaker) db.session.commit() record_activity('update_session', session=session, event_id=event_id) update_version(event_id, False, "sessions_ver")
def add_session_to_event(request, event_id, state=None, use_current_user=True): """ Session will be saved to database with proper Event id :param use_current_user: :param state: :param request: The request :param event_id: Session belongs to Event by event id """ form = request.form slide_temp_url = form.get('slides_url') video_temp_url = form.get('video_url') audio_temp_url = form.get('audio_url') slide_file = '' video_file = '' audio_file = '' if slide_temp_url: slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1]) if video_temp_url: video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1]) if audio_temp_url: audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1]) if not state: state = form.get('state', 'draft') event = DataGetter.get_event(event_id) new_session = Session(title=form.get('title', ''), subtitle=form.get('subtitle', ''), long_abstract=form.get('long_abstract', ''), start_time=event.start_time, end_time=event.start_time + timedelta(hours=1), event_id=event_id, short_abstract=form.get('short_abstract', ''), level=form.get('level', ''), comments=form.get('comments', ''), language=form.get('language', ''), state=state) if form.get('track', None) != "": new_session.track_id = form.get('track', None) if form.get('session_type', None) != "": new_session.session_type_id = form.get('session_type', None) speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first() speaker = save_speaker( request, event_id=event_id, speaker=speaker, user=login.current_user if use_current_user else None ) new_session.speakers.append(speaker) save_to_db(new_session, "Session saved") if state == 'pending': trigger_new_session_notifications(new_session.id, event=event) if slide_temp_url != "" and slide_file: slide_url = upload( slide_file, UPLOAD_PATHS['sessions']['slides'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.slides = slide_url if audio_temp_url != "" and audio_file: audio_url = upload( audio_file, UPLOAD_PATHS['sessions']['audio'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.audio = audio_url if video_temp_url != "" and video_file: video_url = upload( video_file, UPLOAD_PATHS['sessions']['video'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.video = video_url record_activity('create_session', session=new_session, event_id=event_id) update_version(event_id, False, 'sessions_ver') invite_emails = form.getlist("speakers[email]") for index, email in enumerate(invite_emails): if not string_empty(email): new_invite = Invite(event_id=event_id, session_id=new_session.id) hash = random.getrandbits(128) new_invite.hash = "%032x" % hash save_to_db(new_invite, "Invite saved") link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id, _external=True) Helper.send_email_invitation(email, new_session.title, link) # If a user is registered by the email, send a notification as well user = DataGetter.get_user_by_email(email, no_flash=True) if user: cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier) Helper.send_notif_invite_papers(user, event.name, cfs_link, link)
def add_session_to_event(request, event_id, state=None, use_current_user=True, no_name=False): """ Session will be saved to database with proper Event id :param use_current_user: :param state: :param request: The request :param event_id: Session belongs to Event by event id """ form = request.form slide_temp_url = form.get('slides_url') video_temp_url = form.get('video_url') audio_temp_url = form.get('audio_url') slide_file = '' video_file = '' audio_file = '' if slide_temp_url: slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1]) if video_temp_url: video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1]) if audio_temp_url: audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1]) if not state: state = form.get('state', 'draft') event = DataGetter.get_event(event_id) new_session = Session(title=form.get('title', ''), subtitle=form.get('subtitle', ''), long_abstract=form.get('long_abstract', ''), start_time=event.start_time, end_time=event.start_time + timedelta(hours=1), event_id=event_id, short_abstract=form.get('short_abstract', ''), level=form.get('level', ''), comments=form.get('comments', ''), language=form.get('language', ''), state=state) if form.get('track', None) != "": new_session.track_id = form.get('track', None) if form.get('session_type', None) != "": new_session.session_type_id = form.get('session_type', None) if form.get('email', '') != '': speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first() speaker = save_speaker( request, event_id=event_id, speaker=speaker, user=login.current_user if use_current_user else None, no_name=no_name ) new_session.speakers.append(speaker) save_to_db(new_session, "Session saved") if state == 'pending': trigger_new_session_notifications(new_session.id, event=event) if slide_temp_url != "" and slide_file: slide_url = upload( slide_file, UPLOAD_PATHS['sessions']['slides'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.slides = slide_url if audio_temp_url != "" and audio_file: audio_url = upload( audio_file, UPLOAD_PATHS['sessions']['audio'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.audio = audio_url if video_temp_url != "" and video_file: video_url = upload( video_file, UPLOAD_PATHS['sessions']['video'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.video = video_url record_activity('create_session', session=new_session, event_id=event_id) update_version(event_id, False, 'sessions_ver') invite_emails = form.getlist("speakers[email]") for index, email in enumerate(invite_emails): if not string_empty(email): new_invite = Invite(event_id=event_id, session_id=new_session.id) hash = random.getrandbits(128) new_invite.hash = "%032x" % hash save_to_db(new_invite, "Invite saved") link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id, _external=True) Helper.send_email_invitation(email, new_session.title, link) # If a user is registered by the email, send a notification as well user = DataGetter.get_user_by_email(email, no_flash=True) if user: cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier) Helper.send_notif_invite_papers(user, event.name, cfs_link, link)