diff --git a/media/css/main.css b/media/css/main.css
index 4027e79..ec09b4e 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -8,10 +8,31 @@
border-bottom: 1px #888 solid;
}
+#main {
+ margin-left: 13em;
+ padding-left: 1em;
+}
+
+ul.menu {
+ float: right;
+ text-align: right;
+ display: inline;
+}
+
+ul.menu li {
+ list-style: none;
+ display: inline;
+}
+
.links {
text-align: right;
}
+.project-link {
+ float: right;
+ text-align: right;
+}
+
.project {
border-bottom: 1px #888 solid;
margin-bottom: 2ex;
@@ -26,3 +47,24 @@
margin-right: 1ex;
}
+.comment {
+ border-top: 1px #888 solid;
+ margin-bottom: 1em;
+}
+
+p.comment-title {
+ border-bottom: 1px #888 solid;
+ background: #eee;
+ margin-top: 0;
+ padding-left: 1em;
+}
+
+p.date {
+ font-size: small;
+ text-align: right;
+}
+
+.bug {
+ border: 1px #888 solid;
+ padding: 1ex;
+}
diff --git a/mgmt/context.py b/mgmt/context.py
index 6aa5bfc..af7d7ef 100644
--- a/mgmt/context.py
+++ b/mgmt/context.py
@@ -38,6 +38,10 @@ def add_blocks(request):
log_msg = u'Вы не вошли.'
return dict(blocks=blocks,login_message=log_msg)
+def add_menu(request):
+ menu = hms.modules.menu(request)
+ return dict(menu=menu)
+
def debug_messages(request):
if settings.DEBUG:
return dict(debug = debug.dump())
diff --git a/mgmt/rights.py b/mgmt/rights.py
index f7e7a7a..2e8de01 100644
--- a/mgmt/rights.py
+++ b/mgmt/rights.py
@@ -26,8 +26,15 @@ def can_change_bug_state(user,bug,new_state):
def can(user,action,object=None,target=None):
if action in ['comment','send bug']:
return user.is_authenticated()
- if action in ['create', 'edit', 'delete']:
- return user.is_authenticated() and user.has_perm('mgmt.%s.%s' % (object,action))
+# if action in ['create', 'edit', 'delete']:
+# return user.is_authenticated() and user.has_perm('mgmt.%s.%s' % (object,action))
+ if action == 'edit':
+ if object.__class__.__name__ == 'Project':
+ return user in object.admins.iterator()
+ if object.__class__.__name__ == 'Bug':
+ return user in object.project.team.iterator()
+ if object.__class__.__name__ == 'Document':
+ return user in object.project.team.iterator()
if action == 'document':
return user in object.team.iterator()
if object.__class__.__name__ == 'Bug':
diff --git a/mgmt/views.py b/mgmt/views.py
index 8019064..8ed2c70 100644
--- a/mgmt/views.py
+++ b/mgmt/views.py
@@ -10,11 +10,11 @@ from django.shortcuts import render_to_response
import django.newforms as forms
from models import *
-from context import add_blocks,debug_messages
+from context import add_blocks,debug_messages,add_menu
from rights import can,possible_changes
def render_it(template,dict,request):
- c = RequestContext(request,dict,[add_blocks,debug_messages])
+ c = RequestContext(request,dict,[add_blocks,add_menu,debug_messages])
t = get_template(template)
return HttpResponse(t.render(c))
@@ -43,6 +43,8 @@ def one_project(request,id):
if request.method=='POST':
title = request.POST['title']
text = request.POST['text']
+ if not title:
+ title = text[:20]+'...'
c = Comment(created=datetime.now(),
author = request.user,
object_id = project.id,
@@ -98,6 +100,8 @@ def one_document(request,id):
if request.method=='POST':
title = request.POST['title']
text = request.POST['text']
+ if not title:
+ title = text[:20]+'...'
c = Comment(created=datetime.now(),
author = request.user,
object_id = doc.id,
@@ -110,18 +114,42 @@ def one_document(request,id):
form = CommentForm()
else:
form = None
+ if can(request.user,'edit',doc):
+ edit_link = '/docs/%s/edit/' % id
+ else:
+ edit_link = None
return render_it('document.html',
{'document': doc,
+ 'edit_link': edit_link,
'comments': comments,
'form': form},
request)
+def edit_document(request,id):
+ doc = Document.objects.get(pk=id)
+ project = doc.project
+ if request.method=='POST':
+ name = request.POST['name']
+ text = request.POST['text']
+ doc = Document.objects.get(pk=id)
+ doc.name = name
+ doc.text = text
+ doc.save()
+ form = DocForm(dict(name = doc.name, text = doc.text))
+ return render_it('edit_document.html',
+ {'document': doc,
+ 'project_id': project.id,
+ 'form': form},
+ request)
+
def one_bug(request,id):
bug = Bug.objects.get(pk=id)
if request.method=='POST':
if request.POST['action']=='comment':
title = request.POST['title']
text = request.POST['text']
+ if not title:
+ title = text[:20]+'...'
c = Comment(created=datetime.now(),
author = request.user,
object_id = bug.id,
diff --git a/templates/base.html b/templates/base.html
index c1819d2..c24ef65 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -16,6 +16,14 @@
<div id='header'>
{%block header%}
{{login_message}}
+ {% if menu %}
+ <ul class='menu'>
+ {% for item in menu %}
+ <li>{{item|safe}}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
{%endblock%}
</div>
diff --git a/templates/document.html b/templates/document.html
index 4de2b7c..9fdd49b 100644
--- a/templates/document.html
+++ b/templates/document.html
@@ -5,6 +5,11 @@
{% block main %}
<h2>{{document.name}}</h2>
+{% if edit_link %}
+ <div class='links'>
+ <a href='{{edit_link}}'>Изменить</a>
+ </div>
+{% endif %}
<p>Проект: <a href='/projects/{{document.project.id}}/'>{{document.project.name}}</a></p>
<div class='document'>
diff --git a/templates/edit_document.html b/templates/edit_document.html
new file mode 100644
index 0000000..36870b3
--- /dev/null
+++ b/templates/edit_document.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+
+{% block title %}Редактировать документ: {{document.name}}{% endblock %}
+
+{% block main %}
+
+<h2>Редактировать документ</h2>
+<div class='links'>
+ <a href='/docs/{{document.id}}'>Посмотреть</a>
+</div>
+
+<form method='post' action='.'>
+ {{form.as_p}}
+ <input type='submit'/>
+</form>
+
+{% endblock %}
diff --git a/templates/project_bugs.html b/templates/project_bugs.html
index c138727..ff481c0 100644
--- a/templates/project_bugs.html
+++ b/templates/project_bugs.html
@@ -19,6 +19,7 @@
{%endif%}
{% if form %}
+ <h3>Отправить баг:</h3>
<form method='post' action='.'>
{{form.as_p}}
<input type='submit'/>
diff --git a/urls.py b/urls.py
index 2bf524b..577a30e 100644
--- a/urls.py
+++ b/urls.py
@@ -7,6 +7,7 @@ urlpatterns = patterns('',
(r'^projects/(\d+)/bugs/$', "mgmt.views.project_bugs"),
(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/(\d+)/$', "mgmt.views.one_bug"),
(r'^bugs/$', "mgmt.views.all_bugs"),
(r'^create/doc/(\d+)/$', "mgmt.views.create_document"),