Skip to content

Commit

Permalink
Fix ressources on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Sep 17, 2024
1 parent a160976 commit e0b4d9c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lemarche/www/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from django.utils import timezone
from django.views.generic import DetailView, UpdateView

from lemarche.cms.models import ArticlePage
from lemarche.cms.snippets import ArticleCategory
from content_manager.models import ContentPage, Tag
from lemarche.cms.models import ArticleList
from lemarche.siaes.models import Siae
from lemarche.tenders.models import Tender
from lemarche.users.models import User
Expand Down Expand Up @@ -47,19 +47,28 @@ def get_context_data(self, **kwargs):
category_slug = SLUG_RESSOURCES_CAT_SIAES
elif user.kind == User.KIND_BUYER:
category_slug = SLUG_RESSOURCES_CAT_BUYERS
article_list = ArticlePage.objects.live().public().order_by("-last_published_at")

# Get ContentPage under the ArticleList that has the slug "ressources"
try:
ressource_page = ArticleList.objects.get(slug="ressources")
ressource_list = (
ContentPage.objects.descendant_of(ressource_page)
.live()
.prefetch_related("tags")
.order_by("-last_published_at")
)
except ArticleList.DoesNotExist:
ressource_list = ContentPage.objects.none()

if category_slug:
try:
# Look for the blog category by its slug.
category = ArticleCategory.objects.get(slug=category_slug)
article_list = article_list.filter(categories__in=[category])
tag = Tag.objects.get(slug=category_slug)
ressource_list = ressource_list.filter(tags__in=[tag])
except Exception:
category_slug = None

# set context ressources
context["current_slug_cat"] = category_slug
context["last_3_ressources"] = article_list[:3]
context["last_3_ressources"] = ressource_list[:3]

# for specific users
if user.kind == User.KIND_SIAE:
Expand Down

0 comments on commit e0b4d9c

Please sign in to comment.