def save_talk(): raw_data = request.form resp, seminar, talk = can_edit_talk(raw_data.get("seminar_id", ""), raw_data.get("seminar_ctr", ""), raw_data.get("token", "")) if resp is not None: return resp data = { 'seminar_id': talk.seminar_id, 'token': talk.token, 'display': talk.display, # could be being edited by anonymous user } if talk.new: curmax = talks_max('seminar_ctr', {'seminar_id': talk.seminar_id}) if curmax is None: curmax = 0 data['seminar_ctr'] = curmax + 1 else: data['seminar_ctr'] = talk.seminar_ctr for col in db.talks.search_cols: if col in data: continue try: val = raw_data.get(col) if not val: data[col] = None else: data[col] = process_user_input(val, db.talks.col_type[col]) if col == 'speaker_homepage' and val and not val.startswith( "http"): data[col] = "http://" + data[col] if col == "access" and val not in ["open", "users", "endorsed"]: raise ValueError("Invalid access type") except Exception as err: flash_error("Error processing %s: %s", [col, err]) talk = WebTalk(talk.seminar_id, talk.seminar_ctr, data=raw_data) title = "Create talk" if talk.new else "Edit talk" return render_template("edit_talk.html", talk=talk, seminar=seminar, title=title, top_menu=basic_top_menu(), categories=categories(), institutions=institutions(), timezones=timezones) new_version = WebTalk(talk.seminar_id, data['seminar_ctr'], data=data) if new_version == talk: flash("No changes made to talk.") else: new_version.save() edittype = "created" if talk.new else "edited" flash("Talk successfully %s!" % edittype) return redirect( url_for("show_talk", semid=new_version.seminar_id, talkid=new_version.seminar_ctr), 301)
def edit_talk(): if request.method == "POST": data = request.form else: data = request.args token = data.get("token", "") resp, talk = can_edit_talk(data.get("seminar_id", ""), data.get("seminar_ctr", ""), token) if resp is not None: return resp if token: # Also want to override top menu from seminars.utils import top_menu menu = top_menu() menu[2] = (url_for("create.index"), "", "Manage") extras = {"top_menu": menu} else: extras = {} # The seminar schedule page adds in a date and times if data.get("date", "").strip(): tz = talk.seminar.tz date = process_user_input(data["date"], "date", "date", tz) try: # TODO: clean this up start_time = process_user_input(data.get("start_time"), "start_time", "time", tz) end_time = process_user_input(data.get("end_time"), "end_time", "time", tz) start_time = localize_time(datetime.combine(date, start_time), tz) end_time = localize_time(datetime.combine(date, end_time), tz) except ValueError: return redirect( url_for(".edit_seminar_schedule", shortname=talk.seminar_id), 302) talk.start_time = start_time talk.end_time = end_time # lock = get_lock(seminar_id, data.get("lock")) title = "Create talk" if talk.new else "Edit talk" return render_template("edit_talk.html", talk=talk, seminar=talk.seminar, title=title, section="Manage", subsection="edittalk", institutions=institutions(), timezones=timezones, token=token, **extras)
def edit_talk(): if request.method == 'POST': data = request.form else: data = request.args resp, seminar, talk = can_edit_talk(data.get("seminar_id", ""), data.get("seminar_ctr", ""), data.get("token", "")) if resp is not None: return resp #lock = get_lock(seminar_id, data.get("lock")) title = "Create talk" if talk.new else "Edit talk" return render_template("edit_talk.html", talk=talk, seminar=seminar, title=title, top_menu=basic_top_menu(), categories=categories(), institutions=institutions(), timezones=timezones)
def save_talk(): raw_data = request.form token = raw_data.get("token", "") resp, talk = can_edit_talk(raw_data.get("seminar_id", ""), raw_data.get("seminar_ctr", ""), token) if resp is not None: return resp errmsgs = [] data = { "seminar_id": talk.seminar_id, "token": talk.token, "display": talk.display, # could be being edited by anonymous user } if talk.new: curmax = talks_max("seminar_ctr", {"seminar_id": talk.seminar_id}, include_deleted=True) if curmax is None: curmax = 0 data["seminar_ctr"] = curmax + 1 else: data["seminar_ctr"] = talk.seminar_ctr default_tz = talk.seminar.timezone if not default_tz: default_tz = "UTC" data["timezone"] = tz = raw_data.get("timezone", default_tz) tz = pytz.timezone(tz) for col in db.talks.search_cols: if col in data: continue typ = db.talks.col_type[col] try: val = raw_data.get(col, "") data[ col] = None # make sure col is present even if process_user_input fails data[col] = process_user_input(val, col, typ, tz) if col == "access" and data[col] not in [ "open", "users", "endorsed" ]: errmsgs.append( format_errmsg("Access type %s invalid", data[col])) except Exception as err: # should only be ValueError's but let's be cautious errmsgs.append(format_input_errmsg(err, val, col)) if not data["speaker"]: errmsgs.append( "Speaker name cannot be blank -- use TBA if speaker not chosen.") if data["start_time"] is None or data["end_time"] is None: errmsgs.append("Talks must have both a start and end time.") data["topics"] = clean_topics(data.get("topics")) data["language"] = clean_language(data.get("language")) data["subjects"] = clean_subjects(data.get("subjects")) if not data["subjects"]: errmsgs.append("Please select at least one subject") # Don't try to create new_version using invalid input if errmsgs: return show_input_errors(errmsgs) else: # to make it obvious that these two statements should be together new_version = WebTalk(talk.seminar_id, data=data) # Warnings sanity_check_times(new_version.start_time, new_version.end_time) if "zoom" in data["video_link"] and not "rec" in data["video_link"]: flash_warning( "Recorded video link should not be used for Zoom meeting links; be sure to use Livestream link for meeting links." ) if not data["topics"]: flash_warning( "This talk has no topics, and thus will only be visible to users when they disable their topics filter." ) if new_version == talk: flash("No changes made to talk.") else: new_version.save() edittype = "created" if talk.new else "edited" flash("Talk successfully %s!" % edittype) edit_kwds = dict(seminar_id=new_version.seminar_id, seminar_ctr=new_version.seminar_ctr) if token: edit_kwds["token"] = token else: edit_kwds.pop("token", None) return redirect(url_for(".edit_talk", **edit_kwds), 302)
def save_talk(): raw_data = request.form token = raw_data.get("token", "") resp, talk = can_edit_talk(raw_data.get("seminar_id", ""), raw_data.get("seminar_ctr", ""), token) if resp is not None: return resp def make_error(talk, col=None, err=None): if err is not None: flash_error("Error processing %s: {0}".format(err), col) talk = WebTalk(talk.seminar_id, talk.seminar_ctr, data=raw_data) title = "Create talk error" if talk.new else "Edit talk error" return render_template( "edit_talk.html", talk=talk, seminar=talk.seminar, title=title, section="Manage", subsection="edittalk", institutions=institutions(), timezones=timezones, ) data = { "seminar_id": talk.seminar_id, "token": talk.token, "display": talk.display, # could be being edited by anonymous user } if talk.new: curmax = talks_max("seminar_ctr", {"seminar_id": talk.seminar_id}) if curmax is None: curmax = 0 data["seminar_ctr"] = curmax + 1 else: data["seminar_ctr"] = talk.seminar_ctr default_tz = talk.seminar.timezone if not default_tz: default_tz = "UTC" data["timezone"] = tz = raw_data.get("timezone", default_tz) tz = pytz.timezone(tz) for col in db.talks.search_cols: if col in data: continue try: val = raw_data.get(col, "").strip() if not val: data[col] = None else: data[col] = process_user_input(val, db.talks.col_type[col], tz=tz) if col == "speaker_homepage" and val and not val.startswith( "http"): data[col] = "http://" + data[col] if col == "access" and val not in ["open", "users", "endorsed"]: raise ValueError("Invalid access type") except Exception as err: return make_error(talk, col, err) data["topics"] = clean_topics(data.get("topics")) data["language"] = clean_language(data.get("language")) new_version = WebTalk(talk.seminar_id, data["seminar_ctr"], data=data) if check_time(new_version.start_time, new_version.end_time, check_past=True): return make_error(talk) if new_version == talk: flash("No changes made to talk.") else: new_version.save() edittype = "created" if talk.new else "edited" flash("Talk successfully %s!" % edittype) edit_kwds = dict(seminar_id=new_version.seminar_id, seminar_ctr=new_version.seminar_ctr) if token: edit_kwds["token"] = token else: edit_kwds.pop("token", None) return redirect(url_for(".edit_talk", **edit_kwds), 301)