Ejemplo n.º 1
0
def save_institution():
    raw_data = request.form
    shortname = raw_data["shortname"]
    new = (raw_data.get("new") == "yes")
    resp, institution = can_edit_institution(shortname, new)
    if resp is not None:
        return resp

    data = {}
    for col in db.institutions.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.institutions.col_type[col])
            if col == 'admin':
                userdata = db.users.lookup(val)
                if userdata is None:
                    raise ValueError("%s must have account on this site" % val)
                if not userdata['phd']:
                    raise ValueError(
                        "%s must have a PhD to administer an institution" %
                        val)
            if col == '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:
            # TODO: this probably needs to be a redirect to change the URL?  We want to save the data the user entered.
            flash_error("Error processing %s: %s" % (col, err))
            institution = WebInstitution(shortname, data=raw_data)
            return render_template("edit_institution.html",
                                   institution=institution,
                                   institution_types=institution_types,
                                   timezones=timezones,
                                   title="Edit institution error",
                                   top_menu=basic_top_menu())
    new_version = WebInstitution(shortname, data=data)
    new_version.save()
    edittype = "created" if new else "edited"
    flash("Institution successfully %s!" % edittype)
    return redirect(url_for("show_institution", shortname=shortname), 301)
Ejemplo n.º 2
0
def search():
    info = to_dict(request.args, seminar_search_array=SemSearchArray(), takks_search_array=TalkSearchArray())
    if len(request.args) > 0:
        st = info.get("search_type", info.get("hst", "talks"))
        if st == "talks":
            return search_talks(info)
        elif st == "seminars":
            return search_seminars(info)
    menu = basic_top_menu()
    menu.pop(1)
    return render_template(
        "search.html",
        title="Search",
        info=info,
        categories=categories(),
        top_menu=menu,
        bread=None,
    )
Ejemplo n.º 3
0
def edit_institution():
    if request.method == 'POST':
        data = request.form
    else:
        data = request.args
    shortname = data.get("shortname", "")
    new = (data.get("new") == "yes")
    resp, institution = can_edit_institution(shortname, new)
    if resp is not None:
        return resp
    # Don't use locks for institutions since there's only one non-admin able to edit.
    title = "Create institution" if new else "Edit institution"
    return render_template("edit_institution.html",
                           institution=institution,
                           institution_types=institution_types,
                           timezones=timezones,
                           title=title,
                           top_menu=basic_top_menu())
Ejemplo n.º 4
0
def index():
    # TODO: use a join for the following query
    seminars = []
    conferences = []
    for semid in db.seminar_organizers.search({'email': current_user.email},
                                              'seminar_id'):
        seminar = WebSeminar(semid)
        if seminar.is_conference:
            conferences.append(seminar)
        else:
            seminars.append(seminar)
    menu = basic_top_menu()
    menu.pop(-3)
    return render_template("create_index.html",
                           seminars=seminars,
                           conferences=conferences,
                           top_menu=menu,
                           title="Create",
                           user_is_creator=current_user.is_creator())
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
def edit_seminar():
    if request.method == 'POST':
        data = request.form
    else:
        data = request.args
    shortname = data.get("shortname", "")
    new = (data.get("new") == "yes")
    resp, seminar = can_edit_seminar(shortname, new)
    if resp is not None:
        return resp
    lock = get_lock(shortname, data.get("lock"))
    title = "Create seminar" if new else "Edit seminar"
    return render_template("edit_seminar.html",
                           seminar=seminar,
                           title=title,
                           top_menu=basic_top_menu(),
                           categories=categories(),
                           institutions=institutions(),
                           weekdays=weekdays,
                           timezones=timezones,
                           lock=lock)
Ejemplo n.º 7
0
def edit_seminar_schedule():
    # It would be good to have a version of this that worked for a conference, but that's a project for later
    if request.method == 'POST':
        data = request.form
    else:
        data = request.args
    shortname = data.get("shortname", "")
    resp, seminar = can_edit_seminar(shortname, new=False)
    if resp is not None:
        return resp
    resp, seminar, all_dates, by_date = make_date_data(seminar)
    if resp is not None:
        return resp
    title = "Edit seminar schedule"
    return render_template("edit_seminar_schedule.html",
                           seminar=seminar,
                           all_dates=all_dates,
                           by_date=by_date,
                           weekdays=weekdays,
                           title=title,
                           top_menu=basic_top_menu())
Ejemplo n.º 8
0
def about():
    menu = basic_top_menu()
    menu.pop(4)
    return render_template("about.html", title="About", top_menu=menu)