Skip to content

Commit

Permalink
Merge pull request #3 from BecauseOfProg/develop
Browse files Browse the repository at this point in the history
Release v2.2.2
  • Loading branch information
Théo Vidal authored Jul 30, 2020
2 parents 82dd13c + f2e75c5 commit d880e35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/blog_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def filter_by_category(posts, category):
def filter_by_type(posts, type):
return posts.where(type=type)

@staticmethod
@db_session
def filter_by_author(posts, author):
return posts.where(author=author)

@staticmethod
@db_session
def filter_by_search(posts, search):
Expand Down
1 change: 0 additions & 1 deletion app/models/blog_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ class BlogPost(db.Entity):
banner = Required(str)
content = Required(str)
locale = Required(str, default='fr')
article_language = Required(str, default='md')

_table_ = 'articles'
5 changes: 5 additions & 0 deletions app/views/blog_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
def get_all_blog_posts():
posts = BlogPostsController.fetch_all()

# TODO: make the code less repetitive by using a dict or something like that
category = request.args.get('category', None)
if category is not None:
posts = BlogPostsController.filter_by_category(posts, category)
Expand All @@ -21,6 +22,10 @@ def get_all_blog_posts():
if type is not None:
posts = BlogPostsController.filter_by_type(posts, type)

author = request.args.get('author', None)
if author is not None:
posts = BlogPostsController.filter_by_author(posts, author)

search = request.args.get('search', None)
if search is not None:
posts = BlogPostsController.filter_by_search(posts, search)
Expand Down

0 comments on commit d880e35

Please sign in to comment.