예제 #1
0
파일: search.py 프로젝트: wnku/newparp
def search_save():

    new_details = validate_character_form(request.form)
    g.user.search_character_id = new_details["search_character_id"]
    g.user.name = new_details["name"]
    g.user.acronym = new_details["acronym"]
    g.user.color = new_details["color"]
    g.user.quirk_prefix = new_details["quirk_prefix"]
    g.user.quirk_suffix = new_details["quirk_suffix"]
    g.user.case = new_details["case"]
    g.user.replacements = new_details["replacements"]
    g.user.regexes = new_details["regexes"]

    if request.form["style"] in User.search_style.type.enums:
        g.user.search_style = request.form["style"]

    level_filter = set()
    for level in g.user.level_options:
        if level in request.form:
            level_filter.add(level)
    if not level_filter:
        level_filter.add("sfw")
    g.user.search_levels = level_filter

    search_filters = set()
    for search_filter in request.form.getlist("search_filter"):
        search_filter = search_filter.strip().lower()
        if search_filter:
            search_filters.add(search_filter)
        if len(search_filters) == 200:
            break
    g.user.search_filters = sorted(list(search_filters))

    g.user.search_age_restriction = "age_restriction" in request.form

    all_character_ids = set(_[0] for _ in g.db.query(SearchCharacter.id).all())

    # Picky checkboxes
    g.db.query(SearchCharacterChoice).filter(
        SearchCharacterChoice.user_id == g.user.id).delete()
    if "use_picky" in request.form:
        for key in list(request.form.keys()):
            if not key.startswith("picky_"):
                continue
            try:
                character_id = int(key[6:])
            except:
                continue
            if character_id not in all_character_ids:
                continue
            g.db.add(
                SearchCharacterChoice(user_id=g.user.id,
                                      search_character_id=character_id))

    return redirect(url_for("rp_search"))
예제 #2
0
파일: search.py 프로젝트: MSPARP/newparp
def search_save():

    new_details = validate_character_form(request.form)
    g.user.search_character_id = new_details["search_character_id"]
    g.user.name = new_details["name"]
    g.user.acronym = new_details["acronym"]
    g.user.color = new_details["color"]
    g.user.quirk_prefix = new_details["quirk_prefix"]
    g.user.quirk_suffix = new_details["quirk_suffix"]
    g.user.case = new_details["case"]
    g.user.replacements = new_details["replacements"]
    g.user.regexes = new_details["regexes"]

    if request.form["style"] in User.search_style.type.enums:
        g.user.search_style = request.form["style"]

    level_filter = set()
    for level in g.user.level_options:
        if level in request.form:
            level_filter.add(level)
    if not level_filter:
        level_filter.add("sfw")
    g.user.search_levels = level_filter

    search_filters = set()
    for search_filter in request.form.getlist("search_filter"):
        search_filter = search_filter.strip().lower()
        if search_filter:
            search_filters.add(search_filter)
        if len(search_filters) == 200:
            break
    g.user.search_filters = sorted(list(search_filters))

    g.user.search_age_restriction = "age_restriction" in request.form

    all_character_ids = set(_[0] for _ in g.db.query(SearchCharacter.id).all())

    # Picky checkboxes
    g.db.query(SearchCharacterChoice).filter(SearchCharacterChoice.user_id == g.user.id).delete()
    if "use_picky" in request.form:
        for key in list(request.form.keys()):
            if not key.startswith("picky_"):
                continue
            try:
                character_id = int(key[6:])
            except:
                continue
            if character_id not in all_character_ids:
                continue
            g.db.add(SearchCharacterChoice(user_id=g.user.id, search_character_id=character_id))

    return redirect(url_for("rp_search"))
예제 #3
0
def save_search_character(id):
    character = search_character_query(id)
    new_details = validate_character_form(request.form)
    # Ignore a blank title.
    if new_details["title"] != "":
        character.title = new_details["title"]
    character.name = new_details["name"]
    character.acronym = new_details["acronym"]
    character.color = new_details["color"]
    character.quirk_prefix = new_details["quirk_prefix"]
    character.quirk_suffix = new_details["quirk_suffix"]
    character.case = new_details["case"]
    character.replacements = new_details["replacements"]
    character.regexes = new_details["regexes"]
    character.text_preview = request.form["text_preview"]
    # Remember to clear the cache
    g.redis.delete("search_character:%s" % id)
    return redirect(url_for("rp_search_character_list"))
예제 #4
0
def save_search_character(id):
    character = search_character_query(id)
    new_details = validate_character_form(request.form)
    # Ignore a blank title.
    if new_details["title"] != "":
        character.title = new_details["title"]
    character.name = new_details["name"]
    character.acronym = new_details["acronym"]
    character.color = new_details["color"]
    character.quirk_prefix = new_details["quirk_prefix"]
    character.quirk_suffix = new_details["quirk_suffix"]
    character.case = new_details["case"]
    character.replacements = new_details["replacements"]
    character.regexes = new_details["regexes"]
    character.text_preview = request.form["text_preview"]
    # Remember to clear the cache
    g.redis.delete("search_character:%s" % id)
    return redirect(url_for("rp_search_character_list"))
