Commits

Matthew Schinckel committed 1c3ff7f

Actually mark a notification as read.
Template improvements.

  • Participants
  • Parent commits bf45ca9

Comments (0)

Files changed (5)

File notifications/models.py

         return id2slug(self.id)
 
     def mark_as_read(self):
-        if self.marked_read_at:
+        if not self.marked_read_at:
             self.marked_read_at = now()
             self.save()
 

File notifications/templates/notifications/empty.html

+<script>
+require(['jquery'], function($) {
+  $('#notification-{{ notice.pk }}').detach();
+});
+</script>

File notifications/templates/notifications/list.html

 
 <ul class="notifications nav-list nav-pills nav-stacked" style="list-style: none; padding: 0; margin: 0">
   <li class="nav-header">
-    <a href="#" class="pull-right cancel">
-      <i class="icon-remove"></i>
-    </a>
     Notifications
   </li>
   <li>

File notifications/templates/notifications/notice.html

-<li class="notification" style="border-bottom: 1px solid silver; margin: 0 -20px; padding: 7px 5px 0 15px">
+{% load url from future %}
+
+<li class="notification" 
+    id="notification-{{ notice.pk }}"
+    style="border-bottom: 1px solid silver; margin: 0 -20px; padding: 7px 5px 0 15px">
   <p>
+    <form action="{% url 'notifications:mark_as_read' notice.slug %}" class="pull-right dynamic-form mark-as-read" method="post">
+      {% csrf_token %}
+      <button type="submit" class="remove btn-link">
+        <i class="icon-remove"></i>
+      </button>
+    </form>
     {{ notice.summary }}
   </p>
   <p>{{ notice.timestamp|timesince }} ago</p>
   {% if 'actions' in notice.data %}
   <p>
     {% for action in notice.data.actions %}
-    <form action="{{ action.href }}" method="{{ action.method }}" class="form form-inline dynamic-form discard-response">
-      {% if action.method.lower == 'post' %}
-        {% csrf_token %}
+    
+      {% if true or action.data %}
+        {# This is an action that will submit a form. #}
+        <form 
+          action="{{ action.href }}" 
+          method="{{ action.method }}" 
+          class="form form-inline {% if not action.followa %}dynamic-form{% endif %} {% if action.dismiss %}mark-as-read{% endif %}">
+      
+          {% if action.method.lower == 'post' %}
+            {% csrf_token %}
+          {% endif %}
+      
+          {% for item in action.data %}
+            <input type="hidden" name="{{ item.name }}" value="{{ item.value }}">
+          {% endfor %}
+      
+          <button class="btn {% if action.level %}btn-{{ action.level }}{% endif %} btn-small" type="submit">
+            {% if action.icon %}<i class="icon-{{ action.icon }}"></i>{% endif %}
+            {{ action.title }}
+          </button>
+      
+        </form>
+      {% else %}
+        {# This is a link we want to follow. New window? #}
+        <a href="{{ action.href }}#{{ action.hash}}" class="btn {% if action.level %}btn-{{ action.level }}{% endif %} btn-small">
+          {% if action.icon %}<i class="icon-{{ action.icon }}"></i>{% endif %}
+          {{ action.title }}
+        </a>
+        
       {% endif %}
-      {% for item in action.data %}
-        <input type="hidden" name="{{ item.name }}" value="{{ item.value }}">
-      {% endfor %}
-      <button class="btn" type="submit">
-        {% if action.icon %}<i class="icon-{{ action.icon }}"></i>{% endif %}
-        {{ action.title }}
-      </button>
-    </form>
     {% endfor %}
   </p>
   {% endif %}

File notifications/views.py

     if not notification.data.get('followup_required', None):
         notification.mark_as_read()
     
-    return unread(request)
+    return render(request, 'notifications/empty.html', {
+        'notice': notification
+    })
 
 @login_required
 @allow(['GET'])