Beispiel #1
0
def product_list():
    page = int(flask.request.args.get("page", "1"))
    search = flask.request.args.get("search", "").strip()
    search_norm = normalize_search(search)
    search_words = search_norm.split()

    if not search_words:
        # Predict page count
        num_products = db.session.query(sqlalchemy.func.count(
            model.Product.id)).one()[0]
        page_info = calc_pageinfo(page, num_products, PRODUCTS_PER_PAGE)

        products = db.session.query(model.Product) \
            .order_by(
                (model.Product.release_date >
                sqlalchemy.sql.functions.now()).asc()) \
            .order_by(
                sqlalchemy.sql.functions.coalesce(
                    model.Product.release_date,
                    datetime.date(1, 1, 1)).desc()) \
            .offset(page_info["from"]).limit(PRODUCTS_PER_PAGE)

    else:
        query = db.session.query(model.Product) \
            .order_by(
                sqlalchemy.sql.functions.char_length(model.Product.title))

        # Add a filter for each search word
        for word in search_words:
            word_cond = model.Product.title_norm.like("%{}%".format(word))
            if word.isdecimal():
                word_cond |= (model.Product.id == int(word))
            query = query.filter(word_cond)

        products = query.all()
        page_info = calc_pageinfo(page, len(products), PRODUCTS_PER_PAGE)
        products = products[page_info["from"]:page_info["to"]]

    if search:
        page_info["prev_link"] = flask.url_for("product_list",
                                               page=page_info["page"] - 1,
                                               search=search)
        page_info["next_link"] = flask.url_for("product_list",
                                               page=page_info["page"] + 1,
                                               search=search)
    else:
        page_info["prev_link"] = flask.url_for("product_list",
                                               page=page_info["page"] - 1)
        page_info["next_link"] = flask.url_for("product_list",
                                               page=page_info["page"] + 1)

    return flask.render_template("product_list.html",
                                 products=products,
                                 page_info=page_info,
                                 search=search)
def product_list():
    page = int(flask.request.args.get("page", "1"))
    limit = int(flask.request.args.get('limit', PRODUCTS_PER_PAGE))
    search = flask.request.args.get("search", "").strip()
    search_norm = normalize_search(search)

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    result = loop.run_until_complete(api.query_products(search_norm, limit, page))
    loop.close()

    page_info = calc_pageinfo(page, result['pages'], limit)

    if search != "":
        page_info["prev_link"] = flask.url_for(
            "product_list", page=page_info["page"] - 1, search=search, limit=limit)
        page_info["next_link"] = flask.url_for(
            "product_list", page=page_info["page"] + 1, search=search, limit=limit)
    else:
        page_info["prev_link"] = flask.url_for(
            "product_list", page=page_info["page"] - 1, limit=limit)
        page_info["next_link"] = flask.url_for(
            "product_list", page=page_info["page"] + 1, limit=limit)

    return flask.render_template(
        "product_list.html",
        products=result['products'],
        page_info=page_info,
        search=search
    )
def changelog_ext_page(view):
    page = int(flask.request.args.get("page", "1"))
    limit = int(flask.request.args.get("limit", "100"))

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    result = loop.run_until_complete(api.list_changes(limit, page))
    loop.close()

    page_info = calc_pageinfo(page, int(result['pages']), limit)

    changes = result['records']

    page_info["prev_link"] = flask.url_for(view, page=page_info["page"] - 1)
    page_info["next_link"] = flask.url_for(view, page=page_info["page"] + 1)

    recordgroups = []
    for groupkey, items in itertools.groupby(
            changes,
            key=lambda record:
        (record['dateTime'].split(' ')[0], record['game'])):
        recordgroups.append(list(items))

    if view == "changelog_atom":
        response = flask.make_response(
            flask.render_template("changelog_ext.xml",
                                  changes=recordgroups,
                                  page_info=page_info))
        response.mimetype = "application/atom+xml"
        return response

    else:
        return flask.render_template("changelog_ext.html",
                                     changes=recordgroups,
                                     page_info=page_info)
