Exemple #1
0
def test_user_search_ordering(db):
    config = CharSettings({'use-only-tag-blacklist'}, {}, {})
    db_utils.create_user("user_aa", username="******", config=config)
    db_utils.create_user("user_ba", username="******", config=config)
    db_utils.create_user("user_Ab", username="******", config=config)
    db_utils.create_user("user_Bb", username="******", config=config)

    results = search.select_users(u"user")
    assert [user["title"] for user in results] == ["user_aa", "user_Ab", "user_ba", "user_Bb"]
Exemple #2
0
def test_user_search(db, term, n_results):
    config = CharSettings({'use-only-tag-blacklist'}, {}, {})
    db_utils.create_user("Sam Peacock", username="******", config=config)
    db_utils.create_user("LionCub", username="******", config=config)
    db_utils.create_user("Samantha Wildlife", username="******", config=config)
    db_utils.create_user("Ryan Otherkin", username="******", config=config)
    db_utils.create_user("Pawsome", username="******", config=config)
    db_utils.create_user("Twisted Calvin", username="******", config=config)
    db_utils.create_user("JasonAG", username="******", config=config)
    db_utils.create_user("Twisted Mindset", username="******", config=config)
    db_utils.create_user("Martha", config=config)

    results = search.select_users(term)
    assert len(results) == n_results
Exemple #3
0
def search_(request):
    rating = define.get_rating(request.userid)

    form = request.web_input(q="", find="", within="", rated=[], cat="", subcat="", backid="", nextid="")

    page = define.common_page_start(request.userid, title="Browse and search")

    if form.q:
        find = form.find

        if find not in ("submit", "char", "journal", "user"):
            find = "submit"

        q = form.q.strip()
        search_query = search.Query.parse(q, find)

        meta = {
            "q": q,
            "find": search_query.find,
            "within": form.within,
            "rated": set('gap') & set(form.rated),
            "cat": int(form.cat) if form.cat else None,
            "subcat": int(form.subcat) if form.subcat else None,
            "backid": int(form.backid) if form.backid else None,
            "nextid": int(form.nextid) if form.nextid else None,
        }

        if search_query.find == "user":
            query = search.select_users(q)
            next_count = back_count = 0
        else:
            search_query.ratings.update(ratings.CHARACTER_MAP[rating_code].code for rating_code in meta["rated"])

            query, next_count, back_count = search.select(
                userid=request.userid,
                rating=rating,
                limit=63,
                search=search_query,
                within=meta["within"],
                cat=meta["cat"],
                subcat=meta["subcat"],
                backid=meta["backid"],
                nextid=meta["nextid"])

        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "search"},
            # Search metadata
            meta,
            # Search results
            query,
            next_count,
            back_count,
            # Submission subcategories
            macro.MACRO_SUBCAT_LIST,
            search.COUNT_LIMIT,
        ]))
    elif form.find:
        query = search.browse(request.userid, rating, 66, form)

        meta = {
            "find": form.find,
            "cat": int(form.cat) if form.cat else None,
        }

        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "browse"},
            # Search metadata
            meta,
            # Search results
            query,
            0,
            0,
        ]))
    else:
        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "summary"},
            # Search metadata
            None,
            # Search results
            {
                "submit": search.browse(request.userid, rating, 22, form, find="submit"),
                "char": search.browse(request.userid, rating, 22, form, find="char"),
                "journal": search.browse(request.userid, rating, 22, form, find="journal"),
            },
        ]))

    return Response(define.common_page_end(request.userid, page, options={'search'}))
