bootstrap-flask icon indicating copy to clipboard operation
bootstrap-flask copied to clipboard

pagination with post needed

Open WolfgangFahl opened this issue 3 years ago • 0 comments

After changing the pagination example in http://fb4demo.bitplan.com/pagination grafik

as outlined below things don't work as expected since the pagination uses get and not post so that the PerPage selection is not picked up. This way even a 404 might be reported since the page and perPage values do not fit any more. Search and Per Page Selection form

class IconSearchForm(FlaskForm):
    search=StringField('search', render_kw={"onchange":"this.form.submit()"})
    perPage=SelectField(choices=[('twenty','20'),
        ('fifty','50'),
        ('hundred','100'),
        ('twohundred','200'),
        ('all','all'),
        ],
        #https://stackoverflow.com/a/38157356/1497139
        render_kw={"onchange":"this.form.submit()"}
    )

pagination

def pagination(self):
        '''
        pagination example
        
        Returns:
            rendered html for pagination
        '''
        search_form=IconSearchForm()
        perPageChoice=search_form.perPage.data    
        if perPageChoice is None:
            perPageChoice="twenty"
        choices=dict(search_form.perPage.choices)
        perPageSelection=choices[perPageChoice]
        search_form.perPage.data=perPageChoice
        if perPageChoice=="all":
            per_page=2000
        else:    
            per_page=int(perPageSelection)    
        pagination=None
        icons=None
        if search_form.validate_on_submit() and search_form.search.data:
            search="%{}%".format(search_form.search.data)
            print("searching %s: " % search)
            icons = BootstrapIcon.query.filter(BootstrapIcon.id.like(search)).all()
        if icons is None:
            page = request.args.get('page', 1, type=int)
            pagination = BootstrapIcon.query.paginate(page, per_page=per_page)
            icons = pagination.items
        displayIcons=self.getDisplayIcons(icons)
        return render_template('pagination.html', form=search_form,pagination=pagination, icons=displayIcons)

WolfgangFahl avatar Jan 24 '21 14:01 WolfgangFahl