Beispiel #4
0
def changelog():
    page = int(flask.request.args.get("page", "1"))

    # Get total number of entries
    total_entries = db.session.query(
        ChangeRecord.timestamp  # just a placeholder
    ).group_by(ChangeRecord.timestamp, ChangeRecord.type_prim,
               ChangeRecord.prod_id).count()

    page_info = calc_pageinfo(page, total_entries, ITEMS_PER_PAGE)

    changes = db.session.query(
        ChangeRecord.timestamp, ChangeRecord.type_prim, ChangeRecord.prod_id,
        sqlalchemy.sql.functions.max(
            model.Product.title).label("title")).join(model.Product).group_by(
                ChangeRecord.timestamp, ChangeRecord.type_prim,
                ChangeRecord.prod_id).order_by(
                    ChangeRecord.timestamp.desc()).offset(
                        page_info["from"]).limit(ITEMS_PER_PAGE)

    page_info["prev_link"] = flask.url_for("changelog",
                                           page=page_info["page"] - 1)
    page_info["next_link"] = flask.url_for("changelog",
                                           page=page_info["page"] + 1)

    return flask.render_template("changelog.html",
                                 changes=changes,
                                 page_info=page_info)
Beispiel #5
0
def changelog():
    page = int(flask.request.args.get("page", "1"))

    cur = get_indexdb().cursor()
    # Get total number of entries
    cur.execute("SELECT COUNT(*) FROM changelog_summary;")
    total_entries = cur.fetchone()[0]

    page_info = calc_pageinfo(page, total_entries, ITEMS_PER_PAGE)

    cur.execute(
        "SELECT * FROM changelog_summary ORDER BY timestamp DESC LIMIT ? OFFSET ?;",
        (ITEMS_PER_PAGE, page_info["from"]))

    changelog_summaries = []
    for summary_res in cur:
        summary = model.IndexChangelogSummary(
            product_id=summary_res["product_id"],
            product_title=summary_res["product_title"],
            timestamp=datetime.datetime.fromtimestamp(summary_res["timestamp"],
                                                      datetime.timezone.utc),
            categories=summary_res["categories"].split(","))
        changelog_summaries.append(summary)

    page_info["prev_link"] = flask.url_for("changelog",
                                           page=page_info["page"] - 1)
    page_info["next_link"] = flask.url_for("changelog",
                                           page=page_info["page"] + 1)

    return flask.render_template("changelog.html",
                                 changes=changelog_summaries,
                                 page_info=page_info)
Beispiel #6
0
def changelog_ext_page(view):
    page = int(flask.request.args.get("page", "1"))
    total_entries = db.session.query(model.ChangeRecord.id).count()
    page_info = calc_pageinfo(page, total_entries, ITEMS_PER_PAGE)

    changes = db.session.query(model.ChangeRecord) \
        .options(orm.selectinload("product").selectinload("downloads")) \
        .order_by(model.ChangeRecord.id.desc()) \
        .offset(page_info["from"]).limit(ITEMS_PER_PAGE)

    page_info["prev_link"] = flask.url_for(view, page=page_info["page"] - 1)
    page_info["next_link"] = flask.url_for(view, page=page_info["page"] + 1)

    recordgroups = []
    for groupkey, items in itertools.groupby(
            changes, key=lambda record: (record.timestamp, record.prod_id)):
        recordgroups.append(list(items))

    if view == "changelog_atom":
        response = flask.make_response(
            flask.render_template("changelog_ext.xml",
                                  changes=recordgroups,
                                  page_info=page_info))
        response.mimetype = "application/atom+xml"
        return response

    else:
        return flask.render_template("changelog_ext.html",
                                     changes=recordgroups,
                                     page_info=page_info)
