# Path: gramps_connect/template_functions.py
# def make_button(text, link):
#     return """<input type="button" value="%s" onclick="location.href='%s';" />""" % (text, link)


import logging
import math
import time
from ..template_functions import make_button
from gramps.gen.display.name import NameDisplay
from gramps.gen.datehandler import displayer, parser
    def get_column_count(self):
        return len(self.select_fields) + 1

    def make_query(self, **kwargs):
        kwargs.update({"search": self.search})
        query = ""
        for kw in kwargs:
            if kwargs[kw]:
                if query == "":
                    query += "?"
                else:
                    query += "&"
                query += "%s=%s" % (kw, kwargs[kw])
        return query

    def get_table_count(self):
        return self.database.get_table_func(self.table,"count_func")()

    def get_page_controls(self, page):
        total = self.get_table_count()
        records = self.rows.total
        matching = len(self.rows)
        total_pages = math.ceil(records / self.page_size)
        return ("""<div align="center" style="background-color: lightgray; border: 1px solid black; border-radius:5px; margin: 0px 1px; padding: 1px;">""" +
                make_button("<<", self.make_query(page=1)) +
                " | " +
                make_button("<", self.make_query(page=max(page - 1, 1))) +
                (" | <b>Page</b> %s of %s | " % (page, total_pages)) +
                make_button(">", self.make_query(page=min(page + 1, total_pages))) +
                " | " +

# Path: gramps_connect/template_functions.py
# def make_button(text, link):
#     return """<input type="button" value="%s" onclick="location.href='%s';" />""" % (text, link)


# Path: gramps_connect/forms/forms.py
import logging
import math
import time
from ..template_functions import make_button
from gramps.gen.display.name import NameDisplay
from gramps.gen.datehandler import displayer, parser

    def get_column_count(self):
        return len(self.select_fields) + 1

    def make_query(self, **kwargs):
        kwargs.update({"search": self.search})
        query = ""
        for kw in kwargs:
            if kwargs[kw]:
                if query == "":
                    query += "?"
                else:
                    query += "&"
                query += "%s=%s" % (kw, kwargs[kw])
        return query

    def get_table_count(self):
        return self.database.get_table_func(self.table,"count_func")()

    def get_page_controls(self, page):
        total = self.get_table_count()
        records = self.rows.total
        matching = len(self.rows)
        total_pages = math.ceil(records / self.page_size)
        return ("""<div align="center" style="background-color: lightgray; border: 1px solid black; border-radius:5px; margin: 0px 1px; padding: 1px;">""" +
                make_button("<<", self.make_query(page=1)) +
                " | " +
                make_button("<", self.make_query(page=max(page - 1, 1))) +
                (" | <b>Page</b> %s of %s | " % (page, total_pages)) +
                make_button(">", self.make_query(page=min(page + 1, total_pages))) +
                " | " +

                make_button(">>", self.make_query(page=total_pages)) +