appy.gen: bugfixes.

This commit is contained in:
Gaetan Delannay 2012-05-08 14:49:45 +02:00
parent 6245023365
commit 8cc20b0d34
5 changed files with 24 additions and 13 deletions

View file

@ -1,5 +1,5 @@
'''This package contains functions for sending email notifications.''' '''This package contains functions for sending email notifications.'''
import smtplib import smtplib, socket
from email.MIMEMultipart import MIMEMultipart from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText from email.MIMEText import MIMEText
@ -50,6 +50,8 @@ def sendMail(tool, to, subject, body, attachments=None):
if attachments: if attachments:
for fileName, fileContent in attachments: for fileName, fileContent in attachments:
part = MIMEBase('application', 'octet-stream') part = MIMEBase('application', 'octet-stream')
if fileContent.__class__.__name__ == 'FileWrapper':
fileContent = fileContent._zopeFile
if hasattr(fileContent, 'data'): if hasattr(fileContent, 'data'):
# It is a File instance coming from the database # It is a File instance coming from the database
data = fileContent.data data = fileContent.data
@ -87,6 +89,8 @@ def sendMail(tool, to, subject, body, attachments=None):
type='warning') type='warning')
except smtplib.SMTPException, e: except smtplib.SMTPException, e:
tool.log('Mail sending failed: %s' % str(e), type='error') tool.log('Mail sending failed: %s' % str(e), type='error')
except socket.error, se:
tool.log('Mail sending failed: %s' % str(se), type='error')
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
def sendNotification(obj, transition, transitionName, workflow): def sendNotification(obj, transition, transitionName, workflow):

View file

@ -223,6 +223,7 @@ class Tool(ModelClass):
# Tool attributes # Tool attributes
def isManager(self): pass def isManager(self): pass
def isManagerEdit(self): pass
title = gen.String(show=False, page=gen.Page('main', show=False)) title = gen.String(show=False, page=gen.Page('main', show=False))
mailHost = gen.String(default='localhost:25') mailHost = gen.String(default='localhost:25')
mailEnabled = gen.Boolean(default=False) mailEnabled = gen.Boolean(default=False)
@ -249,7 +250,7 @@ class Tool(ModelClass):
page=gen.Page('pages', show=isManager)) page=gen.Page('pages', show=isManager))
# Document generation page # Document generation page
dgp = {'page': gen.Page('documentGeneration', show=isManager)} dgp = {'page': gen.Page('documentGeneration', show=isManagerEdit)}
def validPythonWithUno(self, value): pass # Real method in the wrapper def validPythonWithUno(self, value): pass # Real method in the wrapper
unoEnabledPython = gen.String(show=False,validator=validPythonWithUno,**dgp) unoEnabledPython = gen.String(show=False,validator=validPythonWithUno,**dgp)
openOfficePort = gen.Integer(default=2002, show=False, **dgp) openOfficePort = gen.Integer(default=2002, show=False, **dgp)

View file

@ -1,3 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html metal:define-macro="main" <html metal:define-macro="main"
tal:define="user tool/getUser; tal:define="user tool/getUser;
isAnon tool/userIsAnon; isAnon tool/userIsAnon;
@ -8,7 +9,7 @@
_ python: tool.translate; _ python: tool.translate;
req python: request; req python: request;
resp req/RESPONSE; resp req/RESPONSE;
x python: resp.setHeader('Content-Type', 'text/html;;charset=UTF-8'); x python: resp.setHeader('Content-type', 'text/html;;charset=UTF-8');
x python: resp.setHeader('Expires', 'Thu, 11 Dec 1975 12:05:00 GMT+2'); x python: resp.setHeader('Expires', 'Thu, 11 Dec 1975 12:05:00 GMT+2');
x python: resp.setHeader('Content-Language', req.get('language', 'en'))"> x python: resp.setHeader('Content-Language', req.get('language', 'en'))">

View file

@ -34,6 +34,10 @@ class ToolWrapper(AbstractWrapper):
'''Some pages on the tool can only be accessed by God.''' '''Some pages on the tool can only be accessed by God.'''
if self.user.has_role('Manager'): return 'view' if self.user.has_role('Manager'): return 'view'
def isManagerEdit(self):
'''Some pages on the tool can only be accessed by God, also in edit.'''
if self.user.has_role('Manager'): return True
podOutputFormats = ('odt', 'pdf', 'doc', 'rtf') podOutputFormats = ('odt', 'pdf', 'doc', 'rtf')
def getPodOutputFormats(self): def getPodOutputFormats(self):
'''Gets the available output formats for POD documents.''' '''Gets the available output formats for POD documents.'''
@ -54,7 +58,11 @@ class ToolWrapper(AbstractWrapper):
def getDiskFolder(self): def getDiskFolder(self):
'''Returns the disk folder where the Appy application is stored.''' '''Returns the disk folder where the Appy application is stored.'''
return self.o.getProductConfig().diskFolder return self.o.config.diskFolder
def getClass(self, zopeName):
'''Gets the Appy class corresponding to technical p_zopeName.'''
return self.o.getAppyClass(zopeName)
def getAttributeName(self, attributeType, klass, attrName=None): def getAttributeName(self, attributeType, klass, attrName=None):
'''Some names of Tool attributes are not easy to guess. For example, '''Some names of Tool attributes are not easy to guess. For example,

View file

@ -281,23 +281,20 @@ def cleanXhtml(s, keepStyles=False):
return s return s
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
toLower = {'Ç':'ç','Ù':'ù','Û':'û','Ü':'ü','Î':'î','Ï':'ï','Ô':'ô','Ö':'ö',
'É':'é','È':'è','Ê':'ê','Ë':'ë','À':'à','Â':'â','Ä':'ä'}
toUpper = {'ç':'Ç','ù':'Ù','û':'Û','ü':'Ü','î':'Î','ï':'Ï','ô':'Ô','ö':'Ö',
'é':'É','è':'È','ê':'Ê','ë':'Ë','à':'À','â':'Â','ä':'Ä'}
def lower(s): def lower(s):
'''French-accents-aware variant of string.lower.''' '''French-accents-aware variant of string.lower.'''
isUnicode = isinstance(s, unicode)
if not isUnicode: s = s.decode('utf-8')
res = s.lower() res = s.lower()
for upp, low in toLower.iteritems(): if not isUnicode: res = res.encode('utf-8')
if upp in res: res = res.replace(upp, low)
return res return res
def upper(s): def upper(s):
'''French-accents-aware variant of string.upper.''' '''French-accents-aware variant of string.upper.'''
isUnicode = isinstance(s, unicode)
if not isUnicode: s = s.decode('utf-8')
res = s.upper() res = s.upper()
for low, upp in toUpper.iteritems(): if not isUnicode: res = res.encode('utf-8')
if low in res: res = res.replace(low, upp)
return res return res
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------