Beispiel #7
0
def changelog_ext_page(view):
    page = int(flask.request.args.get("page", "1"))

    cur = get_indexdb().cursor()
    # Get total number of entries
    cur.execute("SELECT COUNT(*) FROM changelog;")
    total_entries = cur.fetchone()[0]

    page_info = calc_pageinfo(page, total_entries, ITEMS_PER_PAGE)

    cur.execute(
        "SELECT * FROM changelog ORDER BY timestamp DESC LIMIT ? OFFSET ?;",
        (ITEMS_PER_PAGE, page_info["from"]))

    changes = []
    for change_res in cur:
        record_dict = json.loads(change_res["serialized_record"])
        change = model.IndexChange(
            id=change_res["product_id"],
            title=change_res["product_title"],
            timestamp=datetime.datetime.fromtimestamp(change_res["timestamp"],
                                                      datetime.timezone.utc),
            action=change_res["action"],
            category=change_res["category"],
            dl_type=change_res["dl_type"],
            bonus_type=change_res["bonus_type"],
            property_name=change_res["property_name"],
            record=class_from_json(model.ChangeRecord, record_dict))
        changes.append(change)

    recordgroups = []
    for groupkey, items in itertools.groupby(changes,
                                             key=lambda record:
                                             (record.timestamp, record.id)):
        recordgroups.append(list(items))

    page_info["prev_link"] = flask.url_for(view, page=page_info["page"] - 1)
    page_info["next_link"] = flask.url_for(view, page=page_info["page"] + 1)

    if view == "changelog_atom":
        response = flask.make_response(
            flask.render_template("changelog_ext.xml",
                                  changes=recordgroups,
                                  page_info=page_info))
        response.mimetype = "application/atom+xml"
        return response

    else:
        return flask.render_template("changelog_ext.html",
                                     changes=recordgroups,
                                     page_info=page_info)
def changelog():
    page = int(flask.request.args.get("page", "1"))
    limit = int(flask.request.args.get("limit", "100"))

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    result = loop.run_until_complete(api.list_changes(limit, page))
    loop.close()

    page_info = calc_pageinfo(page, int(result['pages']), limit)

    page_info['prev_link'] = flask.url_for("changelog",
                                           page=page_info['page'] - 1)
    page_info['next_link'] = flask.url_for("changelog",
                                           page=page_info['page'] + 1)

    return flask.render_template("changelog.html",
                                 changes=result['records'],
                                 page_info=page_info)
Beispiel #9
0
def product_list():
    page = int(flask.request.args.get("page", "1"))
    search = flask.request.args.get("search", "").strip()
    # Filter illegal characters and resulting empty strings
    search_words = list(
        filter(None, (normalize_search(word) for word in search.split())))

    cur = get_indexdb().cursor()
    if len(search) == 10 and search.isdecimal():
        return flask.redirect(flask.url_for("product_info", prod_id=search),
                              303)

    elif search_words:
        query_filters = []
        # Add a filter for each search word
        for word in search_words:
            # Should not be injectable because words are filtered
            word_cond = "search_title LIKE '%{}%'".format(word)
            query_filters.append(word_cond)
        filter_string = "WHERE " + " AND ".join(query_filters)
        order_string = "sale_rank DESC, LENGTH(title) ASC"
    else:
        filter_string = ""
        order_string = "sale_rank DESC"

    cur.execute("SELECT COUNT(*) FROM products {};".format(filter_string))
    num_products = cur.fetchone()[0]
    page_info = calc_pageinfo(page, num_products, PRODUCTS_PER_PAGE)

    cur.execute(
        "SELECT * FROM products {} ORDER BY {} LIMIT ? OFFSET ?;".format(
            filter_string, order_string),
        (PRODUCTS_PER_PAGE, page_info["from"]))
    products = []
    for prod_res in cur:
        idx_prod = model.IndexProduct(id=prod_res["product_id"],
                                      title=prod_res["title"],
                                      image_logo=prod_res["image_logo"],
                                      type=prod_res["product_type"],
                                      comp_systems=decompress_systems(
                                          prod_res["comp_systems"]),
                                      sale_rank=prod_res["sale_rank"],
                                      search_title=prod_res["search_title"])
        products.append(idx_prod)

    if search:
        page_info["prev_link"] = flask.url_for("product_list",
                                               page=page_info["page"] - 1,
                                               search=search)
        page_info["next_link"] = flask.url_for("product_list",
                                               page=page_info["page"] + 1,
                                               search=search)
    else:
        page_info["prev_link"] = flask.url_for("product_list",
                                               page=page_info["page"] - 1)
        page_info["next_link"] = flask.url_for("product_list",
                                               page=page_info["page"] + 1)

    return flask.render_template("product_list.html",
                                 products=products,
                                 page_info=page_info,
                                 search=search)