Add personal info pages for each user.

portnov [2008-06-10 15:09:44]
Add personal info pages for each user.
Filename
media/css/main.css
mgmt/views.py
pygit/chart.py
pygit/pygit.py
pygit/views.py
templates/all_bugs.html
templates/user_page.html
urls.py
diff --git a/media/css/main.css b/media/css/main.css
index 02daebf..a07d469 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -18,6 +18,10 @@ a:hover {
   color: #0b0;
 }

+table {
+  width: 100%;
+}
+
 td {
   border-right: 1px #ddd solid;
   border-bottom: 1px #888 solid;
diff --git a/mgmt/views.py b/mgmt/views.py
index 21da2fd..666d90c 100644
--- a/mgmt/views.py
+++ b/mgmt/views.py
@@ -3,11 +3,12 @@

 from datetime import datetime

-from django.http import HttpResponse
+from django.http import HttpResponse,Http404
 from django.template import RequestContext
 from django.template.loader import get_template
 from django.shortcuts import render_to_response
 import django.newforms as forms
+from django.contrib.auth.models import User

 from models import *
 from context import add_blocks,debug_messages,add_menu
@@ -233,3 +234,26 @@ def all_bugs(request):
   return render_it('all_bugs.html',
      {'bugs': bugs},
      request)
+
+def bugs_by_state(request,sid):
+  state = BugState.objects.get(pk=sid)
+  bugs = Bug.objects.filter(status=state)
+  return render_it('all_bugs.html',
+     {'bugs': bugs,
+      'state': state.name},
+     request)
+
+def user_page(request,name):
+  try:
+    user = User.objects.get(username=name)
+  except:
+    raise Http404
+  pr_admin = Project.objects.filter(admins=user)
+  pr_team  = Project.objects.filter(team=user)
+  bugs_resp = Bug.objects.filter(responsible=user)
+  return render_it('user_page.html',
+      {'user': name,
+       'projects_admin': pr_admin,
+       'projects_team': pr_team,
+       'bugs_resp': bugs_resp},
+       request)
diff --git a/pygit/chart.py b/pygit/chart.py
index df1e648..8c4b6e2 100644
--- a/pygit/chart.py
+++ b/pygit/chart.py
@@ -3,7 +3,7 @@ from os.path import exists
 import cairo

 width,height = 600,100
-pl,pr,py = 10,50,17
+pl,pr,py = 10,30,17
 root = "/home/portnov/www/projects/"

 def chart_path(data):
@@ -22,7 +22,7 @@ def make_chart(data,out_path):
   cx.move_to(pl,height-py)
   cur_x = pl
   for d in y:
-    cx.line_to(int(cur_x),int(height-d*scale_y))
+    cx.line_to(int(cur_x),int(height-d*scale_y-py))
     cur_x += step_x
   cx.line_to(width-pr,height-py)
   cx.close_path()
diff --git a/pygit/pygit.py b/pygit/pygit.py
index c1db846..55bf554 100644
--- a/pygit/pygit.py
+++ b/pygit/pygit.py
@@ -2,7 +2,8 @@
 from os.path import basename
 from git import *

-REPOS = ['/home/portnov/www/projects']
+REPOS = ['/home/portnov/www/projects',
+         '/home/portnov/www/projects/mgmt/hms']

 rp = None
 curr_path = None
@@ -106,10 +107,10 @@ def uniq(lst):
   r.append((prev,count))
   return r

-def commits_stats(rid):
+def commits_stats(rid,branch='master'):
   def date(tp):
     y,m,d = tp
     return "%d.%d" % (d,m)
   r = open_repo(rid)
-  d = [c.authored_date[:3] for c in r.commits()][:30]
+  d = [c.authored_date[:3] for c in r.commits(branch)][:20]
   return [(date(t[0]),t[1]) for t in uniq(d)]
diff --git a/pygit/views.py b/pygit/views.py
index 561e8e4..4ea9ae0 100644
--- a/pygit/views.py
+++ b/pygit/views.py
@@ -33,7 +33,7 @@ def one_repo(request,rid,branch='master'):
   tags = pygit.tags(rid)
   cs  = pygit.commits(rid,branch)
   dirs,files = pygit.root_tree(rid,branch)
-  cht = chart(pygit.commits_stats(rid))
+  cht = chart(pygit.commits_stats(rid,branch))
   return render_it('repo.html',
       {'description': dsc,
        'rid': rid,
diff --git a/templates/all_bugs.html b/templates/all_bugs.html
index f2885be..8a52102 100644
--- a/templates/all_bugs.html
+++ b/templates/all_bugs.html
@@ -1,11 +1,11 @@
 {% extends "base.html" %}
 {% load prj_filters %}

-{% block title %}Все баги{% endblock %}
+{% block title %}Все баги{% if state %} в состоянии {{state}}{% endif %}{% endblock %}

 {% block main %}

-<h2>Все баги</h2>
+<h2>Все баги{% if state %} в состоянии {{state}}{% endif %}</h2>

 <div class='bugs'>
 {% for bug in bugs %}
diff --git a/templates/user_page.html b/templates/user_page.html
new file mode 100644
index 0000000..e89f230
--- /dev/null
+++ b/templates/user_page.html
@@ -0,0 +1,42 @@
+{% extends "base.html" %}
+{% load prj_filters %}
+
+{% block title %}Пользователь {{user}}{% endblock %}
+
+{% block main %}
+<h2>Пользователь {{user}}</h2>
+
+{% if projects_admin %}
+  <h3>Администрирует проекты:</h3>
+  <ul>
+  {% for project in projects_admin %}
+    <li><a href='/projects/{{project.id}}/'>{{project.name}}</a></li>
+  {% endfor %}
+  </ul>
+{% endif %}
+
+{% if projects_team %}
+  <h3>В команде проектов:</h3>
+  <ul>
+  {% for project in projects_team %}
+    <li><a href='/projects/{{project.id}}/'>{{project.name}}</a></li>
+  {% endfor %}
+  </ul>
+{% endif %}
+
+{% if bugs_resp %}
+  <h3>Отвечает за баги:</h3>
+  <div class='bugs'>
+  {% for bug in bugs_resp %}
+      <div class='bug bug-state-{{bug.status.id}}'>
+        <div class='project-link'>{{bug.project|link|safe}}</div>
+        <h3><a href='/bugs/{{bug.id}}/'>Баг #{{bug.id}}: {{bug.name}}</a></h3>
+        {% if edit_link %}
+          <div class='links'><a href='{{edit_link}}'>Изменить</a></div>
+        {% endif %}
+        <p>{{bug.text}}</p>
+      </div>
+  {% endfor %}
+  </div>
+{% endif %}
+{% endblock %}
diff --git a/urls.py b/urls.py
index b914f8f..621bb24 100644
--- a/urls.py
+++ b/urls.py
@@ -8,10 +8,13 @@ urlpatterns = patterns('',
     (r'^projects/(\d+)/docs/$', "mgmt.views.project_documents"),
     (r'^docs/(\d+)/$', "mgmt.views.one_document"),
     (r'^docs/(\d+)/edit/$', "mgmt.views.edit_document"),
+    (r'^bugs/state/(\d+)/$', 'mgmt.views.bugs_by_state'),
     (r'^bugs/(\d+)/$', "mgmt.views.one_bug"),
     (r'^bugs/(\d+)/edit/$', "mgmt.views.edit_bug"),
     (r'^bugs/$', "mgmt.views.all_bugs"),
     (r'^create/doc/(\d+)/$', "mgmt.views.create_document"),
+    (r'^users/(\w+)/$', 'mgmt.views.user_page'),
+
     (r'^git/$', "pygit.views.all_repos"),
     (r'^git/repo/(\d+)/$', 'pygit.views.one_repo'),
     (r'^git/repo/(\d+)/(\w+)/$', 'pygit.views.one_repo'),
ViewGit