Exemplo n.º 1
0
def ctx_proc_userdata():
    # insert an empty info={} as default
    # set the body class to some default, blueprints should
    # overwrite it with their name, using @<blueprint_object>.context_processor
    # see http://flask.pocoo.org/docs/api/?highlight=context_processor#flask.Blueprint.context_processor
    vars = {'info': {}, 'body_class': ''}

    # insert the default bread crumb hierarchy
    # overwrite this variable when you want to customize it
    # For example, [ ('Bread', '.'), ('Crumb', '.'), ('Hierarchy', '.')]
    vars['bread'] = None

    # default title
    vars['title'] = r'Bean Theory'

    # LMFDB version number displayed in footer
    vars['version'] = SEMINARS_VERSION

    # meta_description appears in the meta tag "description"
    vars[
        'meta_description'] = r'Welcome to Bean Theory, a listing of mathematical research seminars and conferences.'
    vars[
        'shortthanks'] = r'This project is supported by <a href="%s">grants</a> from the US National Science Foundation, the UK Engineering and Physical Sciences Research Council, and the Simons Foundation.' % (
            url_for('acknowledgment') + "#sponsors")
    vars[
        'feedbackpage'] = r"https://docs.google.com/spreadsheet/viewform?formkey=dDJXYXBleU1BMTFERFFIdjVXVmJqdlE6MQ"
    vars['LINK_EXT'] = lambda a, b: '<a href="%s" target="_blank">%s</a>' % (b,
                                                                             a)

    # debug mode?
    vars['DEBUG'] = is_debug_mode()

    vars['categories'] = categories()

    return vars
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 def make_error(err):
     flash_error("Error processing %s: %s" % (col, err))
     seminar = WebSeminar(shortname, data=raw_data)
     return render_template("edit_seminar.html",
                            seminar=seminar,
                            title="Edit seminar error",
                            top_menu=basic_top_menu(),
                            categories=categories(),
                            institutions=institutions(),
                            lock=None)
Exemplo n.º 4
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,
    )
Exemplo 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)
Exemplo 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)
Exemplo n.º 7
0

def seminars_parser(info, query):
    parse_category(info, query)
    parse_institution_sem(info, query)
    parse_online(info, query)
    parse_substring(info, query, "keywords", "keywords")
    parse_access(info, query)

    parse_substring(info, query, "name", "name")


# Common boxes
## categories
category = SelectBox(
    name="category", label="Category", options=[("", "")] + categories()
)
## pick institution where it is held


def institutions_shortnames():
    return sorted(db.institutions.search({}, projection="shortname"))


institution = SelectBox(
    name="institution",
    label="Institution",
    options=[("", ""), ("No institution", "None"),]
    + [(elt, elt) for elt in institutions_shortnames()],
)
## online only?