[Mpuls-commits] r5561 - in base/trunk/mpulsweb: controllers lib model templates/documents

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 9 15:13:21 CET 2011


Author: ludwig
Date: 2011-11-09 15:13:18 +0100 (Wed, 09 Nov 2011)
New Revision: 5561

Modified:
   base/trunk/mpulsweb/controllers/casedocument.py
   base/trunk/mpulsweb/controllers/document.py
   base/trunk/mpulsweb/lib/config.py
   base/trunk/mpulsweb/lib/validators.py
   base/trunk/mpulsweb/model/document.py
   base/trunk/mpulsweb/templates/documents/case_new.mako
   base/trunk/mpulsweb/templates/documents/case_overview.mako
   base/trunk/mpulsweb/templates/documents/global_overview.mako
   base/trunk/mpulsweb/templates/documents/global_upload.mako
Log:
Issue 2626: If "module","documents-description" is set, the application uses
a "beschreibung" column in ka_dokumente_tbl table to add a description to 
a file in global documents and case documents.

If this option is not set, everything stays in the old way.

The beschreibung column is given thru the application.


Modified: base/trunk/mpulsweb/controllers/casedocument.py
===================================================================
--- base/trunk/mpulsweb/controllers/casedocument.py	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/controllers/casedocument.py	2011-11-09 14:13:18 UTC (rev 5561)
@@ -9,8 +9,9 @@
 from pylons.controllers.util import redirect_to
 from mpulsweb.lib.translation import _, ungettext
 
-from mpulsweb.lib.base import BaseController, render, session
-from mpulsweb.lib.validators import UploadCaseDocumentForm
+from mpulsweb.lib.base import BaseController, render, session, g
+from mpulsweb.lib.validators import UploadCaseDocumentForm, \
+                                    UploadCaseDocumentWDescForm
 from mpulsweb.lib.security import checkRole
 import mpulsweb.lib.helpers as h
 
@@ -38,7 +39,10 @@
 
     @checkRole('cm')
     def newAction(self):
-        validator = UploadCaseDocumentForm()
+        if g.mpuls_config.is_enabled("module", "documents-description"):
+            validator = UploadCaseDocumentWDescForm()
+        else:
+            validator = UploadCaseDocumentForm()
         try:
             result = validator.to_python(request.params)
             doc = Document()
@@ -52,7 +56,11 @@
                     filename = result['name'] + '.' + extension
                 else:
                     filename = result['name']
