Commits

Lukasz Balcerzak committed 518c6e0

Small timeline entry update at project details page

Comments (0)

Files changed (2)

 from django.db.models.signals import post_save
 from projector.models import Project
+from projector.models import Task
 
 
 def action_project_created(sender, instance, created, **kwargs):
     elif created:
         instance.create_action("created")
 
+
+def action_task_saved(sender, instance, created, **kwargs):
+
+    if created:
+        instance.project.create_action("created new task",
+            author=instance.editor, action_object=instance)
+    else:
+        try:
+            last_rev = instance.taskrevision_set\
+                .select_related('status')\
+                .order_by('-created_at')[1]
+            if instance.status.is_resolved and not last_rev.status.is_resolved:
+                verb = "resolved"
+            elif not instance.status.is_resolved and last_rev.status.is_resolved:
+                verb = "reopened"
+            else:
+                verb = "updated"
+            instance.project.create_action(verb, action_object=instance,
+                author=instance.editor)
+        except IndexError:
+            pass
+
+
+def pushed(sender, **kwargs):
+    import logging
+    logging.critical("Pushing!")
+    logging.debug("Sender: %s" % sender)
+    logging.debug("kwargs: %s" % kwargs)
+
 def actions_start_listening():
     """
     Register handlers for users activity.
     """
     post_save.connect(action_project_created, sender=Project)
+    post_save.connect(action_task_saved, sender=Task)
 
+    from vcs.web.simplevcs.signals import post_push
+    post_push.connect(pushed, sender=None)
+

projector/templates/projector/project/detail.html

 
         <h2>{% trans "Timeline" %}:</h2>
         <ul class="nav-vertical">
+            {% for action in project.actions.all %}
+            <li>
+                {{ action.author }} {% trans action.verb %}
+                {% if action.action_object %}
+                    {{ action_object }} {% trans "on" %}
+                {% endif %}
+                {{ action.project }} {{ action.created_at|timesince }} {% trans "ago" %}
+            </li>
+            {% empty %}
+            <li>
+                <ul class="messages">
+                    <li class="message message-info">{% trans "No timeline entries defined yet" %}</li>
+                </ul>
+            </li>
+            {% endfor %}
+
+            {% comment %}
             {% for entry in project.timelineentry_set.all %}
             <li>
                 {% if entry.user %}
                 </ul>
             </li>
             {% endfor %}
+            {% endcomment %}
         </ul>
         
     </div>