From 33f39730aa7fdd53b5dac7509e518a5abed5b132 Mon Sep 17 00:00:00 2001 From: tata Date: Sun, 27 Aug 2023 00:14:33 +0200 Subject: [PATCH] For #45 :sparkles: menu:breadcrumples --- pytest.ini | 2 +- sandbox/conf/base.py | 1 + src/posts/context_processors.py | 29 ++ src/posts/urls.py | 3 +- src/posts/views.py | 9 +- src/static/images/svgs/home.svg | 336 +++++++++++++++++++++ src/templates/base.html | 11 +- src/templates/components/bread_crumbs.html | 22 -- src/templates/components/crumbs.html | 22 ++ src/templates/posts/post_detail.html | 35 +++ src/templates/posts/post_list.html | 4 +- 11 files changed, 444 insertions(+), 30 deletions(-) create mode 100644 src/posts/context_processors.py create mode 100644 src/static/images/svgs/home.svg delete mode 100644 src/templates/components/bread_crumbs.html create mode 100644 src/templates/components/crumbs.html create mode 100644 src/templates/posts/post_detail.html diff --git a/pytest.ini b/pytest.ini index 5bef2fd..4b9d970 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,7 +2,7 @@ env_path=./.env DJANGO_SETTINGS_MODULE=sandbox.conf.dev python_files=tests.py test_*.py *_tests.py -addopts = -p no:warnings --reuse-db +addopts = -p no:warnings norecursedirs = venv dist filterwarnings=ignore::DeprecationWarning \ No newline at end of file diff --git a/sandbox/conf/base.py b/sandbox/conf/base.py index 29ff1be..821008f 100644 --- a/sandbox/conf/base.py +++ b/sandbox/conf/base.py @@ -85,6 +85,7 @@ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "src.contacts.context_processors.check_subscription", + "src.posts.context_processors.build_crumbs", ], }, }, diff --git a/src/posts/context_processors.py b/src/posts/context_processors.py new file mode 100644 index 0000000..83c682d --- /dev/null +++ b/src/posts/context_processors.py @@ -0,0 +1,29 @@ +from django.shortcuts import get_object_or_404 +from django.urls import Resolver404, resolve, reverse + +from src.posts.models.post_model import Post + + +def build_crumbs(request): + """build breadcrumbs""" + crumbs = [{"name": "Home", "url": reverse("home")}] + try: + match = resolve(request.path_info) + except Resolver404: + return {"crumbs": []} + # if match.url_name == "post_list": + crumbs.append({"name": "posts", "url": reverse("posts:post_list")}) + if match.url_name == "post_detail": + post = get_object_or_404(Post, slug=match.kwargs["slug"]) + print(post) + crumbs.append( + { + "name": post.title, + "url": reverse( + f"{match.app_names[0]}:{match.url_name}", + args=[match.kwargs["slug"]], + ), + } + ) + print("crumbs are ", crumbs) + return {"crumbs": crumbs} diff --git a/src/posts/urls.py b/src/posts/urls.py index 96c6cc1..82a9e21 100644 --- a/src/posts/urls.py +++ b/src/posts/urls.py @@ -1,11 +1,12 @@ from django.urls import path, re_path -from .views import PostCategSearch, PostList, PostTagSearch, SearchPost +from .views import PostCategSearch, PostDetail, PostList, PostTagSearch, SearchPost app_name = "posts" urlpatterns = [ path("", PostList.as_view(), name="post_list"), + path("detail//", PostDetail.as_view(), name="post_detail"), path("categ//", PostCategSearch.as_view(), name="cat_search"), path("search/", SearchPost.as_view(), name="search_posts"), re_path( diff --git a/src/posts/views.py b/src/posts/views.py index b5f5284..85e1d6b 100644 --- a/src/posts/views.py +++ b/src/posts/views.py @@ -3,7 +3,7 @@ from django.shortcuts import get_object_or_404 from django.utils.translation import get_language from django.utils.translation import gettext_lazy as _ -from django.views.generic import ListView +from django.views.generic import DetailView, ListView from src.core.utils.views_help import make_query, search_qs from src.posts.forms import SearchForm @@ -12,6 +12,7 @@ class PostList(ListView): + """display only public posts""" template_name = "posts/post_list.html" @@ -20,6 +21,7 @@ class PostList(ListView): paginate_by = 2 def get_queryset(self): + print("looking for posts") return ( Post.objects.get_public() .select_related("categ", "author") @@ -27,6 +29,11 @@ def get_queryset(self): ) +class PostDetail(DetailView): + model = Post + template_name = "posts/post_detail.html" + + class PostTagSearch(ListView): template_name = "posts/post_list.html" context_object_name = "posts" diff --git a/src/static/images/svgs/home.svg b/src/static/images/svgs/home.svg new file mode 100644 index 0000000..84476f4 --- /dev/null +++ b/src/static/images/svgs/home.svg @@ -0,0 +1,336 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +image/svg+xmlOpencliparthome insurance2010-07-04T20:34:47real estate clip arthttps://openclipart.org/detail/70165/home-insurance-by-netalloynetalloyhome insurancehome securitysafety diff --git a/src/templates/base.html b/src/templates/base.html index 86b5910..6571008 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -18,12 +18,12 @@ - - + + + + {% include "components/menu.html" %}
@@ -51,6 +51,9 @@
{% show_search_form %}
+
+ {% include "components/crumbs.html" %} +
diff --git a/src/templates/components/bread_crumbs.html b/src/templates/components/bread_crumbs.html deleted file mode 100644 index 73d6ac8..0000000 --- a/src/templates/components/bread_crumbs.html +++ /dev/null @@ -1,22 +0,0 @@ -{% load i18n %} - - diff --git a/src/templates/components/crumbs.html b/src/templates/components/crumbs.html new file mode 100644 index 0000000..b2b6e34 --- /dev/null +++ b/src/templates/components/crumbs.html @@ -0,0 +1,22 @@ +{% load static %} + \ No newline at end of file diff --git a/src/templates/posts/post_detail.html b/src/templates/posts/post_detail.html new file mode 100644 index 0000000..02b3ced --- /dev/null +++ b/src/templates/posts/post_detail.html @@ -0,0 +1,35 @@ +{% extends 'base.html' %} +{% load static sidebars i18n %} + + +{% block content %} +
+ +
+ +

{{post.title}}

+

{{post.created_at|date:"F d, Y"}}

+ {%trans "category" %}: {{post.categ.name}} +
+ {{post.content|safe}} +
+
+ + +
+
+ {% show_tags %} +
+ +
+ +{% endblock%} +{% block js %} + +{% endblock %} \ No newline at end of file diff --git a/src/templates/posts/post_list.html b/src/templates/posts/post_list.html index f1c87c2..5a23033 100644 --- a/src/templates/posts/post_list.html +++ b/src/templates/posts/post_list.html @@ -1,6 +1,5 @@ {% extends 'base.html' %} {% load static sidebars i18n %} - {% block content %}