Skip to content

Commit

Permalink
Merge pull request #1951 from gustavi/fix-1771-b
Browse files Browse the repository at this point in the history
Fix #1731: Ajout de la possibilité de trier ses articles/tutoriels
  • Loading branch information
GerardPaligot committed Dec 29, 2014
2 parents bcf8dcd + d0e7045 commit 1ab9f44
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 15 deletions.
44 changes: 39 additions & 5 deletions templates/article/member/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
{% elif request.GET.type == "draft" %}
/ {% trans "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 @@ -50,6 +57,13 @@
{% elif request.GET.type == "draft" %}
/ {% trans "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>{% trans "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 %}">
{% trans "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 %}">
{% trans "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 %}">
{% trans "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">
{% trans "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>{% trans "Filtres" %}</h3>
{% trans "Aucun article disponible" %}.
</p>
{% endif %}
{% endblock %}
{% endblock %}
46 changes: 40 additions & 6 deletions templates/tutorial/member/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
{% elif request.GET.type == "draft" %}
/ {% trans "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" %}
/ {% trans "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>{% trans "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 %}">
{% trans "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 %}">
{% trans "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 %}">
{% trans "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 %}">
{% trans "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">
{% trans "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 %}
47 changes: 43 additions & 4 deletions zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,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
Expand All @@ -393,21 +400,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
Expand All @@ -420,7 +446,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
Expand Down

0 comments on commit 1ab9f44

Please sign in to comment.