[Mpuls-commits] r1575 - in wasko/branches/2.0: . mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Feb 15 19:45:11 CET 2010


Author: bh
Date: 2010-02-15 19:45:10 +0100 (Mon, 15 Feb 2010)
New Revision: 1575

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/mpulsweb/model/document.py
Log:
* mpulsweb/model/document.py: Fix formatting.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-02-15 18:39:50 UTC (rev 1574)
+++ wasko/branches/2.0/ChangeLog	2010-02-15 18:45:10 UTC (rev 1575)
@@ -1,5 +1,9 @@
 2010-02-15  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/model/document.py: Fix formatting.
+
+2010-02-15  Bernhard Herzog  <bh at intevation.de>
+
 	* waskaweb/controllers/casedocument.py: Remove unused imports
 
 2010-02-15  Bernhard Herzog  <bh at intevation.de>

Modified: wasko/branches/2.0/mpulsweb/model/document.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/document.py	2010-02-15 18:39:50 UTC (rev 1574)
+++ wasko/branches/2.0/mpulsweb/model/document.py	2010-02-15 18:45:10 UTC (rev 1575)
@@ -1,27 +1,27 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS - 
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
 # Web-Anwendungs-Server fuer Kompetenzagenturen).
-# 
+#
 # mpuls WASKA is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the
 # Free Software Foundation, either version 3 of the License, or (at your
 # option) any later version.
-# 
+#
 # mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 # License for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public
 # License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-# 
-# mpuls WASKA has been developed on behalf of the 
+#
+# mpuls WASKA has been developed on behalf of the
 # Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
 # within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
 # European Social Fund resources.
 #
 # Authors:
@@ -29,26 +29,29 @@
 #
 
 from mimetypes import guess_type
-import mpulsweb.lib.helpers as h
-import psycopg2  as dbapi
 import cStringIO as StringIO
 
+import psycopg2  as dbapi
+
+import mpulsweb.lib.helpers as h
 from mpulsweb.lib.db import db
 
-MAX_SIZE   = 10*1024*1024
-BLOCK_SIZE = 4*1024
 
+MAX_SIZE = 10 * 1024 * 1024
+BLOCK_SIZE = 4 * 1024
+
 CREATE_GLOBAL = 'SELECT * FROM create_global_dokument_ds(%(name)s)'
-CREATE_CASE   = 'SELECT * FROM create_fall_dokument_ds(%(id)s, %(uuid)s, %(name)s)'
+CREATE_CASE = '\
+SELECT * FROM create_fall_dokument_ds(%(id)s, %(uuid)s, %(name)s)'
 
 UPDATE_GLOBAL = '''
-UPDATE ka_global_dokumente_tbl_view 
+UPDATE ka_global_dokumente_tbl_view
 SET daten = %(bytes)s, groesse = %(size)s, name = %(name)s, mime = %(mime)s
 WHERE id = %(id)s
 '''
 
 UPDATE_CASE = '''
-UPDATE ka_fall_dokumente_tbl_view 
+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
 '''
