[Mpuls-commits] r1106 - wasko/branches/2.0/waskaweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Feb 1 18:22:16 CET 2010


Author: torsten
Date: 2010-02-01 18:22:14 +0100 (Mon, 01 Feb 2010)
New Revision: 1106

Modified:
   wasko/branches/2.0/waskaweb/controllers/casedocument.py
Log:
* waskaweb/controllers/casedocument.py (CasedocumentController.newAction): 
  New.



Modified: wasko/branches/2.0/waskaweb/controllers/casedocument.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/casedocument.py	2010-02-01 17:09:42 UTC (rev 1105)
+++ wasko/branches/2.0/waskaweb/controllers/casedocument.py	2010-02-01 17:22:14 UTC (rev 1106)
@@ -1,14 +1,21 @@
+# -*- coding: utf-8 -*-
 import logging
 
-from pylons import request, response, session, tmpl_context as c
+from pylons import request, response, session, tmpl_context as c, h
 from pylons.controllers.util import abort, redirect_to
 
 from waskaweb.lib.base import BaseController, render
 from waskaweb.lib.security import checkRole
 from waskaweb.model.case import CaseFactory, LoadCaseNotExistsError
+from waskaweb.model.document import Document
 
 log = logging.getLogger(__name__)
 
+SET_ATTACHMENT_SUCCESS_HEADER       = u"""Anlage hinzugefügt!"""
+SET_ATTACHMENT_SUCCESS_TEXT         = u"""Bitte klicken Sie auf "OK", um fortzufahren."""
+SET_ATTACHMENT_FAILED_HEADER        = u"""Keine Anlage hinzugefügt!"""
+SET_ATTACHMENT_FAILED_TEXT          = u"""Vergewissern Sie sich, ob der angegebene Pfad korrekt ist. Anlagen  können direkt über den "Browse" bzw. "Durchsuchen" Button ausgewählt werden. Bitte klicken Sie auf "OK", um fortzufahren."""
+
 def loadCase(id):
     factory = CaseFactory()
     try:
@@ -33,3 +40,31 @@
     def new(self):
         return render('/documents/case_new.mako')
 
+    @checkRole('cm_ka')
+    def newAction(self):
+        try:
+            case = int(request.POST['case'])
+        except:
+            redirect_to(controller="casedocument", action="index") 
+
+        try:
+            doc = Document()
+            myfile = None
+            try:
+                myfile = request.POST.get('file')
+                if not myfile is None:
+                    doc.create(myfile.filename, myfile.file, case)
+                    c.success_for = SET_ATTACHMENT_SUCCESS_HEADER
+                    c.success_text = SET_ATTACHMENT_SUCCESS_TEXT
+                    c.url_ok = h.url_for(controller="/casedocument", action="index", id=case)
+                    return render('/documents/dialogs/success_attachment.mako')
+            finally:
+                if not myfile is None:
+                    try: myfile.file.close()
+                    except: pass
+        except Exception, e:
+            log.exception(e)
+            c.failed_for = SET_ATTACHMENT_FAILED_HEADER
+            c.failed_text = SET_ATTACHMENT_FAILED_TEXT
+            c.url_ok = h.url_for(controller="/casedocument", action="new", id=case)
+            return render('/documents/dialogs/failed_attachment.mako')



More information about the Mpuls-commits mailing list