slugbucket / crossword-hints

Python Flask web application to aid decipherment of cryptic crossword clues for known setters
GNU General Public License v3.0
1 stars 0 forks source link

Add pagination and new item styling to all sections - feat0017 #22

Closed slugbucket closed 5 years ago

slugbucket commented 5 years ago

While only the solutions page is likely to need pagination links, the syling used for the new solution link should be applied to the other pages.

slugbucket commented 5 years ago

Track as feat0017

slugbucket commented 5 years ago

The render_pagination function in templates/macros.html contains layout specific to the crossword-solutions page (though it should be possible to avoid this by passing the page name as a parametr to render_pagination from the calling template) but it is certianly possible to add the styling to the new item link.

slugbucket commented 5 years ago

Complete the development of this feature before geat0014.

slugbucket commented 5 years ago

The general form of the index page becomes:

@application.route("/solution-types/", methods=["GET"], defaults={'page': 1})
@application.route('/solution-types/page/<int:page>')
def solution_types_index(page):
    count = solution_types.select(fn.COUNT(solution_types.rowid)).scalar()
    PER_PAGE=25
    offset = ((int(page)-1) * PER_PAGE)
    rs = solution_types.select().order_by(fn.Lower(solution_types.name))
    if not rs and page != 1:
        return(render_template('errors/409.html', errmsg="Requested page out of bounds"), 409 )
    pagination = Pagination(page, PER_PAGE, count)
    return render_template('views/solution-types/index.html',
                           stypes=rs.dicts(),
                           pagination=pagination,
                           r=request)

render_pagination in templates/macros.html needs to accept to more parameters

render_pagination(pagination, page_name, new_link_text)

So that the call to it in the index.html template becomes

{{ f.render_pagination(pagination, "solution-types", "crossword solution type") }}
slugbucket commented 5 years ago

The PeeWee library appears to have a problem using the limit operator

rs = crossword_setters.select(crossword_setters.rowid, crossword_setters.name, crossword_setters.description, setter_types.name.alias('setter_type_name')).join(setter_types).where(crossword_setters.setter_type_id == setter_types.rowid).limit(PER_PAGE, offset).order_by(fn.Lower(crossword_setters.name))

gives the following error

TypeError: limit() takes from 1 to 2 positional arguments but 3 were given

While it looks like there are only 2 arguments, PeeWee actually uses a separate offset method, thus,

..;. .where(crossword_setters.setter_type_id == setter_types.rowid).limit(PER_PAGE),offset(offset).order_by(fn.Lower(crossword_setters.name)
slugbucket commented 5 years ago

All pages updated along with the back to index link on each form.