changeset 802:dbc389a409f5

Work in progress: rework private messages. Add trash view.
author Brian Neal <bgneal@gmail.com>
date Sat, 30 Aug 2014 19:11:32 -0500
parents 6bbd1473d48e
children b3eeaefc39a8
files messages/urls.py messages/views.py sg101/templates/messages/inbox.html sg101/templates/messages/messages_base.html sg101/templates/messages/outbox.html sg101/templates/messages/trash.html sg101/templates/messages/trash_tab.html
diffstat 7 files changed, 65 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/messages/urls.py	Sat Aug 30 17:25:38 2014 -0500
+++ b/messages/urls.py	Sat Aug 30 19:11:32 2014 -0500
@@ -15,9 +15,9 @@
     url(r'^outbox/$',
         'messages.views.outbox',
         name='messages-outbox'),
-#   url(r'^trash/$',
-#       'messages.views.trash',
-#       name='messages-trash'),
+    url(r'^trash/$',
+        'messages.views.trash',
+        name='messages-trash'),
 #   url(r'^options/$',
 #       'messages.views.options',
 #       name='messages-options'),
--- a/messages/views.py	Sat Aug 30 17:25:38 2014 -0500
+++ b/messages/views.py	Sat Aug 30 19:11:32 2014 -0500
@@ -97,6 +97,21 @@
 
 
 @login_required
+def trash(request):
+
+    msg_list = Message.objects.trash(request.user)
+
+    page = _get_page(request, msg_list)
+
+    return render(request, 'messages/trash.html', {
+        'tab': 'trash',
+        'page': page,
+        'inbox_pct': None,
+        'outbox_pct': None,
+        })
+
+
+@login_required
 def compose_to(request, receiver):
     """
     This function displays the base tabbed private messages view,
@@ -113,27 +128,6 @@
         })
 
 
-def trash(request):
-    """
-    Returns the trash for the user.
-
-    """
-    if not request.user.is_authenticated():
-        return HttpResponseForbidden()
-
-    msg_list = Message.objects.trash(request.user)
-    paginator = Paginator(msg_list, MSGS_PER_PAGE)
-    try:
-        msgs = paginator.page(_get_page(request))
-    except (EmptyPage, InvalidPage):
-        msgs = paginator.page(paginator.num_pages)
-
-    return render(request, 'messages/trash_tab.html', {
-        'msgs': msgs,
-        'url': reverse('messages-trash'),
-        })
-
-
 def message(request):
     """
     This view function retrieves a message and returns it as a JSON object.
--- a/sg101/templates/messages/inbox.html	Sat Aug 30 17:25:38 2014 -0500
+++ b/sg101/templates/messages/inbox.html	Sat Aug 30 19:11:32 2014 -0500
@@ -6,6 +6,7 @@
 Messages in <em>italics</em> have been replied to.
 </p>
 {% if page.object_list %}
+   {% include "messages/pagination.html" %}
    <form action="." onsubmit="return bulkMsgAction(this, 'delete');">
    <table class="messages">
    <tr>
--- a/sg101/templates/messages/messages_base.html	Sat Aug 30 17:25:38 2014 -0500
+++ b/sg101/templates/messages/messages_base.html	Sat Aug 30 19:11:32 2014 -0500
@@ -23,8 +23,8 @@
 {% endcomment %}
    <li>{% if tab != 'outbox' %}<a href="{% url 'messages-outbox' %}">{% endif %}Outbox{% if tab != 'outbox' %}</a>{% endif %}
       {% if outbox_pct %}({{ outbox_pct }}% used){% endif %}</li>
+   <li>{% if tab != 'trash' %}<a href="{% url 'messages-trash' %}">{% endif %}Trash{% if tab != 'trash' %}</a>{% endif %}</li>
 {% comment %}
-   <li>{% if tab != 'trash' %}<a href="{% url 'messages-trash' %}">{% endif %}Trash{% if tab != 'trash' %}</a>{% endif %}</li>
    <li>{% if tab != 'options' %}<a href="{% url 'messages-options' %}">{% endif %}Options{% if tab != 'options' %}</a>{% endif %}</li>
 {% endcomment %}
 </ul>
--- a/sg101/templates/messages/outbox.html	Sat Aug 30 17:25:38 2014 -0500
+++ b/sg101/templates/messages/outbox.html	Sat Aug 30 19:11:32 2014 -0500
@@ -6,6 +6,7 @@
 by the recipient. Messages in <em>italics</em> have been replied to.
 </p>
 {% if page.object_list %}