-            doc.create(filename, content, case)
+            if g.mpuls_config.is_enabled("module", "documents-description"):
+                doc.create(filename, content, case, 
+                           description=result['description'])
+            else:
+                doc.create(filename, content, case)
             c.dialog_title = _(u"Attachment added!")
             c.dialog_text = _(u"Please click OK to continue.")
             c.url_ok = h.url_for(controller="/casedocument", action="index",

Modified: base/trunk/mpulsweb/controllers/document.py
===================================================================
--- base/trunk/mpulsweb/controllers/document.py	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/controllers/document.py	2011-11-09 14:13:18 UTC (rev 5561)
@@ -35,9 +35,11 @@
 
 import paste
 
-from mpulsweb.lib.base import BaseController, c, h, redirect_to, render, request
+from mpulsweb.lib.base import BaseController, c, h, redirect_to, render, \
+                              request, g
 from mpulsweb.lib.security import checkRole
-from mpulsweb.lib.validators import UploadGlobalDocumentForm
+from mpulsweb.lib.validators import UploadGlobalDocumentForm, \
+                                    UploadGlobalDocumentWDescForm  
 from mpulsweb.model.document import Document, listDocuments, deleteDocument
 
 log = logging.getLogger(__name__)
@@ -63,7 +65,10 @@
 
     @checkRole('admin')
     def globalUploadAction(self):
-        validator = UploadGlobalDocumentForm()
+        if g.mpuls_config.is_enabled("module", "documents-description"):
+            validator = UploadGlobalDocumentWDescForm()
+        else:    
+            validator = UploadGlobalDocumentForm()
         try:
             result = validator.to_python(request.params)
             doc = Document()
@@ -71,7 +76,10 @@
             content = result['file']['content']
             if result['name']:
                 filename = result['name']
-            doc.create(filename, content)
+            if  g.mpuls_config.is_enabled("module", "documents-description"):
+               doc.create(filename, content, description=result['description'])
+            else:
+               doc.create(filename, content)
             c.dialog_title = _(u"Document added!")
             c.dialog_text = _("Please click OK to continue.")
             c.url_ok = h.url_for(controller="document",

Modified: base/trunk/mpulsweb/lib/config.py
===================================================================
--- base/trunk/mpulsweb/lib/config.py	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/lib/config.py	2011-11-09 14:13:18 UTC (rev 5561)
@@ -135,6 +135,7 @@
         set('module', 'casemanagement', '1')
         set('module', 'appointments', '1')
         set('module', 'documents', '1')
+        set('module', 'documents-description', '0')
         set('module', 'news', '1')
         set('module', 'evaluation', '1')
         # Used for evaluation server.

Modified: base/trunk/mpulsweb/lib/validators.py
===================================================================
--- base/trunk/mpulsweb/lib/validators.py	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/lib/validators.py	2011-11-09 14:13:18 UTC (rev 5561)
@@ -580,7 +580,9 @@
     overwrite = Bool(if_missing=False)
     chained_validators = [FileExistsChecker('file', 'name', 'overwrite',
                                             'case')]
+class UploadGlobalDocumentWDescForm(UploadGlobalDocumentForm):
 
+    description = String()
 
 class UploadCaseDocumentForm(BaseFormValidator):
 
@@ -593,6 +595,9 @@
     chained_validators = [FileExistsChecker('file', 'name', 'overwrite',
                                             'case')]
 
+class UploadCaseDocumentWDescForm(UploadCaseDocumentForm):
+    
+    description = String()
 
 class EditSettingsForm(BaseFormValidator):
 

Modified: base/trunk/mpulsweb/model/document.py
===================================================================
--- base/trunk/mpulsweb/model/document.py	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/model/document.py	2011-11-09 14:13:18 UTC (rev 5561)
@@ -44,11 +44,11 @@
      StructureInstanceTree
 
 import mpulsweb.lib.helpers as h
+from mpulsweb.lib.base import g
 from mpulsweb.lib.db import db
 from mpulsweb.lib.translation import _
 from mpulsweb.model.logbook import text_subelement, new_node
 
-
 MAX_SIZE = 10 * 1024 * 1024
 BLOCK_SIZE = 4 * 1024
 
@@ -56,16 +56,36 @@
 CREATE_CASE = '\
 SELECT * FROM create_fall_dokument_ds(%(id)s, %(uuid)s, %(name)s)'
 
-UPDATE_GLOBAL = '''
+DELETE_GLOBAL = '''
+SELECT delete_global_dokument_ds(%(id)s)
+'''
+DELETE_CASE = '''
+SELECT delete_fall_dokument_ds(%(id)s)
+'''
+
+    
+UPDATE_GLOBAL_WITH_DESC = '''
 UPDATE ka_global_dokumente_tbl_view
-SET daten = %(bytes)s, groesse = %(size)s, name = %(name)s, mime = %(mime)s
+SET daten = %(bytes)s, groesse = %(size)s, name = %(name)s,
+mime = %(mime)s, beschreibung = %(description)s
 WHERE id = %(id)s
 '''
 
-UPDATE_CASE = '''
-UPDATE ka_fall_dokumente_tbl_view
+LIST_GLOBAL_WITH_DESC = '''
+SELECT id, master_id, groesse, mime, name, beschreibung
+FROM ka_global_dokumente_tbl_view
+'''
+
+LOAD_GLOBAL_WITH_DESC = '''
+SELECT master_id, groesse, mime, daten, name, beschreibung
+FROM ka_global_dokumente_tbl_view
+WHERE id = %(id)s
+'''
+
+UPDATE_GLOBAL = '''
+UPDATE ka_global_dokumente_tbl_view
 SET daten = %(bytes)s, groesse = %(size)s, name = %(name)s, mime = %(mime)s
-WHERE id = %(id)s AND master_id = %(case)s
+WHERE id = %(id)s
 '''
 
 LIST_GLOBAL = '''
@@ -73,24 +93,41 @@
 FROM ka_global_dokumente_tbl_view
 '''
 
-LIST_CASE = '''
-SELECT id, master_id, groesse, mime, name
+LOAD_GLOBAL = '''
+SELECT master_id, groesse, mime, daten, name
+FROM ka_global_dokumente_tbl_view
+WHERE id = %(id)s
+'''
+
+UPDATE_CASE_WITH_DESC = '''
+UPDATE ka_fall_dokumente_tbl_view
+SET daten = %(bytes)s, groesse = %(size)s, name = %(name)s,
+mime = %(mime)s, beschreibung = %(description)s
+WHERE id = %(id)s AND master_id = %(case)s
+'''
+
+LIST_CASE_WITH_DESC = '''
+SELECT id, master_id, groesse, mime, name, beschreibung
 FROM ka_fall_dokumente_tbl_view
 WHERE master_id = %(master_id)s
 '''
 
-DELETE_GLOBAL = '''
-SELECT delete_global_dokument_ds(%(id)s)
+LOAD_CASE_WITH_DESC = '''
+SELECT master_id, groesse, mime, daten, name, beschreibung
+FROM ka_fall_dokumente_tbl_view
+WHERE id = %(id)s
 '''
 
-DELETE_CASE = '''
-SELECT delete_fall_dokument_ds(%(id)s)
+UPDATE_CASE = '''
+UPDATE ka_fall_dokumente_tbl_view
+SET daten = %(bytes)s, groesse = %(size)s, name = %(name)s, mime = %(mime)s
+WHERE id = %(id)s AND master_id = %(case)s
 '''
 
-LOAD_GLOBAL = '''
-SELECT master_id, groesse, mime, daten, name
-FROM ka_global_dokumente_tbl_view
-WHERE id = %(id)s
+LIST_CASE = '''
+SELECT id, master_id, groesse, mime, name
+FROM ka_fall_dokumente_tbl_view
+WHERE master_id = %(master_id)s
 '''
 
 LOAD_CASE = '''
@@ -99,7 +136,6 @@
 WHERE id = %(id)s
 '''
 
-
 class DocumentException(Exception):
 
     def __init__(self, value):
@@ -113,21 +149,34 @@
     documents = []
 
     if case_id is None:
-        cursor.execute(LIST_GLOBAL)
+        if g.mpuls_config.is_enabled("module", "documents-description"):
+            stmnt = LIST_GLOBAL_WITH_DESC
+        else:
+            stmnt = LIST_GLOBAL
+        cursor.execute(stmnt)
     else:
-        cursor.execute(LIST_CASE, {'master_id': case_id})
+        if g.mpuls_config.is_enabled("module", "documents-description"):
+            stmnt = LIST_CASE_WITH_DESC
+        else:
+            stmnt = LIST_CASE
+        cursor.execute(stmnt, {'master_id': case_id})
 
     while True:
         row = cursor.fetchone()
         if not row:
             break
-        id, case, size, mime, name = row
-        documents.append(Document(id, case, size, mime, name))
+        if g.mpuls_config.is_enabled('module', 'documents-description'):
+            id, case, size, mime, name, description = row
+        else:
+            id, case, size, mime, name = row
+            description = None
+        documents.append(Document(id, case, size, mime, name, description))
 
     return documents
 
 
-def create_document_with_cursor(cursor, name, content, mime, case_id, uuid):
+def create_document_with_cursor(cursor, name, content, mime, case_id, uuid,
+                                description=""):
     if case_id is None:
         cursor.execute(CREATE_GLOBAL, {'name': name})
     else:
@@ -140,12 +189,19 @@
 
     document_id = row[0]
     fields = {'bytes': dbapi.Binary(content), 'size': len(content),
-              'name': name, 'mime': mime, 'id': document_id}
+              'name': name, 'mime': mime, 'id': document_id,
+              'description': description}
 
     if case_id is None:
-        stmnt = UPDATE_GLOBAL
+        if g.mpuls_config.is_enabled("module", "documents-description"):
+            stmnt = UPDATE_GLOBAL_WITH_DESC
+        else:
+            stmnt = UPDATE_GLOBAL
     else:
-        stmnt = UPDATE_CASE
+        if g.mpuls_config.is_enabled("module", "documents-description"):
+            stmnt = UPDATE_CASE_WITH_DESC
+        else:
+            stmnt = UPDATE_CASE
         fields['case'] = case_id
 
     cursor.execute(stmnt, fields)
@@ -181,13 +237,15 @@
 
 class Document:
 
-    def __init__(self, id=None, case=None, size=None, mime=None, name=None):
+    def __init__(self, id=None, case=None, size=None, mime=None, name=None,
+                       description=None):
         self.id = id
         self.case = case
         self.size = size
         self.mime = mime
         self.name = name
         self.data = None
+        self.description = description
 
     def isCaseAttached(self):
         return not self.case is None
@@ -198,7 +256,7 @@
             return None
         return h.ensure_unicode(name)
 
-    def create(self, name, src, case=None, uuid=None):
+    def create(self, name, src, case=None, uuid=None, description=None):
         name = name.strip().rsplit('\\', 1)[-1].rsplit('/', 1)[-1]
         if not name:
             raise DocumentException(_(u"No document available"))
@@ -222,7 +280,7 @@
 
         with db.transaction() as cur:
             self.id = create_document_with_cursor(cur, name, bytes, mime, case,
-                                                  uuid)
+                                                  uuid, description)
 
     def load(self, asCase=False):
         if self.id is None:
@@ -232,17 +290,30 @@
             con = db.getConnection()
             cur = con.cursor()
             if asCase:
-                cur.execute(LOAD_CASE, {'id': self.id})
+                if g.mpuls_config.is_enabled("module", "documents-description"):
+                    stmnt = LOAD_CASE_WITH_DESC
+                else:
+                    stmnt = LOAD_CASE
+                cur.execute(stmnt, {'id': self.id})
             else:
-                cur.execute(LOAD_GLOBAL, {'id': self.id})
+                if g.mpuls_config.is_enabled("module", "documents-description"):
+                    stmnt = LOAD_GLOBAL_WITH_DESC
+                else:
+                    stmnt = LOAD_GLOBAL
+                cur.execute(stmnt, {'id': self.id})
             row = cur.fetchone()
             if not row:
                 raise DocumentException(_(u"The requested document can't be found."))
+            print "XXX row=" + str(row)
             self.case = row[0]
             self.size = row[1]
             self.mime = row[2]
             self.data = row[3]
             self.name = row[4]
+            if g.mpuls_config.is_enabled("module", "documents-description"):
+                self.description = row[5]
+            else:
+                self.description = None
         finally:
             db.recycleConnection(con, cur)
 
@@ -257,14 +328,16 @@
         text_subelement(document_element, "anlage-name", document.name)
         text_subelement(document_element, "anlage-daten",
                         base64.b64encode(document.data))