Exemple #4
0
def search_(request):
    rating = define.get_rating(request.userid)

    form = request.web_input(q="", find="", within="", rated=[], cat="", subcat="", backid="", nextid="")

    page = define.common_page_start(request.userid, title="Browse and search")

    if form.q:
        find = form.find

        if find not in ("submit", "char", "journal", "user"):
            find = "submit"

        q = form.q.strip()
        search_query = search.Query.parse(q, find)

        meta = {
            "q": q,
            "find": search_query.find,
            "within": form.within,
            "rated": set('gap') & set(form.rated),
            "cat": int(form.cat) if form.cat else None,
            "subcat": int(form.subcat) if form.subcat else None,
            "backid": int(form.backid) if form.backid else None,
            "nextid": int(form.nextid) if form.nextid else None,
        }

        if search_query.find == "user":
            query = search.select_users(q)
            next_count = back_count = 0
        else:
            search_query.ratings.update(ratings.CHARACTER_MAP[rating_code].code for rating_code in meta["rated"])

            query, next_count, back_count = search.select(
                userid=request.userid,
                rating=rating,
                limit=63,
                search=search_query,
                within=meta["within"],
                cat=meta["cat"],
                subcat=meta["subcat"],
                backid=meta["backid"],
                nextid=meta["nextid"])

        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "search"},
            # Search metadata
            meta,
            # Search results
            query,
            next_count,
            back_count,
            # Submission subcategories
            macro.MACRO_SUBCAT_LIST,
            search.COUNT_LIMIT,
        ]))
    elif form.find:
        query = search.browse(request.userid, rating, 66, form)

        meta = {
            "find": form.find,
            "cat": int(form.cat) if form.cat else None,
        }

        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "browse"},
            # Search metadata
            meta,
            # Search results
            query,
            0,
            0,
        ]))
    else:
        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "summary"},
            # Search metadata
            None,
            # Search results
            {
                "submit": search.browse(request.userid, rating, 22, form, find="submit"),
                "char": search.browse(request.userid, rating, 22, form, find="char"),
                "journal": search.browse(request.userid, rating, 22, form, find="journal"),
            },
        ]))

    return Response(define.common_page_end(request.userid, page, options={'search'}))
Exemple #5
0
def search_(request):
    rating = define.get_rating(request.userid)

    q = request.params.get('q')
    find = request.params.get('find')
    within = request.params.get('within', '')
    rated = request.params.getall('rated')
    cat = request.params.get('cat')
    subcat = request.params.get('subcat')
    backid = request.params.get('backid')
    nextid = request.params.get('nextid')

    page = define.common_page_start(request.userid, title="Browse and search")

    if q:
        if find not in ("submit", "char", "journal", "user"):
            find = "submit"

        q = q.strip()
        search_query = search.Query.parse(q, find)

        meta = {
            "q": q,
            "find": search_query.find,
            "within": within,
            "rated": set('gap') & set(rated),
            "cat": int(cat) if cat else None,
            "subcat": int(subcat) if subcat else None,
            "backid": int(backid) if backid else None,
            "nextid": int(nextid) if nextid else None,
        }

        if search_query.find == "user":
            query = search.select_users(q)
            next_count = back_count = 0
        else:
            search_query.ratings.update(ratings.CHARACTER_MAP[rating_code].code for rating_code in meta["rated"])

            query, next_count, back_count = search.select(
                userid=request.userid,
                rating=rating,
                limit=63,
                search=search_query,
                within=meta["within"],
                cat=meta["cat"],
                subcat=meta["subcat"],
                backid=meta["backid"],
                nextid=meta["nextid"])

        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "search"},
            # Search metadata
            meta,
            # Search results
            query,
            next_count,
            back_count,
            # Submission subcategories
            macro.MACRO_SUBCAT_LIST,
            search.COUNT_LIMIT,
        ]))
    elif find:
        query = search.browse(
            userid=request.userid,
            rating=rating,
            limit=66,
            find=find,
            cat=cat,
            backid=backid,
            nextid=nextid,
        )

        meta = {
            "find": find,
            "cat": int(cat) if cat else None,
        }

        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "browse"},
            # Search metadata
            meta,
            # Search results
            query,
            0,
            0,
        ]))
    else:
        backid = define.get_int(backid)
        nextid = define.get_int(nextid)
        page.append(define.render("etc/search.html", [
            # Search method
            {"method": "summary"},
            # Search metadata
            None,
            # Search results
            {
                "submit": search.browse(
                    userid=request.userid,
                    rating=rating,
                    limit=22,
                    find="submit",
                    cat=cat,
                    backid=backid,
                    nextid=nextid
                ),
                "char": search.browse(
                    userid=request.userid,
                    rating=rating,
                    limit=22,
                    find="char",
                    cat=cat,
                    backid=backid,
                    nextid=nextid
                ),
                "journal": search.browse(
                    userid=request.userid,
                    rating=rating,
                    limit=22,
                    find="journal",
                    cat=cat,
                    backid=backid,
                    nextid=nextid
                ),
            },
        ]))

    return Response(define.common_page_end(request.userid, page, options={'search'}))