-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
import sqlalchemy as sa | ||
from flask import render_template, Blueprint, current_app | ||
from blog.post.models import Post | ||
from flask import render_template, Blueprint | ||
from blog.post.views import pages_gen | ||
from blog.tags.models import Tag | ||
from blog import db | ||
|
||
tagsb = Blueprint("tagsb", __name__, url_prefix='/tags') | ||
tagsb = Blueprint("tagsb", __name__, url_prefix="/tags") | ||
|
||
PAGE_STATUS = 1 | ||
PAGE_SPECIAL = 3 | ||
|
||
|
||
@tagsb.route('/') | ||
def index(): | ||
page_category = current_app.config['PAGE_CATEGORY'] | ||
@tagsb.route("/") | ||
@pages_gen | ||
def index(**kwargs): | ||
tags = db.session.scalars(sa.select(Tag)).all() | ||
pages_query = sa.select(Post).where(Post.category_id == page_category) | ||
pages = db.session.scalars(pages_query).all() | ||
return render_template("tags.html", tags=tags, pages=pages) | ||
return render_template("tags.html", tags=tags, **kwargs) | ||
|
||
|
||
@tagsb.route('/<alias>') | ||
def view(alias=None): | ||
page_category = current_app.config['PAGE_CATEGORY'] | ||
pages_query = sa.select(Post).where(Post.category_id == page_category) | ||
pages = db.session.scalars(pages_query).all() | ||
@tagsb.route("/<alias>") | ||
@pages_gen | ||
def view(alias=None, **kwargs): | ||
tag_query = sa.select(Tag).where(Tag.alias == alias) | ||
tag = db.first_or_404(tag_query) | ||
return render_template('posts.html', posts=tag.posts, pages=pages, tag=tag) | ||
return render_template("posts.html", posts=tag.posts, tag=tag, **kwargs) |