New application: kb - Knowledge Base. Models.

portnov [2008-06-17 17:45:33]
New application: kb - Knowledge Base. Models.
Filename
kb/__init__.py
kb/fields.py
kb/models.py
kb/views.py
locale/en/LC_MESSAGES/django.mo
locale/en/LC_MESSAGES/django.po
locale/ru/LC_MESSAGES/django.mo
locale/ru/LC_MESSAGES/django.po
mgmt/models.py
settings.py
diff --git a/kb/__init__.py b/kb/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/kb/fields.py b/kb/fields.py
new file mode 100644
index 0000000..24bc83a
--- /dev/null
+++ b/kb/fields.py
@@ -0,0 +1,81 @@
+from os.path import join
+import codecs
+from md5 import md5
+
+from django import oldforms
+from django.utils.safestring import mark_safe
+from django.utils.html import escape
+from django.db import models
+from django.conf import settings
+
+class FileStoredText(object):
+  def __init__(self,filename=None,text=None):
+    self.text = text
+    if filename:
+      self.read_from(join(settings.TEXTS_PATH,filename))
+
+  def write_to(self,filename):
+    f = codecs.open(filename,'w',encoding='utf-8')
+    f.write(self.text)
+    f.close()
+
+  def read_from(self,filename):
+    f = codecs.open(filename,'r',encoding='utf-8')
+    self.text = f.read()
+    f.close()
+
+  def digest(self):
+    return md5(self.text.encode('utf-8')[:50]).hexdigest()
+
+  def __repr__(self):
+    return "<FileStoredText: %s...>" % self.text[:10]
+
+  def __unicode__(self):
+    return self.text
+
+class StoredTextField(oldforms.TextField):
+    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, max_length=None):
+        if validator_list is None: validator_list = []
+        self.field_name = field_name
+        self.rows, self.cols, self.is_required = rows, cols, is_required
+        self.validator_list = validator_list[:]
+        if max_length:
+            self.validator_list.append(self.isValidLength)
+            self.max_length = max_length
+
+    def render(self, data):
+        if data is None:
+            data = ''
+        data = FileStoredText(filename=data[4:]).text
+        return mark_safe(u'<textarea id="%s" class="v%s%s" name="%s" rows="%s" cols="%s">%s</textarea>' % \
+            (self.get_id(), self.__class__.__name__, self.is_required and u' required' or u'',
+            self.field_name, self.rows, self.cols, escape(data)))
+
+class FileStoredTextField(models.Field):
+  __metaclass__ = models.SubfieldBase
+
+  def get_manipulator_field_objs(self):
+      return [StoredTextField]
+
+  def get_internal_type(self):
+      return "TextField"
+
+  def formfield(self, **kwargs):
+      defaults = {'widget': forms.Textarea}
+      defaults.update(kwargs)
+      return super(FileStoredTextField, self).formfield(**defaults)
+
+  def db_type(self):
+    return "varchar(64)"
+
+  def to_python(self,value):
+    if value[:3]=='md5:':
+      return FileStoredText(filename=value[4:]).text
+    else:
+      return value
+
+  def get_db_prep_save(self,value):
+    fs = FileStoredText(text=value)
+    filename = fs.digest()
+    fs.write_to(join(settings.TEXTS_PATH,filename))
+    return 'md5:' + filename
diff --git a/kb/models.py b/kb/models.py
new file mode 100644
index 0000000..f6013e5
--- /dev/null
+++ b/kb/models.py
@@ -0,0 +1,37 @@
+from django.db import models
+from django.conf import settings
+from django.contrib.auth.models import User
+from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import activate
+# activate(settings.LANGUAGE_CODE)
+# _ = lambda s: s
+
+from fields import *
+
+class KBSection(models.Model):
+  title = models.CharField(max_length=128,verbose_name=_("Section"))
+  description = models.TextField(_("Description"))
+  def __unicode__(self):
+    return self.title
+  class Meta:
+    verbose_name=_("Knowledge Base section")
+    verbose_name_plural = _("Knowledge Base sections")
+    ordering = ("title",)
+  class Admin:
+    pass
+
+class KBArticle(models.Model):
+  author = models.ForeignKey(User,verbose_name=_("Author"))
+  created = models.DateTimeField(_("Created"))
+  section = models.ForeignKey(KBSection,verbose_name=_("Section"))
+  title = models.CharField(max_length=128,verbose_name=_("Title"))
+  text = FileStoredTextField()
+  def __unicode__(self):
+    return self.title
+  class Meta:
+    verbose_name=_("Knowledge Base article")
+    verbose_name_plural = _("Knowledge Base articles")
+    ordering = ("title",)
+  class Admin:
+    pass
+
diff --git a/kb/views.py b/kb/views.py
new file mode 100644
index 0000000..60f00ef
--- /dev/null
+++ b/kb/views.py
@@ -0,0 +1 @@
+# Create your views here.
diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo
index 02b8da0..afb0fc2 100644
Binary files a/locale/en/LC_MESSAGES/django.mo and b/locale/en/LC_MESSAGES/django.mo differ
diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po
index bebc667..7ca117b 100644
--- a/locale/en/LC_MESSAGES/django.po
+++ b/locale/en/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-06-17 12:19+0600\n"
+"POT-Creation-Date: 2008-06-17 22:16+0600\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -16,95 +16,188 @@ msgstr ""
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"

