Exemplo n.º 1
0
 def POST(self):
     i = web.input()
     wyrform = forms.wyrform()
     if wyrform.validates(i):
         auth.assert_login(i)
         try:
             status = self.save_and_send_msg(i, wyrform)
         except CaptchaException:
             msg, msg_type = helpers.get_delete_msg()
             return render.writerep(wyrform, msg)
         else:
             if status:
                 p = db.select('politician', what='firstname, middlename, lastname',
                                 where='id=$self.pol', vars=locals())[0]
                 polstr = '<a href="/p/%s">%s %s %s</a>' % (self.pol, p.firstname, p.middlename, p.lastname)  
                 helpers.set_msg('Your message has been sent to %s.' % polstr)
             else:
                 helpers.set_msg('Sorry, your message has NOT been sent.', 'error')
         raise web.seeother('/')
     else:
         return self.GET(wyrform)
Exemplo n.º 2
0
 def POST(self):
     def pol_link(polid):
         p = db.select('politician', what='firstname, middlename, lastname',
                         where='id=$polid', vars=locals())[0]
         return '<a href="/p/%s">%s %s %s</a>' % (polid, p.firstname or '',
                         p.middlename or '', p.lastname or '')
             
 	i = web.input()
 	wf = forms.wyrform()
 	pols = getpols(i.zip5, i.zip4, i.addr1+i.addr2)
 	captcha_needed = require_captcha(i, pols)
 	if not wf.validates(i) or captcha_needed:
         if captcha_needed: wf.valid, wf.note = False, 'Please fill the captcha below'
 	    wf.fill(i)
 	    return self.GET(wf)
 	else:
 	    uid = auth.assert_login(i)
 	    update_user_details(i, uid)
 	    env = simplejson.loads(i.get('captcha_env', '{}'))
 	    status = writerep.send_msgs(uid, i, source_id='wyr', pols=pols, env=env)
 	    pol_str = ", ".join([pol_link(p) for p in pols])
 	    helpers.set_msg('Your message has been sent to %s' % pol_str)
 	    raise web.seeother('/')