Add pie chart to show how many bugs are in each state.

portnov [2008-06-09 16:10:26]
Add pie chart to show how many bugs are in each state.
Filename
.gitignore
media/css/main.css
mgmt/context.py
templates/all_bugs.html
templates/base.html
diff --git a/.gitignore b/.gitignore
index 64dc10f..366c13d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@
 .*.swp
 *.swp
 *.pyc
+mgmt/hms
+media/charts
diff --git a/media/css/main.css b/media/css/main.css
index ec09b4e..b1a7826 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -67,4 +67,25 @@ p.date {
 .bug {
   border: 1px #888 solid;
   padding: 1ex;
+  margin-bottom: 1ex;
+}
+
+.bug-state-1 {
+  background: #ccf;
+}
+
+.bug-state-2 {
+  background: #fcc;
+}
+
+.bug-state-3 {
+  background: #ffc;
+}
+
+.bug-state-4 {
+  background: #cfc;
+}
+
+.bug-state-5 {
+  background: #ccc;
 }
diff --git a/mgmt/context.py b/mgmt/context.py
index af7d7ef..c3b6d72 100644
--- a/mgmt/context.py
+++ b/mgmt/context.py
@@ -9,10 +9,32 @@ import settings
 from hms import hms
 import debug

+from models import *
+
 show_blocks = dict(
     last_comments = dict(),
     login   = dict(hide='/login/$',show_logged=False))

+def make_chart(path):
+  p1 = re.compile('/projects/(\d+)/$')
+  m = p1.match(path)
+  if m:
+    pid = int(m.group(1))
+    project=Project.objects.get(pk=pid)
+    d=[]
+    sts = BugState.objects.all()
+    for s in sts:
+      d.append(Bug.objects.filter(project=project, status=s).count())
+    title = u'<h3>Баги в проекте %s</h3>\n' % project.name
+    return title+hms.modules.bug_chart(d)
+  else:
+    d=[]
+    sts = BugState.objects.all()
+    for s in sts:
+      d.append(Bug.objects.filter(status=s).count())
+    title = u'<h3>Баги во всех проектах</h3>\n'
+    return title+hms.modules.bug_chart(d)
+
 def add_blocks(request):
   blocks = {}
   logged = request.user.is_authenticated()
@@ -36,7 +58,7 @@ def add_blocks(request):
     log_msg = u'Вы вошли в систему как %s.' % request.user.username
   else:
     log_msg = u'Вы не вошли.'
-  return dict(blocks=blocks,login_message=log_msg)
+  return dict(blocks=blocks,login_message=log_msg, chart=make_chart(request.path))

 def add_menu(request):
   menu = hms.modules.menu(request)
diff --git a/templates/all_bugs.html b/templates/all_bugs.html
index c6fed34..9b07be2 100644
--- a/templates/all_bugs.html
+++ b/templates/all_bugs.html
@@ -9,7 +9,7 @@

 <div class='bugs'>
 {% for bug in bugs %}
-    <div class='bug bug-state-{{bug.status}}'>
+    <div class='bug bug-state-{{bug.status.id}}'>
       <p><strong>{{bug.name}}</strong></p>
       <div class='project-link'>{{bug.project|link|safe}}</div>
       <p>{{bug.text}}</p>
diff --git a/templates/base.html b/templates/base.html
index c24ef65..40408c8 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -31,6 +31,7 @@
       <div id='blocks'>
       {{blocks.login|safe}}
       {{blocks.last_comments|safe}}
+      {{chart|safe}}
       </div>
     {% endif %}
ViewGit