add possibility to send an SMS for test in the admin

This commit is contained in:
Frédéric Péters 2012-06-29 13:06:35 +02:00
parent e180b84fbb
commit 0521e128d6
1 changed files with 50 additions and 1 deletions

View File

@ -210,7 +210,7 @@ class SettingsDirectory(QommonSettingsDirectory):
'template', 'misc', 'emails', 'debug_options', 'language',
('import', 'p_import'), 'export', 'identification', 'sitename',
'sms', 'certificates', 'texts', 'utf8switch', 'upload_theme',
'session', 'download_theme']
'session', 'download_theme', 'smstest']
certificates = CertificatesDirectory()
emails = EmailsDirectory()
@ -723,6 +723,55 @@ class SettingsDirectory(QommonSettingsDirectory):
else:
form.render()
if mode != 'none':
form = Form(enctype='multipart/form-data', action='smstest')
form.add(StringWidget, 'sender', title=_('Sender'), required=True)
form.add(StringWidget, 'destinations', title=_('Destinations'), required=True)
form.add(StringWidget, 'text', title=_('Text'), required=True)
form.add_submit('submit', _('Submit'))
'<h3>%s</h3>' % _('SMS Test')
form.render()
def smstest [html] (self):
form = Form(enctype='multipart/form-data', action='smstest')
form.add(StringWidget, 'sender', title=_('Sender'), required=True)
form.add(StringWidget, 'destinations', title=_('Destinations'), required=True)
form.add(StringWidget, 'text', title=_('Text'), required=True)
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_widget('cancel').parse():
return redirect('sms')
if not form.get_submit():
return redirect('sms')
get_response().breadcrumb.append(('smstest', _('SMS Test')))
html_top('settings', title = _('SMS Test'))
'<h2>%s</h2>' % _('SMS Test')
form.render()
if not form.has_errors():
sms_cfg = get_cfg('sms', {})
mode = sms_cfg.get('mode', 'none')
sms = SMS.get_sms_class(mode)
sender = str(form.get_widget('sender').parse())
destinations = str(form.get_widget('destinations').parse()).split(str(','))
text = str(form.get_widget('text').parse())
try:
sms.send(sender, destinations, text)
except Exception, e:
'<pre>'
repr(e)
'</pre>'
else:
'<p>'
_('Success')
'</p>'
def utf8switch(self):
def toutf8(x):