diff --git a/templates/article/member/index.html b/templates/article/member/index.html index b58264bdcc..cb5944f020 100644 --- a/templates/article/member/index.html +++ b/templates/article/member/index.html @@ -37,6 +37,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 %} @@ -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 %} @@ -64,29 +78,49 @@

Filtres

+ {% endblock %} @@ -104,4 +138,4 @@

Filtres

Aucun article disponible.

{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/tutorial/member/index.html b/templates/tutorial/member/index.html index 5e007496b3..e5bf5d4c81 100644 --- a/templates/tutorial/member/index.html +++ b/templates/tutorial/member/index.html @@ -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 %} @@ -54,6 +61,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 %}

@@ -113,33 +127,53 @@

{{ tutorial.title }}

Filtres

+ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/zds/member/views.py b/zds/member/views.py index 594fdb8b06..84edb27c0c 100644 --- a/zds/member/views.py +++ b/zds/member/views.py @@ -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