Repository: zestedesavoir/zds-site

Issue:
Ajout d'un filtre « Trier par ordre alphabétique » dans les articles et tutoriels
Via [Guy](http://zestedesavoir.com/membres/voir/Guy/) sur le [forum](http://zestedesavoir.com/forums/sujet/1645/proposition-assez-simple-sur-les-pages-mes-tutoriels-et-mes-articles/?page=1#p28696) : 

> Petite proposition, qui concerne les pages "mes tutoriels" et "mes articles", sur lesquelles on voit quels sont les tutoriels/articles que l'on a rédigé : trier les écrits par ordre alphabétique plutôt que par ordre de création. C'est plus facile de s'y repérer pour les gens qui ont beaucoup de tutoriels.



Discussion:

Resolving patch:
diff --git a/zds/member/views.py b/zds/member/views.py
--- a/zds/member/views.py
+++ b/zds/member/views.py
@@ -378,6 +378,13 @@ def tutorials(request):
     except KeyError:
         state = 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
@@ -392,21 +399,40 @@ def tutorials(request):
     else:
         user_tutorials = profile.get_tutos()
 
-    return render(request, 'tutorial/member/index.html', {'tutorials': user_tutorials, 'type': state})
+    # 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(
+        request,
+        'tutorial/member/index.html',
+        {'tutorials': user_tutorials, 'type': state, '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:
         state = request.GET['type']
     except KeyError:
         state = 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
@@ -419,7 +445,20 @@ def articles(request):
     else:
         user_articles = profile.get_articles()
 
-    return render(request, 'article/member/index.html', {'articles': user_articles, 'type': state})
+    # 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(
+        request,
+        'article/member/index.html',
+        {'articles': user_articles, 'type': type, 'sort': sort_articles}
+    )
 
 
 # settings for public profile


Test patch: