Skip to content

Commit

Permalink
Met à jour la page d'accueil
Browse files Browse the repository at this point in the history
* fait correspondre la structure de la page d'accueil à la future organisation "validé/libre" pour les publications
* rend la page plus joueuse avec des "call to actions"
* regroupe les paramètres de configuration dans leur propre section
* refactorise les fonctions de récupération de données pour qu'elles ne dépendent plus directement de certaines configurations
  • Loading branch information
Arnaud-D committed Dec 30, 2024
1 parent 4d9a460 commit 44a4148
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 141 deletions.
2 changes: 1 addition & 1 deletion assets/scss/base/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ body {
}

// Elements with a dark background
.flexpage-header, .write-tutorial, .page-footer, .header-menu, .header-right, .modal-title, .taglist, .hat, .linkbox-item.primary {
.flexpage-header, .call-to-action, .page-footer, .header-menu, .header-right, .modal-title, .taglist, .hat, .linkbox-item.primary {
&::selection, *::selection {
@include negative-selection;
}
Expand Down
26 changes: 9 additions & 17 deletions assets/scss/components/_content-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $content-item-padding-vertical: $length-14;
display: flex;

width: 100%;
height: $content-item-height;
min-height: $content-item-height;

margin: $length-6 $length-10;

Expand Down Expand Up @@ -321,32 +321,29 @@ $content-item-padding-vertical: $length-14;
margin-bottom: $length-24;
}

.write-tutorial {
.call-to-action {
display: flex;
align-items: center;

margin: $length-16 $length-10;

&:not(:last-child) {
margin-bottom: $length-20;
}
flex-wrap: wrap;
box-sizing: border-box;
padding: $length-6 $length-20;

width: 100%;
height: $content-item-height;
min-height: $content-item-height;

border-color: $color-primary;
background-color: $color-primary;

color: $grey-000;

&:hover {
.btn-write-tutorial {
.btn-call-to-action {
background-color: $true-white;
transform: scale(1.05);
}
}

.write-tutorial-text {
.call-to-action-text {
flex: 1;
text-align: center;

Expand All @@ -361,9 +358,8 @@ $content-item-padding-vertical: $length-14;
}
}

.btn-write-tutorial {
.btn-call-to-action {
padding: $length-4 $length-20;
margin-right: $length-24;

background-color: $grey-000;
color: $primary-900;
Expand Down Expand Up @@ -394,10 +390,6 @@ $content-item-padding-vertical: $length-14;

@include mobile {
.content-item {
&.write-tutorial {
display: none;
}

.content-tags {
display: none;
}
Expand Down
85 changes: 57 additions & 28 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,67 +109,86 @@ <h1 class="home-heading heading-white ico-after ico-news" itemprop="name">
{% endfor %}
</div>
</section>

<div class="home-row">
<section itemscope itemtype="http://schema.org/ItemList">
<h2 class="ico-after ico-tutorials home-heading" itemprop="name">
<span>{% trans "Derniers tutoriels" %}</span>
<a href="{% url 'publication:list' %}?type=tutorial" class="btn btn-grey">{% trans "Tous les tutoriels" %}</a>
<span>{% trans "Dernières pépites validées par l'équipe" %}</span>
</h2>

<meta itemprop="itemListOrder" content="Descending">

{% include "tutorialv2/list_page_elements/list_of_online_contents.html" with public_contents=last_tutorials col_number=1 ignore_categories=True %}
<div class="content-item-list">
{% for content in last_contents %}
{% include "tutorialv2/includes/content_item.part.html" with public_content=content show_description=True show_reactions=True ignore_categories=ignore_categories %}
{% endfor %}
<div class="content-item call-to-action">
<div class="call-to-action-text">
<p>
{% blocktrans with plural=contents_count|pluralize_fr %}
Mais ce n'est pas tout...
{% endblocktrans %}
</p>
<p class="lead">
{% if validated_contents_count == 0 %}
{% blocktrans %}
Il y a {{ validated_contents_count }} publication validée par l'équipe.</p>
{% endblocktrans %}
{% else %}
{% blocktrans %}
Il y a {{ validated_contents_count }} publications validées par l'équipe.</p>
{% endblocktrans %}
{% endif %}
</div>
<a href="{% url "publication:list" %}" class="btn btn-call-to-action">{% trans "Montre-les moi !" %}</a>
</div>
</div>
</section>
</div>

<div class="home-row">
<section itemscope itemtype="http://schema.org/ItemList">
<h2 class="ico-after ico-articles home-heading" itemprop="name">
<span>{% trans "Derniers articles" %}</span>
<a href="{% url 'publication:list' %}?type=article" class="btn btn-grey">{% trans "Tous les articles" %}</a>
<h2 class="ico-after ico-opinions home-heading" itemprop="name">
<span>{% trans "Dernières publications de la communauté" %}</span>
</h2>

<meta itemprop="itemListOrder" content="Descending">

{% include "tutorialv2/list_page_elements/list_of_online_contents.html" with public_contents=last_articles col_number=1 ignore_categories=True %}

<div class="content-item-list">

<div class="content-item write-tutorial">
<div class="write-tutorial-text">
<div class="content-item call-to-action">
<div class="call-to-action-text">
<p>
{% blocktrans with plural=contents_count|pluralize_fr %}
Il y a {{ contents_count }} publication{{ plural }} sur Zeste de Savoir.
{% endblocktrans %}
</p>
<p class="lead">{% trans "Pourquoi pas la vôtre ?" %}</p>
</div>
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="btn btn-write-tutorial">{% trans "Commencer à rédiger" %}</a>
<a href="{% url "content:create-content" created_content_type='TUTORIAL' %}" class="btn btn-call-to-action">{% trans "Commencer à rédiger" %}</a>
</div>
</div>
</section>
</div>

<div class="home-row">
<section itemscope itemtype="http://schema.org/ItemList">
<h2 class="ico-after ico-opinions home-heading" itemprop="name">
<span>{% trans "Derniers billets choisis" %}</span>
<a href="{% url "opinion:list" %}" class="btn btn-grey">{% trans "Tous les billets" %}</a>
</h2>

<meta itemprop="itemListOrder" content="Descending">

<div class="content-item-list">
{% for opinion in last_opinions %}
{% include 'tutorialv2/includes/content_item.part.html' with public_content=opinion show_description=True item_class=forloop.first|yesno:", mini" show_reactions=True ignore_categories=True %}
{% empty %}
<p>{% trans "Aucun billet disponible." %}</p>
{% endfor %}
<div class="content-item call-to-action">
<div class="call-to-action-text">
<p>
{% blocktrans with plural=contents_count|pluralize_fr %}
D’autres publications de la communauté vous attendent.
{% endblocktrans %}
</p>
</div>
<a href="{% url "opinion:list" %}" class="btn btn-call-to-action">{% trans "Fais voir !" %}</a>
</div>
</div>
</section>
</div>

<div class="home-row">
<section itemscope itemtype="http://schema.org/ItemList">
<h2 class="home-heading ico-after ico-forum" itemprop="name">
<span>{% trans "Derniers sujets" %}</span>
<a href="{% url "forum:last-subjects" %}" class="btn btn-grey">{% trans "En voir plus" %}</a>
<span>{% trans "En direct du forum" %}</span>
</h2>

<meta itemprop="itemListOrder" content="Descending">
Expand All @@ -180,6 +199,16 @@ <h2 class="home-heading ico-after ico-forum" itemprop="name">
{% empty %}
<p>{% trans "Aucun sujet disponible." %}</p>
{% endfor %}
<div class="content-item call-to-action">
<div class="call-to-action-text">
<p>
{% blocktrans with plural=contents_count|pluralize_fr %}
Entraide, débats, discussions : venez sur nos forums !
{% endblocktrans %}
</p>
</div>
<a href="{% url "forum:cats-forums-list" %}" class="btn btn-call-to-action">{% trans "Je participe" %}</a>
</div>
</div>
</section>
</div>
Expand Down
9 changes: 2 additions & 7 deletions zds/featured/managers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime

from django.db import models
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist

Expand All @@ -14,12 +13,8 @@ class FeaturedResourceManager(models.Manager):
Custom featured resource manager.
"""

def get_last_featured(self):
return (
self.order_by("-pubdate")
.exclude(pubdate__gt=datetime.now())
.prefetch_related("authors__user")[: settings.ZDS_APP["featured_resource"]["home_number"]]
)
def get_last_featured(self, count):
return self.order_by("-pubdate").exclude(pubdate__gt=datetime.now()).prefetch_related("authors__user")[:count]


class FeaturedMessageManager(models.Manager):
Expand Down
25 changes: 7 additions & 18 deletions zds/forum/managers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from django.conf import settings
import django.db.models
from django.db import models
from django.db.models import Q, F
from model_utils.managers import InheritanceManager

from zds.utils import get_current_user


class ForumManager(models.Manager):
"""
Expand Down Expand Up @@ -65,17 +63,13 @@ class TopicManager(models.Manager):
"""

def visibility_check_query(self, current_user):
"""
Build a subquery that checks if a topic is readable by current user
:param current_user:
:return:
"""
"""Build a subquery that checks if a topic is readable by current user"""
if current_user.is_authenticated:
return Q(forum__groups__isnull=True) | Q(forum__groups__pk__in=current_user.profile.group_pks)
else:
return Q(forum__groups__isnull=True)

def last_topics_of_a_member(self, author, user):
def last_topics_of_a_member(self, author, user, count):
"""
Gets last topics of a member but exclude all topics not accessible
for the request user.
Expand All @@ -86,24 +80,19 @@ def last_topics_of_a_member(self, author, user):
queryset = self.filter(author=author).prefetch_related("author")
queryset = queryset.filter(self.visibility_check_query(user)).distinct()

return queryset.order_by("-pubdate").all()[: settings.ZDS_APP["forum"]["home_number"]]
return queryset.order_by("-pubdate").all()[:count]

def get_beta_topic_of(self, tutorial):
return self.filter(key=tutorial.pk, key__isnull=False).first()

def get_last_topics(self):
"""
Get last posted topics and prefetch some related properties.
Depends on settings.ZDS_APP['topic']['home_number']
:return:
:rtype: django.models.Queryset
"""
def get_last_topics(self, count) -> django.db.models.QuerySet:
"""Get last topics and prefetch some related properties."""
return (
self.filter(is_locked=False, forum__groups__isnull=True)
.select_related("forum", "author", "author__profile", "last_message")
.prefetch_related("tags")
.order_by("-pubdate")
.all()[: settings.ZDS_APP["topic"]["home_number"]]
.all()[:count]
)

def get_all_topics_of_a_forum(self, forum_pk, is_sticky=False):
Expand Down
3 changes: 1 addition & 2 deletions zds/forum/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
TopicFactory,
PostFactory,
TagFactory,
create_category_and_forum,
)
from zds.forum.models import Forum, TopicRead, Post, Topic
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory
Expand Down Expand Up @@ -1182,7 +1181,7 @@ def setUp(self):
TopicFactory(forum=self.forum3, author=self.staff.user)

def test_get_last_topics(self):
topics = Topic.objects.get_last_topics()
topics = Topic.objects.get_last_topics(5)
self.assertEqual(2, len(topics))

def test_get_unread_post(self):
Expand Down
5 changes: 3 additions & 2 deletions zds/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def test_topic_list_home_page(self):
_, forum = create_category_and_forum()
topic = create_topic_in_forum(forum, profile)

topics_nb = len(Topic.objects.get_last_topics())
topics_count = 5
topics_nb = len(Topic.objects.get_last_topics(topics_count))

self.client.force_login(staff.user)
data = {"lock": "true", "topic": topic.pk}
Expand All @@ -105,7 +106,7 @@ def test_topic_list_home_page(self):
self.assertEqual(302, response.status_code)
self.assertTrue(Topic.objects.get(pk=topic.pk).is_locked)

self.assertEqual(len(Topic.objects.get_last_topics()), topics_nb - 1)
self.assertEqual(len(Topic.objects.get_last_topics(topics_count)), topics_nb - 1)


class CategoryForumsDetailViewTest(TestCase):
Expand Down
3 changes: 2 additions & 1 deletion zds/member/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def get_context_data(self, **kwargs):
usr = context["usr"]
profile = usr.profile
context["profile"] = profile
context["topics"] = list(Topic.objects.last_topics_of_a_member(usr, self.request.user))
topics_count = settings.ZDS_APP["member"]["topics_on_profile"]
context["topics"] = list(Topic.objects.last_topics_of_a_member(usr, self.request.user, count=topics_count))
followed_query_set = TopicAnswerSubscription.objects.get_objects_followed_by(self.request.user.id)
followed_topics = list(set(followed_query_set) & set(context["topics"]))
for topic in context["topics"]:
Expand Down
Loading

0 comments on commit 44a4148

Please sign in to comment.