@@ -84,6 +87,7 @@
 WHERE id = %(id)s
 '''
 
+
 class DocumentException(Exception):
 
     def __init__(self, value):
@@ -92,10 +96,11 @@
     def __str__(self):
         return repr(self.value)
 
+
 def listDocuments(case=None):
+    if not case is None:
+        case = int(case)
 
-    if not case is None: case = int(case)
-
     documents = []
 
     con, cur = None, None
@@ -105,11 +110,12 @@
         if case is None:
             cur.execute(LIST_GLOBAL)
         else:
-            cur.execute(LIST_CASE, { 'master_id': case })
+            cur.execute(LIST_CASE, {'master_id': case})
 
         while True:
             row = cur.fetchone()
-            if not row: break
+            if not row:
+                break
             id, case, size, mime, name = row
             documents.append(Document(id, case, size, mime, name))
     finally:
@@ -119,24 +125,31 @@
 
 def deleteDocument(id, case=False):
     id = int(id)
-    con, cur, has_commited = None, None, False
+    has_commited = False
+    con, cur = None, None
     try:
         con = db.getConnection()
         cur = con.cursor()
-        if case: cur.execute(DELETE_CASE,   { 'id': id })
-        else:    cur.execute(DELETE_GLOBAL, { 'id': id })
+        if case:
+            cur.execute(DELETE_CASE, {'id': id})
+        else:
+            cur.execute(DELETE_GLOBAL, {'id': id})
         con.commit()
         has_commited = True
     finally:
         if not has_commited and con:
-            try: con.rollback()
-            except: pass
+            try:
+                con.rollback()
+            except:
+                pass
 
         db.recycleConnection(con, cur)
 
+
 class Document:
+
     def __init__(self, id=None, case=None, size=None, mime=None, name=None):
-        self.id   = id
+        self.id = id
         self.case = case
         self.size = size
         self.mime = mime
@@ -148,23 +161,24 @@
 
     def getName(self, encoding="utf-8"):
         name = self.name
-        if name is None: return None
+        if name is None:
+            return None
         if encoding:
             return unicode(str(name), encoding)
         return name
 
     def create(self, name, src, case=None, uuid=None):
-
         name = name.strip().rsplit('\\', 1)[-1].rsplit('/', 1)[-1]
-
         if not name:
             raise DocumentException("Kein Dokumentname vorhanden.")
 
         self.name = name
 
         mime = guess_type(name)
-        if mime: mime = mime[0]
-        else:    mime = "application/octet-stream"
+        if mime:
+            mime = mime[0]
+        else:
+            mime = "application/octet-stream"
 
         self.mime = mime
 
@@ -177,40 +191,39 @@
         while True:
             b = src.read(BLOCK_SIZE)
             l = len(b)
-            if l == 0: break
+            if l == 0:
+                break
             total_size += l
             if total_size > MAX_SIZE:
                 raise DocumentException(
-                    u"Datei ist zu groß. Maximal %sMB sind erlaubt." \
+                    u"Datei ist zu groß. Maximal %sMB sind erlaubt."
                     % h.format_number(MAX_SIZE/float(1024*1024)))
             out.write(b)
         bytes = out.getvalue()
-        out.close(); out = None
+        out.close()
+        out = None
 
         self.size = total_size
 
-        has_commited, con, cur = False, None, None
-
+        has_commited = False
+        con, cur = None, None
         try:
             con = db.getConnection()
             cur = con.cursor()
 
-            if case is None: 
+            if case is None:
                 cur.execute(CREATE_GLOBAL, {'name': name})
-            else:            
-                cur.execute(CREATE_CASE, { 'id': case, 'uuid': uuid, 'name': name})
+            else:
+                cur.execute(CREATE_CASE,
+                            {'id': case, 'uuid': uuid, 'name': name})
 
             row = cur.fetchone()
             if row is None:
                 raise DocumentException("Konnte neues Dokument nicht anlegen.")
 
             id = row[0]
-            fields = {
-                'bytes': dbapi.Binary(bytes),
-                'size':  total_size,
-                'name':  name,
-                'mime':  mime,
-                'id':    id } 
+            fields = {'bytes': dbapi.Binary(bytes), 'size': total_size,
+                      'name': name, 'mime': mime, 'id': id}
 
             if case is None:
                 stmnt = UPDATE_GLOBAL
@@ -226,12 +239,16 @@
             self.id = id
         finally:
             if cur:
-                try: cur.close()
-                except: pass
+                try:
+                    cur.close()
+                except:
+                    pass
 
             if not has_commited and con:
-                try: con.rollback()
-                except: pass
+                try:
+                    con.rollback()
+                except:
+                    pass
 
             db.recycleConnection(con)
 
@@ -242,12 +259,14 @@
         try:
             con = db.getConnection()
             cur = con.cursor()
-            if asCase: cur.execute(LOAD_CASE,   { 'id': self.id })
-            else:      cur.execute(LOAD_GLOBAL, { 'id': self.id })
+            if asCase:
+                cur.execute(LOAD_CASE, {'id': self.id})
+            else:
+                cur.execute(LOAD_GLOBAL, {'id': self.id})
             row = cur.fetchone()
             if not row:
-                raise DocumentException(
-                    u"Das angeforderte Dokument kann nicht gefunden werden.")
+                raise DocumentException(u"Das angeforderte Dokument kann nicht"
+                                        u" gefunden werden.")
             self.case = row[0]
             self.size = row[1]
             self.mime = row[2]



More information about the Mpuls-commits mailing list