-#: mgmt/models.py:9
-msgid "Name"
+#: kb/models.py:49 kb/models.py:63
+msgid "Section"
 msgstr ""

-#: mgmt/models.py:10
-msgid "Text"
+#: kb/models.py:50 mgmt/models.py:101
+msgid "Description"
+msgstr ""
+
+#: kb/models.py:54
+msgid "Knowledge Base section"
+msgstr ""
+
+#: kb/models.py:55
+msgid "Knowledge Base sections"
+msgstr ""
+
+#: kb/models.py:61 mgmt/models.py:48 mgmt/models.py:76 mgmt/models.py:90
+#: mgmt/models.py:114 mgmt/models.py:139
+msgid "Author"
 msgstr ""

-#: mgmt/models.py:11
+#: kb/models.py:62 mgmt/models.py:14
 msgid "Created"
 msgstr ""

-#: mgmt/models.py:18
+#: kb/models.py:64 mgmt/forms.py:14 mgmt/models.py:127
+msgid "Title"
+msgstr ""
+
+#: kb/models.py:69
+msgid "Knowledge Base article"
+msgstr ""
+
+#: kb/models.py:70
+msgid "Knowledge Base articles"
+msgstr ""
+
+#: mgmt/models.py:12 mgmt/models.py:100
+msgid "Name"
+msgstr ""
+
+#: mgmt/models.py:13 mgmt/models.py:128
+msgid "Text"
+msgstr ""
+
+#: mgmt/models.py:21
 msgid "Repository"
 msgstr ""

-#: mgmt/models.py:19
+#: mgmt/models.py:22
 msgid "Link to Git repo"
 msgstr ""

-#: mgmt/models.py:20
+#: mgmt/models.py:23
 msgid "Admins"
 msgstr ""

-#: mgmt/models.py:21
+#: mgmt/models.py:24
 msgid "Team"
 msgstr ""

-#: mgmt/models.py:22
+#: mgmt/models.py:25
 msgid "Is open"
 msgstr ""

-#: mgmt/models.py:26 mgmt/models.py:44
+#: mgmt/models.py:29 mgmt/models.py:47 mgmt/models.py:66 mgmt/models.py:113
 msgid "Project"
 msgstr ""

-#: mgmt/models.py:27
+#: mgmt/models.py:30
 msgid "Projects"
 msgstr ""

-#: mgmt/models.py:37
+#: mgmt/models.py:40
 msgid "Bug state"
 msgstr ""

-#: mgmt/models.py:38
+#: mgmt/models.py:41
 msgid "Bug states"
 msgstr ""

-#: mgmt/models.py:45
-msgid "Author"
-msgstr ""
-
-#: mgmt/models.py:46
+#: mgmt/models.py:49
 msgid "Confirmed"
 msgstr ""

-#: mgmt/models.py:47
+#: mgmt/models.py:50
 msgid "Responsible"
 msgstr ""

+#: mgmt/models.py:51 mgmt/models.py:67 mgmt/models.py:81
+msgid "Status"
+msgstr ""
+
+#: mgmt/models.py:52
+msgid "Component"
+msgstr ""
+
+#: mgmt/models.py:53
+msgid "Your actions"
+msgstr ""
+
+#: mgmt/models.py:54
+msgid "Expected behaivour"
+msgstr ""
+
+#: mgmt/models.py:55
+msgid "Unexpected behaivour"
+msgstr ""
+
 #: mgmt/models.py:56
-msgid "Bug"
+msgid "Priority"
 msgstr ""

 #: mgmt/models.py:57
+msgid "Complexity"
+msgstr ""
+
+#: mgmt/models.py:59 mgmt/models.py:79
+msgid "Bug"
+msgstr ""
+
+#: mgmt/models.py:60
 msgid "Bugs"
 msgstr ""

-#: mgmt/models.py:105
-msgid "Document"
+#: mgmt/models.py:69 mgmt/models.py:80
+msgid "Feature request"
+msgstr ""
+
+#: mgmt/models.py:70
+msgid "Feature requests"
+msgstr ""
+
+#: mgmt/models.py:77 mgmt/models.py:140
+msgid "To"
+msgstr ""
+
+#: mgmt/models.py:83 mgmt/models.py:91
+msgid "Task"
+msgstr ""
+
+#: mgmt/models.py:84
+msgid "Tasks"
+msgstr ""
+
+#: mgmt/models.py:93
+msgid "Report"
+msgstr ""
+
+#: mgmt/models.py:94
+msgid "Reports"
+msgstr ""
+
+#: mgmt/models.py:105 mgmt/models.py:112
+msgid "Category"
 msgstr ""

 #: mgmt/models.py:106
+msgid "Categories"
+msgstr ""
+
+#: mgmt/models.py:116
+msgid "Document"
+msgstr ""
+
+#: mgmt/models.py:117
 msgid "Documents"
 msgstr ""

