Mercurial > public > sg101
changeset 809:ab3deff7672a
Private message refactoring: fix up various template issues.
Added a template tag to generate the URL to send a PM to a user.
This replaced the {% url 'messages-compose_to' username %} in various
templates.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 01 Sep 2014 17:05:30 -0500 |
parents | 0f0ba45704b7 |
children | 4a4fa174a0ec |
files | messages/templatetags/messages_tags.py sg101/templates/base.html sg101/templates/bio/members.html sg101/templates/bio/view_profile.html sg101/templates/forums/display_post.html sg101/templates/messages/unread_messages_tag.html |
diffstat | 6 files changed, 18 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/messages/templatetags/messages_tags.py Mon Sep 01 16:38:06 2014 -0500 +++ b/messages/templatetags/messages_tags.py Mon Sep 01 17:05:30 2014 -0500 @@ -1,8 +1,10 @@ """ Template tags for the messages application. + """ from django import template from django.core.urlresolvers import reverse +from django.utils.http import urlquote from messages.models import Message @@ -13,3 +15,9 @@ def unread_messages(user): unread_count = Message.objects.unread_count(user) return {'unread_count': unread_count} + + +@register.simple_tag +def send_pm_url(username): + """Returns the URL to send a PM to a given username""" + return reverse('messages-compose') + '?to={}'.format(urlquote(username))
--- a/sg101/templates/base.html Mon Sep 01 16:38:06 2014 -0500 +++ b/sg101/templates/base.html Mon Sep 01 17:05:30 2014 -0500 @@ -53,7 +53,7 @@ <li><a href="{% url 'irc-main' %}">IRC</a></li> <li><a href="{% url 'bio-member_list' type='user' %}">Member List</a></li> <li><a href="{% url 'membermap-index' %}">Member Map</a></li> - <li><a href="{% url 'messages-index' %}">Private Messages</a></li> + <li><a href="{% url 'messages-inbox' %}">Private Messages</a></li> <li><a href="{% url 'podcast-main' %}">Podcast</a></li> <li><a href="{% url 'polls-main' %}">Polls</a></li> <li><a href="{% url 'potd-view' %}">Photo of the Day</a></li>
--- a/sg101/templates/bio/members.html Mon Sep 01 16:38:06 2014 -0500 +++ b/sg101/templates/bio/members.html Mon Sep 01 17:05:30 2014 -0500 @@ -1,6 +1,7 @@ {% extends 'bio/base.html' %} {% load cycle from future %} {% load bio_tags %} +{% load messages_tags %} {% block title %}Member List{% endblock %} {% block bio_css %} <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/tab-nav.css" /> @@ -40,7 +41,7 @@ <td>{{ u.profile.location }}</td> <td>{{ u.date_joined|date:"M. d, Y" }}</td> <td> - {% ifnotequal user u %}<a href="{% url 'messages-compose_to' u.username %}"> + {% ifnotequal user u %}<a href="{% send_pm_url u.username %}"> <img src="{{ STATIC_URL }}icons/note.png" alt="PM" title="Send private message" /></a>{% endifnotequal %} {% if not u.profile.hide_email %}<a href="mailto:{{ u.email }}"> <img src="{{ STATIC_URL }}icons/email.png" alt="Email" title="Send Email" /></a>{% endif %}
--- a/sg101/templates/bio/view_profile.html Mon Sep 01 16:38:06 2014 -0500 +++ b/sg101/templates/bio/view_profile.html Mon Sep 01 17:05:30 2014 -0500 @@ -3,6 +3,7 @@ {% load elsewhere_tags %} {% load core_tags %} {% load forum_tags %} +{% load messages_tags %} {% block title %}User Profile for {{ subject.username }}{% endblock %} {% block custom_js %} <script type="text/javascript"> @@ -94,7 +95,7 @@ {% else %} {% if user.is_authenticated %} <ul class="icon-list"> - <li><a href="{% url 'messages-compose_to' subject.username %}"><img src="{{ STATIC_URL }}icons/note.png" alt="PM" title="Send Private Message" /></a> <a href="{% url 'messages-compose_to' subject.username %}">Send a private message to {{ subject.username }}</a></li> + <li><a href="{% send_pm_url subject.username %}"><img src="{{ STATIC_URL }}icons/note.png" alt="PM" title="Send Private Message" /></a> <a href="{% send_pm_url subject.username %}">Send a private message to {{ subject.username }}</a></li> <li><a href="{% url 'forums-posts_for_user' username=subject.username %}"><img src="{{ STATIC_URL }}icons/comments.png" alt="Forum Posts" title="View forum posts by {{ subject.username }}" /></a> <a href="{% url 'forums-posts_for_user' username=subject.username %}">View forum posts by {{ subject.username }}</a></li> <li><a href="{% url 'user_photos-gallery' username=subject.username %}"><img src="{{ STATIC_URL }}icons/pictures.png"
--- a/sg101/templates/forums/display_post.html Mon Sep 01 16:38:06 2014 -0500 +++ b/sg101/templates/forums/display_post.html Mon Sep 01 17:05:30 2014 -0500 @@ -1,5 +1,6 @@ {% load bio_tags %} {% load forum_tags %} +{% load messages_tags %} <tr class="forum-post {{ rowcolors }}" id="post-{{ post.id }}"> <td class="forum-post-author"> <a name="p{{ post.id }}"></a> @@ -18,7 +19,7 @@ {% endfor %} {% if user.is_authenticated %} <p> - <a href="{% url 'messages-compose_to' post.user.username %}"> + <a href="{% send_pm_url post.user.username %}"> <img src="{{ STATIC_URL }}icons/note.png" alt="PM" title="Send Private Message to {{ post.user.username }}" /></a> {% if not post.user.profile.hide_email %}<a href="mailto:{{ post.user.email }}"> <img src="{{ STATIC_URL }}icons/email.png" alt="Email" title="Send Email to {{ post.user.username}}" /></a>{% endif %}
--- a/sg101/templates/messages/unread_messages_tag.html Mon Sep 01 16:38:06 2014 -0500 +++ b/sg101/templates/messages/unread_messages_tag.html Mon Sep 01 17:05:30 2014 -0500 @@ -1,9 +1,5 @@ {% if unread_count == 0 %} -<a href="{% url 'messages-index' %}"><span id="unread_msg_text">Private Messages</span></a> +<a href="{% url 'messages-inbox' %}"><span id="unread_msg_text">Private Messages</span></a> +{% else %} +<a href="{% url 'messages-inbox' %}"><span id="unread_msg_text">{{ unread_count }} New Message{{ unread_count|pluralize }}</span></a> {% endif %} -{% if unread_count == 1 %} -<a href="{% url 'messages-index' %}"><span id="unread_msg_text">1 New Message</span></a> -{% endif %} -{% if unread_count > 1 %} -<a href="{% url 'messages-index' %}"><span id="unread_msg_text">{{ unread_count }} New Messages</span></a> -{% endif %}