+   {% include "messages/pagination.html" %}
    <form action="." onsubmit="return bulkMsgAction(this, 'delete');">
    <table class="messages"> 
    <tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/templates/messages/trash.html	Sat Aug 30 19:11:32 2014 -0500
@@ -0,0 +1,44 @@
+{% extends 'messages/messages_base.html' %}
+{% block messages_content %}
+<h3>Trash <small>(Page {{ page.number }} of {{ page.paginator.num_pages }})</small></h3>
+<p>
+This is your trash folder. It contains messages that you have deleted. The messages will be gone
+forever when the other party deletes their copies. Until that happens you can undelete them to move
+them back to either the inbox or outbox. 
+</p>
+<p>
+Messages in <strong>bold</strong> are unread.  Messages in <em>italics</em> have been replied to.
+</p>
+{% if page.object_list %}
+   {% include "messages/pagination.html" %}
+   <form action="." onsubmit="return bulkMsgAction(this, 'undelete');">
+   <table class="messages">
+   <tr>
+      <th>From</th>
+      <th>To</th>
+      <th>Subject</th>
+      <th>Date</th>
+      <th><input type="checkbox" onclick="tabMasterCheckClick(this, 'trash_ids');" /></th>
+   </tr>
+   {% for msg in page.object_list %}
+   <tr>
+      <td><a href="{% url 'bio.views.view_profile' msg.sender.username %}">
+         {{ msg.sender.username }}</a></td>
+      <td><a href="{% url 'bio.views.view_profile' msg.receiver.username %}">
+         {{ msg.receiver.username }}</a></td>
+      <td>
+         <a href="#" onclick="msgShow(this, {{ msg.id }}); return false;"
+            class="{% if msg.unread %}unread {% endif %}{% if msg.replied_to %}replied_to{% endif %}">{{ msg.subject }}</a>
+         </td>
+      <td>{{ msg.send_date|date:"M j, Y g:i:s A T" }}</td>
+      <td><input type="checkbox" name="trash_ids" value="{{ msg.id }}" /></td>
+   </tr>
+   {% endfor %}
+   <tr><td colspan="5"><input type="submit" value="Undelete Checked Messages" /></td></tr>
+   </table>
+   </form>
+   {% include "messages/pagination.html" %}
+{% else %}
+   <p><em>Your Trash is empty.</em></p>
+{% endif %}
+{% endblock %}
--- a/sg101/templates/messages/trash_tab.html	Sat Aug 30 17:25:38 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-{% if messages %}
-<ul class="user-messages">
-   {% for msg in messages %}
-      <li{% if msg.tags %} class="{{ msg.tags }}"{% endif %}>{{ msg }}</li>
-   {% endfor %}
-</ul>
-{% endif %}
-{% if msgs.object_list %}
-   <form action="." onsubmit="return bulkMsgAction(this, 'undelete');">
-   <table class="messages">
-   <tr>
-      <th>From</th>
-      <th>To</th>
-      <th>Subject</th>
-      <th>Date</th>
-      <th><input type="checkbox" onclick="tabMasterCheckClick(this, 'trash_ids');" /></th>
-   </tr>
-   {% for msg in msgs.object_list %}
-   <tr>
-      <td><a href="{% url 'bio.views.view_profile' msg.sender.username %}">
-         {{ msg.sender.username }}</a></td>
-      <td><a href="{% url 'bio.views.view_profile' msg.receiver.username %}">
-         {{ msg.receiver.username }}</a></td>
-      <td>
-         <a href="#" onclick="msgShow(this, {{ msg.id }}); return false;"
-            class="{% if msg.unread %}unread {% endif %}{% if msg.replied_to %}replied_to{% endif %}">{{ msg.subject }}</a>
-         </td>
-      <td>{{ msg.send_date|date:"M j, Y g:i:s A T" }}</td>
-      <td><input type="checkbox" name="trash_ids" value="{{ msg.id }}" /></td>
-   </tr>
-   {% endfor %}
-   <tr><td colspan="5"><input type="submit" value="Undelete Checked Messages" /></td></tr>
-   </table>
-   </form>
-   {% include "messages/pagination.html" %}
-   <ul>
-      <li>Messages in <strong>bold</strong> are unread.</li>
-      <li>Messages in <em>italics</em> have been replied to.</li>
-   </ul>
-{% else %}
-   <p><em>Your Trash is empty.</em></p>
-{% endif %}