0

I have been developing a flask based app for my college event. I have used an SQLite database along with Peewee and it's playhouse extensions. There is a particular page where I need to show all the entries from a database table.

# The playhouse.flask_utils.FlaskDB object accepts database URL configuration.
DATABASE = 'sqliteext:///%s' % os.path.join(APP_DIR, 'blog.db')
DEBUG = False

# Create a Flask WSGI app and configure it using values from the module.
app = Flask(__name__)
app.config.from_object(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

# FlaskDB is a wrapper for a peewee database that sets up pre/post-request
# hooks for managing database connections.
flask_db = FlaskDB(app)

# The `database` is the actual peewee database, as opposed to flask_db which is
# the wrapper.
database = flask_db.database

There is an Entry class, with save and a query function

class Entry(flask_db.Model):
    title = CharField()
    slug = CharField(unique=True)
    content = TextField()
    tags = TextField()
    published = BooleanField(index=True)
    is_highlight = BooleanField(index=True)
    category = TextField()
    date = TextField()
    time = TextField()
    contact = TextField()
    fee = TextField()
    image = TextField()
    timestamp = DateTimeField(default=datetime.datetime.now, index=True)
    @property
    def html_content(self):
        """
        Generate HTML representation of the markdown-formatted blog entry,
        and also convert any media URLs into rich media objects such as video
        players or images.
        """
        hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
        extras = ExtraExtension()
        markdown_content = markdown(self.content, extensions=[hilite, extras])
        oembed_content = parse_html(
            markdown_content,
            oembed_providers,
            urlize_all=True,
            maxwidth=app.config['SITE_WIDTH'])
        return Markup(oembed_content)

    def save(self, *args, **kwargs):
        # Generate a URL-friendly representation of the entry's title.
        if not self.slug:
            self.slug = re.sub('[^\w]+', '-', self.title.lower()).strip('-')
        ret = super(Entry, self).save(*args, **kwargs)

        # Store search content.
        return ret

    @classmethod
    def public(cls):
        return Entry.select().where(Entry.published == True)

And the function that renders the page is

@app.route('/events')
def events():
    query = Entry.public()
    return object_list(
        'list.html',
        query,
        check_bounds=False)

The query when run over the command line using sqlite3 for ubuntu returns all 26 entries, however in the app, it returns only 20 of them. I verified by deleting one of the entries from the table, and it's place was taken by one of the rows not visible earlier. I looked upon multiple sites and documentations from both peewee and sqlite and haven't found a solution yet. I even tried changing pragma statements like Page Size. I am of the opinion that changing the run-time limits of the DB can help me, but I haven't found a way to change or modify that. Is there anyway to fix it. Or is migration to MariaDB gonna solve it. If so is that the only solution.

1 Answers1

0

I simply had to use 'paginate_by = my-number' in the object list.