本文整理汇总了Python中WebTemplates.WebTemplates.serverError方法的典型用法代码示例。如果您正苦于以下问题:Python WebTemplates.serverError方法的具体用法?Python WebTemplates.serverError怎么用?Python WebTemplates.serverError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebTemplates.WebTemplates
的用法示例。
在下文中一共展示了WebTemplates.serverError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WebSendMail
# 需要导入模块: from WebTemplates import WebTemplates [as 别名]
# 或者: from WebTemplates.WebTemplates import serverError [as 别名]
class WebSendMail(Resource):
fields = [{'name': 'subject', 'maxlength': 255},
{'name': 'body', 'maxlength': 64000},
{'name': 'username', 'maxlength': 255},
{'name': 'user_id', 'maxlength': 255}]
def __init__(self):
self.db = DBConnect()
self.template = WebTemplates()
self.render_POST = self.render_GET
Resource.__init__(self)
def getChild(self, path, request):
if path == "":
return self
else:
return static.File.childNotFound
#Formulario para mandar mail con sugerencias, bugs, etc
def render_GET(self, request):
d = defer.maybeDeferred(getTranslatorFromSession, request)
d.addCallback(self.doAuthentication, request)
return server.NOT_DONE_YET
def doAuthentication(self, trans, request):
session = request.getSession()
_ = trans
# 0) Se empieza la página
request.write(self.template.startPage(session, _('Criticas y sugerencias')))
d = defer.maybeDeferred(lambda:None)
# 1) Verificar que esté autenticado ante el sistema
msg = """<h2>""" + _('Criticas y sugerencias') + """</h2>""" \
+ _('Desde aqui puede mandar sus criticas, sugerencias y comentarios.') + " " \
+ _('La comunicacion se realizara mediante la casilla de mail con la cual se ha registrado.')
if not hasattr(session, 'username'):
request.write(self.template.notAuthenticated(session))
else:
# La función que procesa e imprime el contenido de la pagina
self.printContent(request, d, msg)
# 2) Se termina la página
d.addCallback(lambda a: request.write(self.template.finishPage(session)))
d.addCallback(lambda a: request.finish())
return d
def checkRequest(self, d, request):
session = request.getSession()
_ = session._
args = dict([(i, request.args[i][0]) for i in request.args.keys()])
if "submit" in request.args.keys():
for value in self.fields:
if value['name'] not in args.keys():
args[value['name']] = ''
d.addCallback(lambda a: \
request.write(self.template.unexpectedArguments(session, \
_('Falta el argumento \'%s\'') % value['name'])))
elif len(args[value['name']]) > value['maxlength']:
args[value['name']] = args[value['name']][:value['maxlength']]
d.addCallback(lambda a: \
request.write(self.template.unexpectedArguments(session, \
_('Longitud excesiva del argumento \'%s\'') % value['name'])))
return args
def printContent(self, request, d, page):
session = request.getSession()
args = self.checkRequest(d, request)
user_id = session.userId
query = "select username, id, email from person where id = %d"
d.addCallback(lambda a: self.db.db.runQuery(query, (user_id,)))
d.addCallback(self.mail, args, request, page)
return d
def mail(self, rows, args, request, page):
session = request.getSession()
_ = session._
if len(rows) == 1:
if "submit" in args.keys():
if args['body'] != "":
subject = "[%s][%s] %s" % (rows[0][1], rows[0][0], args['subject'])
msg = MIMEText(args['body'], _charset='utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = rows[0][2]
msg['To'] = MAIL_TO
try:
s = smtplib.SMTP(host = MAIL_HOST, port = MAIL_PORT)
s.sendmail(MAIL_FROM, [msg['To']], msg.as_string())
except:
request.write(self.template.serverError(session, \
_('Error al intentar establecer la comunicacion')))
else:
s.close()
request.write("""<div class="message"><h2>""" + \
_('Mail enviado correctamente') + """</h2>""" + \
_('Agradecemos su colaboracion') + """</div>""")
else:
request.write(self.template.unexpectedArguments(session, \
_('El texto del mail no debe ser vacio')))
else:
request.write(self.template.unexpectedArguments(session, \
_('El usuario no existe en el sistema')))
request.write(page)
#.........这里部分代码省略.........