예제 #5
0
def new_search_character_post():
    new_details = validate_character_form(request.form)
    del new_details["search_character_id"]
    del new_details["shortcut"]
    try:
        group = g.db.query(SearchCharacterGroup).filter(
            SearchCharacterGroup.id == request.form["group_id"], ).one()
    except NoResultFound:
        abort(404)
    order = (g.db.query(func.max(SearchCharacter.order)).filter(
        SearchCharacter.group_id == group.id).scalar() or 0) + 1
    new_search_character = SearchCharacter(
        group_id=group.id,
        order=order,
        text_preview=request.form.get(
            "text_preview", SearchCharacter.text_preview.default.arg),
        **new_details)
    g.db.add(new_search_character)
    return redirect(url_for("rp_search_character_list"))
예제 #6
0
파일: chat_api.py 프로젝트: wnku/newparp
def save():

    # Remember old values so we can check if they've changed later.
    old_name = g.chat_user.name
    old_acronym = g.chat_user.acronym
    old_color = g.chat_user.color

    new_details = validate_character_form(request.form)
    g.chat_user.search_character_id = new_details["search_character_id"]
    g.chat_user.name = new_details["name"]
    g.chat_user.acronym = new_details["acronym"]
    g.chat_user.color = new_details["color"]
    g.chat_user.quirk_prefix = new_details["quirk_prefix"]
    g.chat_user.quirk_suffix = new_details["quirk_suffix"]
    g.chat_user.case = new_details["case"]
    g.chat_user.replacements = new_details["replacements"]
    g.chat_user.regexes = new_details["regexes"]

    # Send a message if name or acronym has changed.
    if g.chat_user.name != old_name or g.chat_user.acronym != old_acronym:
        if g.chat_user.computed_group == "silent":
            send_userlist(g.user_list, g.db, g.chat)
        else:
            send_message(
                g.db, g.redis,
                Message(
                    chat_id=g.chat.id,
                    user_id=g.user.id,
                    type="user_info",
                    name=g.chat_user.name,
                    text=("%s [%s] is now %s [%s].") % (
                        old_name,
                        old_acronym,
                        g.chat_user.name,
                        g.chat_user.acronym,
                    ),
                ), g.user_list)
    # Just refresh the user list if the color has changed.
    elif g.chat_user.color != old_color:
        send_userlist(g.user_list, g.db, g.chat)

    return jsonify(g.chat_user.to_dict(include_options=True))
예제 #7
0
def save():

    # Remember old values so we can check if they've changed later.
    old_name = g.chat_user.name
    old_acronym = g.chat_user.acronym
    old_color = g.chat_user.color

    new_details = validate_character_form(request.form)
    g.chat_user.search_character_id = new_details["search_character_id"]
    g.chat_user.name = new_details["name"]
    g.chat_user.acronym = new_details["acronym"]
    g.chat_user.color = new_details["color"]
    g.chat_user.quirk_prefix = new_details["quirk_prefix"]
    g.chat_user.quirk_suffix = new_details["quirk_suffix"]
    g.chat_user.case = new_details["case"]
    g.chat_user.replacements = new_details["replacements"]
    g.chat_user.regexes = new_details["regexes"]

    # Send a message if name or acronym has changed.
    if g.chat_user.name != old_name or g.chat_user.acronym != old_acronym:
        if g.chat_user.computed_group == "silent":
            send_userlist(g.db, g.redis, g.chat)
        else:
            send_message(g.db, g.redis, Message(
                chat_id=g.chat.id,
                user_id=g.user.id,
                type="user_info",
                name=g.chat_user.name,
                text=("%s [%s] is now %s [%s].") % (
                    old_name, old_acronym,
                    g.chat_user.name, g.chat_user.acronym,
                ),
            ))
    # Just refresh the user list if the color has changed.
    elif g.chat_user.color != old_color:
        send_userlist(g.db, g.redis, g.chat)

    return jsonify(g.chat_user.to_dict(include_options=True))
예제 #8
0
def new_search_character_post():
    new_details = validate_character_form(request.form)
    del new_details["search_character_id"]
    del new_details["shortcut"]
    try:
        group = g.db.query(SearchCharacterGroup).filter(
            SearchCharacterGroup.id == request.form["group_id"],
        ).one()
    except NoResultFound:
        abort(404)
    order = (
        g.db.query(func.max(SearchCharacter.order))
        .filter(SearchCharacter.group_id == group.id)
        .scalar() or 0
    ) + 1
    new_search_character = SearchCharacter(
        group_id=group.id,
        order=order,
        text_preview=request.form.get("text_preview", SearchCharacter.text_preview.default.arg),
        **new_details
    )
    g.db.add(new_search_character)
    return redirect(url_for("rp_search_character_list"))
예제 #9
0
def new_character_post():
    new_details = validate_character_form(request.form)
    g.db.add(Character(user_id=g.user.id, **new_details))
    return redirect(url_for("rp_character_list"))
예제 #10
0
파일: characters.py 프로젝트: wnku/newparp
def new_character_post():
    new_details = validate_character_form(request.form)
    g.db.add(Character(user_id=g.user.id, **new_details))
    return redirect(url_for("rp_character_list"))