# Path: gogdb/views/pagination.py
# def calc_pageinfo(page, num_products, items_per_page):
#     num_pages = int(math.ceil(num_products / items_per_page))
#     page = min(max(page, 1), num_pages)
#     offset = (page - 1) * items_per_page
#     page_info = {
#         "is_first": page == 1,
#         "is_last": page == num_pages,
#         "page": page,
#         "num_pages": num_pages,
#         "from": offset,
#         "to": offset + items_per_page,
#         "prev_link": "", # Filled in later
#         "next_link": ""
#     }
#     return page_info
# 
# Path: gogdb/core/normalization.py
# def normalize_search(search_str):
#     if search_str is None:
#         return ""
#     return "".join(c for c in search_str.lower() if c in NORMALIZED_CHARS)
# 
# def decompress_systems(compressed):
#     systems = []
#     decompress_map = {
#         "w": "windows",
#         "l": "linux",
#         "o": "osx"
#     }
#     for letter in compressed:
#         systems.append(decompress_map[letter])
#     return systems
# 
# Path: gogdb/application/datasources.py
# def get_indexdb():
#     if "indexdb" not in flask.g:
#         storagedb = get_storagedb()
#         index_path = storagedb.path_indexdb()
#         flask.g.indexdb = sqlite3.connect(index_path)
#         flask.g.indexdb.row_factory = sqlite3.Row
# 
#     return flask.g.indexdb


import string
import datetime
import flask
import gogdb.core.model as model
from gogdb.views.pagination import calc_pageinfo
from gogdb.core.normalization import normalize_search, decompress_systems
from gogdb.application.datasources import get_indexdb




PRODUCTS_PER_PAGE = 20


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())))


# Path: gogdb/views/pagination.py
# def calc_pageinfo(page, num_products, items_per_page):
#     num_pages = int(math.ceil(num_products / items_per_page))
#     page = min(max(page, 1), num_pages)
#     offset = (page - 1) * items_per_page
#     page_info = {
#         "is_first": page == 1,
#         "is_last": page == num_pages,
#         "page": page,
#         "num_pages": num_pages,
#         "from": offset,
#         "to": offset + items_per_page,
#         "prev_link": "", # Filled in later
#         "next_link": ""
#     }
#     return page_info
# 
# Path: gogdb/core/normalization.py
# def normalize_search(search_str):
#     if search_str is None:
#         return ""
#     return "".join(c for c in search_str.lower() if c in NORMALIZED_CHARS)
# 
# def decompress_systems(compressed):
#     systems = []
#     decompress_map = {
#         "w": "windows",
#         "l": "linux",
#         "o": "osx"
#     }
#     for letter in compressed:
#         systems.append(decompress_map[letter])
#     return systems
# 
# Path: gogdb/application/datasources.py
# def get_indexdb():
#     if "indexdb" not in flask.g:
#         storagedb = get_storagedb()
#         index_path = storagedb.path_indexdb()
#         flask.g.indexdb = sqlite3.connect(index_path)
#         flask.g.indexdb.row_factory = sqlite3.Row
# 
#     return flask.g.indexdb


# Path: gogdb/views/product_list.py
import string
import datetime
import flask
import gogdb.core.model as model
from gogdb.views.pagination import calc_pageinfo
from gogdb.core.normalization import normalize_search, decompress_systems
from gogdb.application.datasources import get_indexdb





PRODUCTS_PER_PAGE = 20


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()