Enable administration of comments.

portnov [2008-06-07 17:21:26]
Enable administration of comments.
Filename
mgmt/models.py
mgmt/views.py
templates/bug_body.html
templates/document.html
templates/project_bugs.html
templates/project_docs.html
urls.py
diff --git a/mgmt/models.py b/mgmt/models.py
index a1cd1e2..76fde06 100644
--- a/mgmt/models.py
+++ b/mgmt/models.py
@@ -47,6 +47,8 @@ class Comment(models.Model):
   object = models.ForeignKey(Object)
   title = models.CharField(max_length=64,null=True)
   text = models.TextField()
+  class Admin:
+    pass
   def __unicode__(self):
     return self.title
   class Meta:
diff --git a/mgmt/views.py b/mgmt/views.py
index a5b2fad..e44d24c 100644
--- a/mgmt/views.py
+++ b/mgmt/views.py
@@ -1,4 +1,5 @@
 # Create your views here.
+#encoding: utf-8

 from datetime import datetime

@@ -14,6 +15,11 @@ class BugForm(forms.Form):
   name = forms.CharField()
   text = forms.CharField(widget=forms.Textarea())

+class DocForm(forms.Form):
+  name = forms.CharField()
+  project = forms.ModelChoiceField(Project.objects.all())
+  text = forms.CharField(widget=forms.Textarea())
+
 def main(request):
   projects = Project.objects.all()
   return render_to_response('main.html',{'projects': projects})
@@ -77,4 +83,28 @@ def one_document(request,id):
   form = CommentForm()
   return render_to_response('document.html',
       {'document': doc,
-       'comments': comments})
+       'comments': comments,
+       'form': form})
+
+def create_document(request):
+  msg = ""
+  if request.method=='POST':
+    name = request.POST['name']
+    text  = request.POST['text']
+    project = Project.objects.get(pk=request.POST['project'])
+    d = Document(name=name,
+        text=text,
+        created=datetime.now(),
+        author=request.user,
+        project=project)
+    d.save()
+    msg = u"Документ создан"
+  form = DocForm()
+  return render_to_response('create_doc.html',
+      {'msg': msg,
+       'form': form})
+
+def all_bugs(request):
+  bugs = Bug.objects.all()
+  return render_to_response('all_bugs.html',
+     {'bugs': bugs})
diff --git a/templates/bug_body.html b/templates/bug_body.html
index dcd77df..e97445b 100644
--- a/templates/bug_body.html
+++ b/templates/bug_body.html
@@ -1,4 +1,6 @@
+    {% load prj_filters %}
       <div class='bug bug-state-{{bug.status}}'>
         <p><strong>{{bug.name}}</strong></p>
+        <div class='project-link'>{{project|link|safe}}</div>
         <p>{{bug.text}}</p>
       </div>
diff --git a/templates/document.html b/templates/document.html
index bb410db..4de2b7c 100644
--- a/templates/document.html
+++ b/templates/document.html
@@ -6,8 +6,11 @@

 <h2>{{document.name}}</h2>

+<p>Проект: <a href='/projects/{{document.project.id}}/'>{{document.project.name}}</a></p>
 <div class='document'>
   {{document.text}}
 </div>

 {% include "comments.html" %}
+
+{% endblock %}
diff --git a/templates/project_bugs.html b/templates/project_bugs.html
index 19cbf0c..7e73095 100644
--- a/templates/project_bugs.html
+++ b/templates/project_bugs.html
@@ -6,7 +6,7 @@

 {% include "project_body.html" %}

-<h3>Баги:</h3>
+<h3><a href='/bugs/'>Баги:</a></h3>

 {% if bugs %}
   <div class='bugs'>
diff --git a/templates/project_docs.html b/templates/project_docs.html
index d07c218..50f0fcc 100644
--- a/templates/project_docs.html
+++ b/templates/project_docs.html
@@ -1,10 +1,11 @@
 {% extends "base.html" %}
+{% load prj_filters %}

 {% block title %}Документация по проекту {{project.name}}{% endblock %}

 {% block main %}

-  <h2>Проект: {{project.name}}</h2>
+  <h2>Проект: {{project|link|safe}}</h2>
   {%if docs%}
     <ul class='documents'>
     {% for doc in docs %}
@@ -14,5 +15,7 @@
   {%else%}
     <p>Документации пока нет.</p>
   {%endif%}
+  <p><a href='/create/doc/'>Создать страницу документации</a></p>

 {% endblock %}
+
diff --git a/urls.py b/urls.py
index 65b4cbc..36a9e1d 100644
--- a/urls.py
+++ b/urls.py
@@ -1,5 +1,5 @@
 from django.conf.urls.defaults import *
-from mgmt.views import main,one_project,project_bugs,one_document,project_documents
+from mgmt.views import *

 urlpatterns = patterns('',
     (r'^$', main),
@@ -7,6 +7,8 @@ urlpatterns = patterns('',
     (r'^projects/(\d+)/bugs/$', project_bugs),
     (r'^projects/(\d+)/docs/$', project_documents),
     (r'^docs/(\d+)/$', one_document),
+    (r'^bugs/$', all_bugs),
+    (r'^create/doc/$', create_document),

     (r'^admin/', include('django.contrib.admin.urls')),
 )
ViewGit