+        text_subelement(document_element, "anlage-beschreibung",
+                        document.description)
 
-
 def get_documents_import_factory():
     """Return component factory for documents for libformed xmlimport"""
     entry_node = StructureNode(new_node(RepeatNode, "anlage"),
                                [new_node(TextLeaf, "anlage-mime"),
                                 new_node(TextLeaf, "anlage-name"),
                                 new_node(TextLeaf, "anlage-daten"),
+                                new_node(TextLeaf, "anlage-beschreibung"),
                                 ],
                                [])
     return ComponentFactory(None,
@@ -292,7 +365,9 @@
     name = document.get_leaf("anlage-name")
     mime = document.get_leaf("anlage-mime")
     content = base64.b64decode(document.get_leaf("anlage-daten"))
-    create_document_with_cursor(cursor, name, content, mime, case_id, None)
+    description = document.get_leaf("anlage-beschreibung")
+    create_document_with_cursor(cursor, name, content, mime, case_id, None,
+                                description)
 
 
 def load_known_documents(cursor, case_id):

Modified: base/trunk/mpulsweb/templates/documents/case_new.mako
===================================================================
--- base/trunk/mpulsweb/templates/documents/case_new.mako	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/templates/documents/case_new.mako	2011-11-09 14:13:18 UTC (rev 5561)
@@ -66,7 +66,17 @@
       </td>
       <td class=""><span class="error"><form:error name="name"></span></td>
     </tr>
+    % if g.mpuls_config.is_enabled("module", "documents-description"):
     <tr>
+	<td class="label">
+        <label for="description">${_('Description')}</label></td>
+      <td class="">
+        <input type="text" name="description" id="description"><br>
+      </td>
+      <td class=""><span class="error"><form:error name="description"></span></td>
+    </tr>
+    % endif
+    <tr>
       <td class="label">
       <td class="">
         <p class="note">${_('You can optional choose a alternative name for the file, so that you can add more versions of a document. If you choose no optional name, the name of the file is used.')}

Modified: base/trunk/mpulsweb/templates/documents/case_overview.mako
===================================================================
--- base/trunk/mpulsweb/templates/documents/case_overview.mako	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/templates/documents/case_overview.mako	2011-11-09 14:13:18 UTC (rev 5561)
@@ -72,6 +72,11 @@
           % endif
       </td>
     </tr>
+    % if g.mpuls_config.is_enabled("module", "documents-description"):
+    <tr>
+      <td colspan="3">${f.description}</td>
+    </tr>
+    % endif
     % endfor
   % else:
     <tr>

Modified: base/trunk/mpulsweb/templates/documents/global_overview.mako
===================================================================
--- base/trunk/mpulsweb/templates/documents/global_overview.mako	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/templates/documents/global_overview.mako	2011-11-09 14:13:18 UTC (rev 5561)
@@ -61,6 +61,11 @@
         % endif
     </td>
   </tr>
+  % if g.mpuls_config.is_enabled("module", "documents-description"):
+  <tr>
+    <td colspan="3">${f.description}</td>
+  </tr>
+  % endif
   % endfor
 % else:
   <tr>

Modified: base/trunk/mpulsweb/templates/documents/global_upload.mako
===================================================================
--- base/trunk/mpulsweb/templates/documents/global_upload.mako	2011-11-08 16:45:32 UTC (rev 5560)
+++ base/trunk/mpulsweb/templates/documents/global_upload.mako	2011-11-09 14:13:18 UTC (rev 5561)
@@ -54,7 +54,17 @@
       </td>
       <td class=""><span class="error"><form:error name="name"></span></td>
     </tr>
+    % if g.mpuls_config.is_enabled("module", "documents-description"):
     <tr>
+	<td class="label">
+        <label for="description">${_('Description')}</label></td>
+      <td class="">
+        <input type="text" name="description" id="description"><br>
+      </td>
+      <td class=""><span class="error"><form:error name="description"></span></td>
+    </tr>
+    % endif
+    <tr>
       <td class="label">
       <td class="">
         <p class="note">${_('You can optional choose a alternative name for the file, so that you can add more versions of a document. If you choose no optional name, the name of the file is used.')}  </p>



More information about the Mpuls-commits mailing list