Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1731: Ajout de la possibilité de trier ses articles/tutoriels #1733

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 39 additions & 5 deletions templates/article/member/index.html
Expand Up @@ -37,6 +37,13 @@
{% elif request.GET.type == "draft" %}
/ Brouillons
{% endif %}
{% if sort == "abc" %}
/ Par ordre alphabétique
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ne serait-il pas mieux de "variabiliser" ces constantes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aie en effet, des comparairons de texte comme ça ne devrait pas avoir lieu. Il faut définir une classe en amont type_sort avec des conditions du style is_alpha, is_creation, etc.

{% elif sort == "creation" %}
/ Par date de création
{% elif sort == "modification" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le code et les constante doivent être en anglais exclusivement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu changerais quels noms ici ?

/ Par date de dernière modification
{% endif %}
{% endblock %}


Expand All @@ -50,6 +57,13 @@
{% elif request.GET.type == "draft" %}
/ Brouillons
{% endif %}
{% if sort == "abc" %}
/ Par ordre alphabétique
{% elif sort == "creation" %}
/ Par date de création
{% elif sort == "modification" %}
/ Par date de dernière modification
{% endif %}
{% endblock %}


Expand All @@ -64,29 +78,49 @@
<h3>Filtres</h3>
<ul>
<li>
<a href="{% url "zds.member.views.articles" %}?type=public" class="ico-after tick green {% if request.GET.type == "public" %}unread{% endif %}">
<a href="{% url "zds.member.views.articles" %}?{% if sort %}sort={{ sort }}&{% endif %}type=public" class="ico-after tick green {% if request.GET.type == "public" %}unread{% endif %}">
Publiés
</a>
</li>
<li>
<a href="{% url "zds.member.views.articles" %}?type=validate" class="ico-after tick {% if request.GET.type == "validate" %}unread{% endif %}">
<a href="{% url "zds.member.views.articles" %}?{% if sort %}sort={{ sort }}&{% endif %}type=validate" class="ico-after tick {% if request.GET.type == "validate" %}unread{% endif %}">
En validation
</a>
</li>
<li>
<a href="{% url "zds.member.views.articles" %}?type=draft" class="ico-after edit {% if request.GET.type == "draft" %}unread{% endif %}">
<a href="{% url "zds.member.views.articles" %}?{% if sort %}sort={{ sort }}&{% endif %}type=draft" class="ico-after edit {% if request.GET.type == "draft" %}unread{% endif %}">
Brouillons
</a>
</li>
{% if request.GET.type %}
<li>
<a href="{% url "zds.member.views.articles" %}" class="ico-after cross">
<a href="{% url "zds.member.views.articles" %}{% if sort %}?sort={{ sort }}{% endif %}" class="ico-after cross">
Annuler le filtre
</a>
</li>
{% endif %}
</ul>
</div>
<div class="mobile-menu-bloc mobile-all-links" data-title="Trier">
<h3>Trier</h3>
<ul>
<li>
<a href="{% url "zds.member.views.articles" %}?sort=abc{% if type %}&type={{ type }}{% endif %}" class="ico-after gear {% if sort == "abc" %}unread{% endif %}">
Par ordre alphabétique
</a>
</li>
<li>
<a href="{% url "zds.member.views.articles" %}?sort=creation{% if type %}&type={{ type }}{% endif %}" class="ico-after gear {% if sort == "creation" %}unread{% endif %}">
Par date de création
</a>
</li>
<li>
<a href="{% url "zds.member.views.articles" %}?sort=modification{% if type %}&type={{ type }}{% endif %}" class="ico-after gear {% if sort == "modification" %}unread{% endif %}">
Par date de dernière modification
</a>
</li>
</ul>
</div>
</aside>
{% endblock %}

Expand All @@ -104,4 +138,4 @@ <h3>Filtres</h3>
Aucun article disponible.
</p>
{% endif %}
{% endblock %}
{% endblock %}
46 changes: 40 additions & 6 deletions templates/tutorial/member/index.html
Expand Up @@ -14,6 +14,13 @@
{% elif request.GET.type == "draft" %}
/ Brouillons
{% endif %}
{% if sort == "abc" %}
/ Par ordre alphabétique
{% elif sort == "creation" %}
/ Par date de création
{% elif sort == "modification" %}
/ Par date de dernière modification
{% endif %}
{% endblock %}


Expand Down Expand Up @@ -54,6 +61,13 @@ <h2 class="ico-after ico-tutorials">
{% elif request.GET.type == "draft" %}
/ Brouillons
{% endif %}
{% if sort == "abc" %}
/ Par ordre alphabétique
{% elif sort == "creation" %}
/ Par date de création
{% elif sort == "modification" %}
/ Par date de dernière modification
{% endif %}
{% endblock %}
</h2>

Expand Down Expand Up @@ -113,33 +127,53 @@ <h3>{{ tutorial.title }}</h3>
<h3>Filtres</h3>
<ul>
<li>
<a href="{% url "zds.member.views.tutorials" %}?type=public" class="ico-after tick green {% if request.GET.type == "public" %}unread{% endif %}">
<a href="{% url "zds.member.views.tutorials" %}?type=public{% if sort %}&sort={{ sort }}{% endif %}" class="ico-after tick green {% if request.GET.type == "public" %}unread{% endif %}">
Publiés
</a>
</li>
<li>
<a href="{% url "zds.member.views.tutorials" %}?type=validate" class="ico-after tick {% if request.GET.type == "validate" %}unread{% endif %}">
<a href="{% url "zds.member.views.tutorials" %}?type=validate{% if sort %}&sort={{ sort }}{% endif %}" class="ico-after tick {% if request.GET.type == "validate" %}unread{% endif %}">
En validation
</a>
</li>
<li>
<a href="{% url "zds.member.views.tutorials" %}?type=beta" class="ico-after beta {% if request.GET.type == "beta" %}unread{% endif %}">
<a href="{% url "zds.member.views.tutorials" %}?type=beta{% if sort %}&sort={{ sort }}{% endif %}" class="ico-after beta {% if request.GET.type == "beta" %}unread{% endif %}">
En bêta
</a>
</li>
<li>
<a href="{% url "zds.member.views.tutorials" %}?type=draft" class="ico-after edit {% if request.GET.type == "draft" %}unread{% endif %}">
<a href="{% url "zds.member.views.tutorials" %}?type=draft{% if sort %}&sort={{ sort }}{% endif %}" class="ico-after edit {% if request.GET.type == "draft" %}unread{% endif %}">
Brouillons
</a>
</li>

{% if request.GET.type %}
<li>
<a href="{% url "zds.member.views.tutorials" %}" class="ico-after cross">
<a href="{% url "zds.member.views.tutorials" %}{% if sort %}?sort={{ sort }}{% endif %}" class="ico-after cross">
Annuler le filtre
</a>
</li>
{% endif %}
</ul>
<div class="mobile-menu-bloc mobile-all-links" data-title="Trier">
<h3>Trier</h3>
<ul>
<li>
<a href="{% url "zds.member.views.tutorials" %}?sort=abc{% if type %}&type={{ type }}{% endif %}" class="ico-after gear {% if sort == "abc" %}unread{% endif %}">
Par ordre alphabétique
</a>
</li>
<li>
<a href="{% url "zds.member.views.tutorials" %}?sort=creation{% if type %}&type={{ type }}{% endif %}" class="ico-after gear {% if sort == "creation" %}unread{% endif %}">
Par date de création
</a>
</li>
<li>
<a href="{% url "zds.member.views.tutorials" %}?sort=modification{% if type %}&type={{ type }}{% endif %}" class="ico-after gear {% if sort == "modification" %}unread{% endif %}">
Par date de dernière modification
</a>
</li>
</ul>
</div>
</div>
{% endblock %}
{% endblock %}
68 changes: 51 additions & 17 deletions zds/member/views.py
Expand Up @@ -366,58 +366,92 @@ def modify_profile(request, user_pk):
def tutorials(request):
"""Returns all tutorials of the authenticated user."""

# The type indicate what the user would like to display. We can display
# public, draft or all user's tutorials.
# The type indicate what the user would like to display. We can display public, draft or all user's tutorials.

try:
type = request.GET["type"]
type = request.GET['type']
except KeyError:
type = None

# The sort indicate the order of tutorials.

try:
sort_tuto = request.GET['sort']
except KeyError:
sort_tuto = 'abc'

# Retrieves all tutorials of the current user.

profile = request.user.profile
if type == "draft":
if type == 'draft':
user_tutorials = profile.get_draft_tutos()
elif type == "beta":
elif type == 'beta':
user_tutorials = profile.get_beta_tutos()
elif type == "validate":
elif type == 'validate':
user_tutorials = profile.get_validate_tutos()
elif type == "public":
elif type == 'public':
user_tutorials = profile.get_public_tutos()
else:
user_tutorials = profile.get_tutos()

return render_template("tutorial/member/index.html",
{"tutorials": user_tutorials, "type": type})
# Order articles (abc by default)

if sort_tuto == 'creation':
pass # nothing to do. Tutorials are already sort by creation date
elif sort_tuto == 'modification':
user_tutorials = user_tutorials.order_by('-update')
else:
user_tutorials = user_tutorials.extra(select={'lower_title': 'lower(title)'}).order_by('lower_title')

return render_template(
'tutorial/member/index.html',
{'tutorials': user_tutorials, 'type': type, 'sort': sort_tuto}
)


@login_required
def articles(request):
"""Returns all articles of the authenticated user."""

# The type indicate what the user would like to display. We can display
# public, draft or all user's articles.
# The type indicate what the user would like to display. We can display public, draft or all user's articles.

try:
type = request.GET["type"]
type = request.GET['type']
except KeyError:
type = None

# The sort indicate the order of articles.

try:
sort_articles = request.GET['sort']
except KeyError:
sort_articles = 'abc'

# Retrieves all articles of the current user.

profile = request.user.profile
if type == "draft":
if type == 'draft':
user_articles = profile.get_draft_articles()
if type == "validate":
if type == 'validate':
user_articles = profile.get_validate_articles()
elif type == "public":
elif type == 'public':
user_articles = profile.get_public_articles()
else:
user_articles = profile.get_articles()

return render_template("article/member/index.html",
{"articles": user_articles, "type": type})
# Order articles (abc by default)

if sort_articles == 'creation':
pass # nothing to do. Articles are already sort by creation date
elif sort_articles == 'modification':
user_articles = user_articles.order_by('-update')
else:
user_articles = user_articles.extra(select={'lower_title': 'lower(title)'}).order_by('lower_title')

return render_template(
'article/member/index.html',
{'articles': user_articles, 'type': type, 'sort': sort_articles}
)


# settings for public profile
Expand Down