diff --git a/mgmt/forms.py b/mgmt/forms.py
index 231d27b..43222cd 100644
--- a/mgmt/forms.py
+++ b/mgmt/forms.py
@@ -3,7 +3,7 @@ import django.newforms as forms
from django.contrib.auth.models import User
from django.conf import settings
-from models import Bug,Request,Project,Task,Report
+from models import *
############
# Forms
@@ -34,9 +34,14 @@ class RequestForm(forms.Form):
class RequestStateForm(forms.Form):
state = forms.ChoiceField(settings.REQUEST_STATES)
-class DocForm(forms.Form):
- name = forms.CharField()
- text = forms.CharField(widget=forms.Textarea())
+class DocForm(forms.ModelForm):
+ class Meta:
+ model = Document
+ exclude = ("created", "author", "project")
+
+# class DocForm(forms.Form):
+# name = forms.CharField()
+# text = forms.CharField(widget=forms.Textarea())
class MessageForm(forms.Form):
name = forms.CharField()
diff --git a/mgmt/hms/modules/last_comments.py b/mgmt/hms/modules/last_comments.py
index 702286c..2b9a5c3 100644
--- a/mgmt/hms/modules/last_comments.py
+++ b/mgmt/hms/modules/last_comments.py
@@ -16,6 +16,8 @@ def init():
return "/bugs/%s/#comment-%s" % (id,comment.id)
if type=='Document':
return "/docs/%d/#comment-%s" % (id,comment.id)
+ if type=='Request':
+ return "/requests/%d/#comment-%s" % (id,comment.id)
return "<li><a href='%s'>%s</a></li>" % (get_url(comment),comment.title)
b = Block()
b.name='last_comments'
diff --git a/mgmt/models.py b/mgmt/models.py
index 9115d7c..d3b5119 100644
--- a/mgmt/models.py
+++ b/mgmt/models.py
@@ -86,7 +86,18 @@ class Report(Object):
class Admin:
pass
+class Category(models.Model):
+ title = models.CharField(max_length=64)
+ description = models.TextField()
+ def __unicode__(self):
+ return self.title
+ class Meta:
+ ordering = ("title",)
+ class Admin:
+ pass
+
class Document(Object):
+ category = models.ForeignKey(Category)
project = models.ForeignKey(Project)
author = models.ForeignKey(User)
class Meta:
diff --git a/mgmt/views.py b/mgmt/views.py
index bfcb514..8859a99 100644
--- a/mgmt/views.py
+++ b/mgmt/views.py
@@ -107,10 +107,10 @@ def bug_report(request,pid):
def project_documents(request,id):
project = Project.objects.get(pk=id)
- docs = Document.objects.filter(project=project)
+ cats = Category.objects.filter(document__project=project)
return render_it('project_docs.html',
{'project': project,
- 'docs': docs},
+ 'categories': cats},
request)
def one_document(request,id):
@@ -147,16 +147,42 @@ def one_document(request,id):
'form': form},
request)
+@check_auth(Project,'document')
+def create_document(request,project):
+ msg = ""
+ if request.method=='POST':
+ form = DocForm(request.POST)
+ if form.is_valid():
+ doc = form.save(commit=False)
+ doc.created = datetime.now()
+ doc.author = request.user
+ doc.project = project
+ doc.save()
+ return HttpResponseRedirect(reverse('mgmt.views.one_document',args=(doc.id,)))
+ else:
+ return render_it('create_doc.html',
+ {'form': form},
+ request)
+ form = DocForm()
+ return render_it('create_doc.html',
+ {'form': form},
+ request)
+
@check_auth(Document,'edit')
def edit_document(request,doc):
project = doc.project
if request.method=='POST':
- name = request.POST['name']
- text = request.POST['text']
- doc.name = name
- doc.text = text
- doc.save()
- form = DocForm(dict(name = doc.name, text = doc.text))
+ form = DocForm(request.POST,instance=doc)
+ if form.is_valid():
+ form.save()
+ return HttpResponseRedirect(reverse('mgmt.views.one_document',args=(doc.id,)))
+ else:
+ return render_it('edit_document.html',
+ {'document': doc,
+ 'project_id': project.id,
+ 'form': form},
+ request)
+ form = DocForm(instance=doc)
return render_it('edit_document.html',
{'document': doc,
'project_id': project.id,
@@ -270,25 +296,6 @@ def edit_bug(request,bug):
'form': form},
request)
-@check_auth(Project,'document')
-def create_document(request,project):
- msg = ""
- if request.method=='POST':
- name = request.POST['name']
- text = request.POST['text']
- d = Document(name=name,
- text=text,
- created=datetime.now(),
- author=request.user,
- project=project)
- d.save()
- msg = u"Документ создан"
- form = DocForm()
- return render_it('create_doc.html',
- {'msg': msg,
- 'form': form},
- request)
-
def all_bugs(request):
page,pages,bugs = get_bugs(request)
return render_it('all_bugs.html',
diff --git a/templates/document.html b/templates/document.html
index b985ddf..6fb2340 100644
--- a/templates/document.html
+++ b/templates/document.html
@@ -10,7 +10,7 @@
<a href='{{edit_link}}'>Изменить</a>
</div>
{% endif %}
-<h2>{{document.name}}</h2>
+<h2>{{document.category.title}}: {{document.name}}</h2>
<p>Проект: <a href='{% url mgmt.views.one_project document.project.id %}'>{{document.project.name}}</a></p>
<div class='document'>
diff --git a/templates/project_docs.html b/templates/project_docs.html
index 332dcb0..3f858b9 100644
--- a/templates/project_docs.html
+++ b/templates/project_docs.html
@@ -6,12 +6,15 @@
{% block main %}
<h2>Проект: {{project|link|safe}}</h2>
- {%if docs%}
- <ul class='documents'>
- {% for doc in docs %}
- <li><a href='{% url mgmt.views.one_document doc.id %}'>{{doc.name}}</a></li>
+ {%if categories %}
+ {% for cat in categories %}
+ <h3>{{cat.title}}:</h3>
+ <ul class='documents'>
+ {% for doc in cat.document_set.all %}
+ <li><a href='{% url mgmt.views.one_document doc.id %}'>{{doc.name}}</a></li>
+ {% endfor %}
+ </ul>
{% endfor %}
- </ul>
{%else%}
<p>Документации пока нет.</p>
{%endif%}