fix: show 404 on non-existend post types
This commit is contained in:
parent
bb8d1ed431
commit
df71c18d3c
|
@ -9,21 +9,21 @@ It is completely custom and is not intended to be used as a universal blog engin
|
|||
|
||||
## ⚙️ Tech details
|
||||
|
||||
Backend:
|
||||
**Backend:**
|
||||
- Python 3.11+
|
||||
- Django 4+
|
||||
- PostgreSQL
|
||||
- [Poetry](https://python-poetry.org/) as a package manager
|
||||
|
||||
Frontend:
|
||||
**Frontend:**
|
||||
- [htmx](https://htmx.org/)
|
||||
- Mostly pure JS, no webpack, no builders
|
||||
- No CSS framework
|
||||
|
||||
Blogging:
|
||||
**Blogging part:**
|
||||
- Markdown with a bunch of [custom plugins](common/markdown/plugins)
|
||||
|
||||
CI/CD:
|
||||
**CI/CD:**
|
||||
- Github Actions + SSH deployment using [docker-compose.production.yml](docker-compose.production.yml) as a service configuration
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from comments.models import Comment
|
|||
from posts.forms import PostEditForm
|
||||
from posts.models import Post
|
||||
from posts.renderers import render_list, render_list_all, render_post
|
||||
from vas3k_blog.posts import INDEX_PAGE_BEST_POSTS
|
||||
from vas3k_blog.posts import INDEX_PAGE_BEST_POSTS, POST_TYPES
|
||||
|
||||
|
||||
def index(request):
|
||||
|
@ -93,6 +93,9 @@ def list_posts(request, post_type="all"):
|
|||
posts = Post.visible_objects().select_related()
|
||||
|
||||
if post_type and post_type != "all":
|
||||
if post_type not in POST_TYPES:
|
||||
return Http404()
|
||||
|
||||
posts = posts.filter(type=post_type)
|
||||
if not posts:
|
||||
raise Http404()
|
||||
|
@ -109,6 +112,10 @@ def show_post(request, post_type, post_slug):
|
|||
if post.type != post_type:
|
||||
return redirect("show_post", post.type, post.slug)
|
||||
|
||||
# post_type can be removed
|
||||
if post_type not in POST_TYPES:
|
||||
return Http404()
|
||||
|
||||
# drafts are visible only to admins
|
||||
if not post.is_visible:
|
||||
# if not request.me or not request.me.is_admin:
|
||||
|
|
|
@ -34,13 +34,6 @@ POST_TYPES: dict[str, PostTypeConfig] = {
|
|||
list_template="posts/lists/blog.html",
|
||||
show_template="posts/full/blog.html",
|
||||
),
|
||||
"challenge": PostTypeConfig(
|
||||
name="Поисковые челленджи",
|
||||
list_items_per_page=30,
|
||||
card_template="posts/cards/horizontal.html",
|
||||
list_template="posts/lists/blog.html",
|
||||
show_template="posts/full/legacy/challenge.html",
|
||||
),
|
||||
"gallery": PostTypeConfig(
|
||||
name="Галлерея",
|
||||
list_items_per_page=30,
|
||||
|
|
Loading…
Reference in New Issue