It seems I have fixed both bugs \#8 and \#10: add bugs priorities and complexities.

portnov [2008-06-14 05:06:06]
It seems I have fixed both bugs \#8 and \#10: add bugs priorities and complexities.
Filename
media/css/main.css
mgmt/models.py
mgmt/rights.py
mgmt/views.py
settings.py
templates/bug.html
templates/bug_body.html
templates/project_bugs.html
diff --git a/media/css/main.css b/media/css/main.css
index aad1b1c..ddaedb1 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -230,6 +230,19 @@ span.pager {
   background: white;
 }

+.bug-priority {
+  text-align: right;
+  float: right;
+  max-width: 15em;
+  border: 1px #888 solid;
+  padding: 0.5ex;
+  font-size: small;
+}
+
+.bug-priority p {
+  margin: 0;
+}
+
 .bug {
   border: 1px #888 solid;
   padding: 1ex;
diff --git a/mgmt/models.py b/mgmt/models.py
index ec20a66..d1b3f3a 100644
--- a/mgmt/models.py
+++ b/mgmt/models.py
@@ -54,7 +54,7 @@ class Bug(Object):
   class Meta:
     verbose_name = _("Bug")
     verbose_name_plural = _("Bugs")
-    ordering = ("-created",)
+    ordering = ("-priority","complexity","-created")
   class Admin:
     pass

diff --git a/mgmt/rights.py b/mgmt/rights.py
index 6c9568e..69544e8 100644
--- a/mgmt/rights.py
+++ b/mgmt/rights.py
@@ -30,7 +30,12 @@ def can(user,action,object=None,target=None):
   if action == 'document':
     return user in object.team.iterator()
   if object.__class__.__name__ == 'Bug':
-    return can_change_bug_state(user,object,target)
+    if action == 'set_priority':
+      return user in object.project.admins.iterator()
+    if action == 'set_complexity':
+      return user in object.project.team.iterator()
+    if action == 'change_state':
+      return can_change_bug_state(user,object,target)
   return False

 def possible_changes(bug,user):
diff --git a/mgmt/views.py b/mgmt/views.py
index 879304f..56f97f1 100644
--- a/mgmt/views.py
+++ b/mgmt/views.py
@@ -55,6 +55,12 @@ class BugForm(forms.Form):
   unexpected = forms.CharField(widget=forms.Textarea())
   text = forms.CharField(widget=forms.Textarea())

+class BugPriorityForm(forms.Form):
+  priority = forms.ChoiceField(settings.PRIORITY_CHOICES,required=False)
+
+class BugComplexityForm(forms.Form):
+  complexity = forms.ChoiceField(settings.COMPLEXITY_CHOICES,required=False)
+
 class DocForm(forms.Form):
   name = forms.CharField()
   text = forms.CharField(widget=forms.Textarea())
@@ -118,6 +124,9 @@ def one_project(request,id):
 def project_bugs(request,id):
   project = Project.objects.get(pk=id)
   bugs = Bug.objects.filter(project=project)
+  for bug in bugs:
+    bug.complexity_str = dict(settings.COMPLEXITY_CHOICES).get(bug.complexity,'Unknown')
+    bug.priority_str = dict(settings.PRIORITY_CHOICES).get(bug.priority,'Unset')
   can_report = can(request.user,'send bug')
   return render_it('project_bugs.html',
       {'project': project,
@@ -146,6 +155,7 @@ def bug_report(request,pid):
           actions=actions,
           expected=expected,
           unexpected=unexpected,
+          priority=-1,
           text = text)
       b.save()
       return HttpResponseRedirect(reverse('mgmt.views.project_bugs',args=(pid,)))
@@ -235,6 +245,14 @@ def one_bug(request,id):
       bug.status = BugState.objects.get(pk=new_state)
       if bug.status.id==3:
         bug.responsible = request.user
+      if bug.status.id in [1,4,5]:
+        bug.priority=-1
+      bug.save()
+    elif request.POST['action']=='set_priority':
+      bug.priority =request.POST['priority']
+      bug.save()
+    elif request.POST['action']=='set_complexity':
+      bug.complexity = request.POST['complexity']
       bug.save()
   curr,pages,comments = get_comments(request,bug.id,'Bug')
   change_states = possible_changes(bug,request.user)
@@ -247,6 +265,14 @@ def one_bug(request,id):
     state_form = BugStateForm()
   else:
     state_form = None
+  if can(request.user,'set_priority',bug):
+    priority_form = BugPriorityForm(dict(priority=bug.priority))
+  else:
+    priotity_form = None
+  if can(request.user,'set_complexity',bug):
+    complexity_form = BugComplexityForm(dict(complexity=bug.complexity))
+  else:
+    complexity_form = None
   if can(request.user,'comment'):
     form = CommentForm()
   else:
@@ -255,6 +281,8 @@ def one_bug(request,id):
     edit_link = '/bugs/%s/edit/' % bug.id
   else:
     edit_link = None
+  priority = dict(settings.PRIORITY_CHOICES).get(bug.priority,u'Unset')
+  complexity = dict(settings.COMPLEXITY_CHOICES).get(bug.complexity,'Unknown')
   return render_it('bug.html',
       {'bug': bug,
        'change_state': state_form,
@@ -263,6 +291,10 @@ def one_bug(request,id):
        'current_page': curr,
        'page_numbers': pages,
        'comments': comments,
+       'priority': priority,
+       'complexity': complexity,
+       'priority_form': priority_form,
+       'complexity_form': complexity_form,
        'form': form},
        request)

diff --git a/settings.py b/settings.py
index b3a26a2..4238190 100644
--- a/settings.py
+++ b/settings.py
@@ -120,3 +120,19 @@ ROOT = "/home/portnov/www/projects/"
 COLORS = [(0.9,0.9,0.5),
           (0.2,0.2,0.9),
           (0.2,0.9,0.2)]
+
+PRIORITY_CHOICES = [(-1,u'Не установлен'),
+                    (0,u'Не обязательно'),
+                    (1,u'Надо бы'),
+                    (2,u'Низкий'),
+                    (3,u'Средний'),
+                    (4,u'Высокий'),
+                    (5,u'Первоочередной')]
+
+COMPLEXITY_CHOICES = [(0,u'Тривиально'),
+                      (1,u'Совсем просто'),
+                      (2,u'Несложно'),
+                      (3,u'Средняя сложность'),
+                      (4,u'Сложно'),
+                      (5,u'Очень сложно'),
+                      (6,u'Потребует изменения архитектуры')]
diff --git a/templates/bug.html b/templates/bug.html
index b8ccf6f..07e0848 100644
--- a/templates/bug.html
+++ b/templates/bug.html
@@ -7,8 +7,16 @@
 {% include "bug_body.html" %}

 {% if change_state %}
-<h3>Сменить состояние бага</h3>
-{% form change_state "<input type='hidden' name='action' value='change_state'/>" %}
+  <h3>Сменить состояние бага</h3>
+  {% form change_state "<input type='hidden' name='action' value='change_state'/>" %}
+{% endif %}
+{% if priority_form %}
+  <h3>Установить приоритет</h3>
+  {% form priority_form "<input type='hidden' name='action' value='set_priority'/>" %}
+{% endif %}
+{% if complexity_form %}
+  <h3>Указать сложность исправления</h3>
+  {% form complexity_form "<input type='hidden' name='action' value='set_complexity'/>" %}
 {% endif %}

 {% include "comments.html" %}
diff --git a/templates/bug_body.html b/templates/bug_body.html
index a27a78c..f158658 100644
--- a/templates/bug_body.html
+++ b/templates/bug_body.html
@@ -7,6 +7,10 @@
         {% if edit_link %}
           <div class='links'><a href='{{edit_link}}'>Изменить</a></div>
         {% endif %}
+        <div class='bug-priority'>
+          <p><strong>Приоритет:</strong> {{priority}}</p>
+          <p><strong>Сложность:</strong> {{complexity}}</p>
+        </div>
         {% if bug.component %}
           <p><strong>Компонент:</strong> {{bug.component}}</p>
         {% endif %}
diff --git a/templates/project_bugs.html b/templates/project_bugs.html
index 2f421b9..9bbb530 100644
--- a/templates/project_bugs.html
+++ b/templates/project_bugs.html
@@ -24,6 +24,10 @@
         {% if edit_link %}
           <div class='links'><a href='{{edit_link}}'>Изменить</a></div>
         {% endif %}
+        <div class='bug-priority'>
+          <p><strong>Приоритет:</strong> {{bug.priority_str}}</p>
+          <p><strong>Сложность:</strong> {{bug.complexity_str}}</p>
+        </div>
         {% if bug.component %}
           <p><strong>Компонент:</strong> {{bug.component}}</p>
         {% endif %}
ViewGit