-#: mgmt/models.py:123
+#: mgmt/models.py:134
 msgid "Comment"
 msgstr ""

-#: mgmt/models.py:124
+#: mgmt/models.py:135
 msgid "Comments"
 msgstr ""

-#: mgmt/models.py:133
+#: mgmt/models.py:144
 msgid "Private message"
 msgstr ""

-#: mgmt/models.py:134
+#: mgmt/models.py:145
 msgid "Private messages"
 msgstr ""

diff --git a/locale/ru/LC_MESSAGES/django.mo b/locale/ru/LC_MESSAGES/django.mo
index ea779fd..250ad58 100644
Binary files a/locale/ru/LC_MESSAGES/django.mo and b/locale/ru/LC_MESSAGES/django.mo differ
diff --git a/locale/ru/LC_MESSAGES/django.po b/locale/ru/LC_MESSAGES/django.po
index c5fd360..dd97cbc 100644
--- a/locale/ru/LC_MESSAGES/django.po
+++ b/locale/ru/LC_MESSAGES/django.po
@@ -6,7 +6,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Django\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-06-17 14:04+0600\n"
+"POT-Creation-Date: 2008-06-17 22:12+0600\n"
 "PO-Revision-Date: 2006-09-07 15:28+0300\n"
 "Last-Translator: Vasiliy Stavenko <stavenko@gmail.com>\n"
 "Language-Team: Dialcom Services <greg@dial.com.ru>\n"
@@ -19,6 +19,43 @@ msgstr ""
 "X-Poedit-Country: RUSSIAN FEDERATION\n"
 "X-Poedit-SourceCharset: utf-8\n"

+#: kb/models.py:49 kb/models.py:63
+msgid "Section"
+msgstr "Раздел"
+
+#: kb/models.py:50 mgmt/models.py:101
+msgid "Description"
+msgstr "Описание"
+
+#: kb/models.py:54
+msgid "Knowledge Base section"
+msgstr "Раздел Базы Знаний"
+
+#: kb/models.py:55
+msgid "Knowledge Base sections"
+msgstr "Разделы Базы Знаний"
+
+#: kb/models.py:61 mgmt/models.py:48 mgmt/models.py:76 mgmt/models.py:90
+#: mgmt/models.py:114 mgmt/models.py:139
+msgid "Author"
+msgstr "Автор"
+
+#: kb/models.py:62 mgmt/models.py:14
+msgid "Created"
+msgstr "Создано"
+
+#: kb/models.py:64 mgmt/forms.py:14 mgmt/models.py:127
+msgid "Title"
+msgstr "Заголовок"
+
+#: kb/models.py:69
+msgid "Knowledge Base article"
+msgstr "Статья Базы Знаний"
+
+#: kb/models.py:70
+msgid "Knowledge Base articles"
+msgstr "Статьи Базы Знаний"
+
 #: mgmt/models.py:12 mgmt/models.py:100
 msgid "Name"
 msgstr "Название"
@@ -27,10 +64,6 @@ msgstr "Название"
 msgid "Text"
 msgstr "Текст"

-#: mgmt/models.py:14
-msgid "Created"
-msgstr "Создано"
-
 #: mgmt/models.py:21
 msgid "Repository"
 msgstr "Репозиторий"
@@ -67,11 +100,6 @@ msgstr "Состояние бага"
 msgid "Bug states"
 msgstr "Состояния багов"

-#: mgmt/models.py:48 mgmt/models.py:76 mgmt/models.py:90 mgmt/models.py:114
-#: mgmt/models.py:139
-msgid "Author"
-msgstr "Автор"
-
 #: mgmt/models.py:49
 msgid "Confirmed"
 msgstr "Подтвердил"
@@ -144,10 +172,6 @@ msgstr "Отчет"
 msgid "Reports"
 msgstr "Отчеты"

-#: mgmt/models.py:101
-msgid "Description"
-msgstr "Описание"
-
 #: mgmt/models.py:105 mgmt/models.py:112
 msgid "Category"
 msgstr "Категория"
@@ -164,10 +188,6 @@ msgstr "Документ"
 msgid "Documents"
 msgstr "Документы"

-#: mgmt/models.py:127
-msgid "Title"
-msgstr "Заголовок"
-
 #: mgmt/models.py:134
 msgid "Comment"
 msgstr "Комментарий"
diff --git a/mgmt/models.py b/mgmt/models.py
index 66dee16..09ee3d1 100644
--- a/mgmt/models.py
+++ b/mgmt/models.py
@@ -1,4 +1,5 @@
-from os.path import dirname
+#encoding: utf-8
+from os.path import join

 from django.db import models
 from django.conf import settings
diff --git a/settings.py b/settings.py
index b813db6..876ae41 100644
--- a/settings.py
+++ b/settings.py
@@ -87,8 +87,11 @@ INSTALLED_APPS = (
     'django.contrib.sessions',
     'django.contrib.sites',
     'mgmt',
+    'kb',
 )

+TEXTS_PATH = "/home/portnov/www/projects/media/texts/"
+
 SHOW_BLOCKS = dict(
     last_comments = dict(),
     login   = dict(hide='/login/$',show_logged=False))
ViewGit