def POST_sign(self, pid): i = web.input() sf = forms.signform() tocongress = to_congress(pid) p = get_petition_by_id(pid) is_new = lambda sid: not isinstance(sid, str) get_new = lambda sid: int(web.lstrips(sid, "old_")) if tocongress: i.pid, i.ptitle, i.msg = pid, p.title, p.description wf = forms.wyrform() captcha_needed = require_captcha(i) wyr_valid = wf.validates(i) and not captcha_needed if captcha_needed: wf.valid, wf.note = False, "Please fill the captcha below" else: wf, wyr_valid = None, True if sf.validates(i) and wyr_valid: uid = auth.assert_login(i) signid = save_signature(i, pid, uid) if is_new(signid): user = helpers.get_user_by_id(uid) sendmail_to_signatory(user, pid) else: signid = get_new(signid) if tocongress: send_to_congress(uid, i, signid) query = urllib.urlencode(dict(url="/c/%s" % pid, title=p.title)) raise web.seeother("/share?%s" % query, absolute=True) else: return self.GET(pid, sf=sf, wf=wf)
def POST_sign(self, pid): i = web.input() sform = forms.signform() tocongress = to_congress(pid) p = get_petition_by_id(pid) if tocongress: i.pid, i.ptitle, i.msg = pid, p.title, p.description wyrform = forms.wyrform() wyr_valid = wyrform.validates(i) else: wyrform, wyr_valid = None, True if sform.validates(i) and wyr_valid: auth.assert_login(i) user = helpers.get_user_by_email(i.email) signid = save_signature(i, pid, user.id, tocongress) if tocongress: try: i.msg = "%s\n%s" %(i.msg, i.comment) #need to compose msg_sent = send_to_congress(i, wyrform, signid) except CaptchaException: return self.GET(pid, signform=sform, wyrform=wyrform) if signid: sendmail_to_signatory(user, pid) query = urllib.urlencode(dict(url='/c/%s' % pid, title=p.title)) raise web.seeother('/share?%s' % query, absolute=True) else: return self.GET(pid, signform=sform, wyrform=wyrform)
def GET(self, pid, sf=None, wf=None): i = web.input() pid = pid.rstrip("/") p = get_petition_by_id(pid) if not p: raise web.notfound() options = ["unsign", "edit", "delete"] if i.get("m", None) in options: handler = getattr(self, "GET_" + i.m) return handler(pid) if not sf: sf = forms.signform() fill_user_details(sf) captcha_html = "" if to_congress(pid): if not wf: wf = forms.wyrform() fill_user_details(wf) captcha_html = wyrapp.prepare_for_captcha(wf) if "tid" in i: set_referrer_cookie(i.tid, pid) raise web.seeother("/%s" % pid) u = web.storage() u.email = helpers.get_loggedin_email() or helpers.get_unverified_email() u.isauthor = is_author(u.email, pid) u.issignatory = is_signatory(u.email, pid) p.isdraft = is_draft(p) p.signatory_count = get_num_signs(pid) msg, msg_type = helpers.get_delete_msg() return render.petition(p, u, sf, wf, captcha_html, msg)
def GET(self, pid, signform=None, wyrform=None): i = web.input() pid = pid.rstrip('/') p = get_petition_by_id(pid) if not p: raise web.notfound options = ['unsign', 'edit', 'delete'] if i.get('m', None) in options: handler = getattr(self, 'GET_'+i.m) return handler(pid) p.signatory_count = get_num_signs(pid) if not signform: signform = forms.signform() fill_user_details(signform) if to_congress(pid) and not wyrform: wyrform = forms.wyrform() fill_user_details(wyrform) add_captcha(wyrform) if 'tid' in i: set_referrer_cookie(i.tid, pid) raise web.seeother('/%s' % pid) msg, msg_type = helpers.get_delete_msg() useremail = helpers.get_loggedin_email() or helpers.get_unverified_email() isauthor = is_author(useremail, pid) issignatory = is_signatory(useremail, pid) return render.petition(p, signform, useremail, isauthor, issignatory, wyrform, msg)
def POST_sign(self, pid): i = web.input() sf = forms.signform() tocongress = to_congress(pid) p = get_petition_by_id(pid) is_new = lambda sid: not isinstance(sid, str) get_new = lambda sid: int(web.lstrips(sid, 'old_')) if tocongress: i.pid, i.ptitle, i.msg = pid, p.title, p.description wf = forms.wyrform() captcha_needed = require_captcha(i) wyr_valid = wf.validates(i) and not captcha_needed if captcha_needed: wf.valid, wf.note = False, 'Please fill the captcha below' else: wf, wyr_valid = None, True if sf.validates(i) and wyr_valid: uid = auth.assert_login(i) signid = save_signature(i, pid, uid) if is_new(signid): user = helpers.get_user_by_id(uid) sendmail_to_signatory(user, pid) else: signid = get_new(signid) if tocongress: send_to_congress(uid, i, signid) query = urllib.urlencode(dict(url='/c/%s' % pid, title=p.title)) raise web.seeother('/share?%s' % query, absolute=True) else: return self.GET(pid, sf=sf, wf=wf)
def GET(self, pid, sf=None, wf=None): i = web.input() pid = pid.rstrip('/') p = get_petition_by_id(pid) if not p: raise web.notfound() options = ['unsign', 'edit', 'delete'] if i.get('m', None) in options: handler = getattr(self, 'GET_' + i.m) return handler(pid) if not sf: sf = forms.signform() fill_user_details(sf) captcha_html = '' if to_congress(pid): if not wf: wf = forms.wyrform() fill_user_details(wf) captcha_html = wyrapp.prepare_for_captcha(wf) if 'tid' in i: set_referrer_cookie(i.tid, pid) raise web.seeother('/%s' % pid) u = web.storage() u.email = helpers.get_loggedin_email() or helpers.get_unverified_email( ) u.isauthor = is_author(u.email, pid) u.issignatory = is_signatory(u.email, pid) p.isdraft = is_draft(p) p.signatory_count = get_num_signs(pid) msg, msg_type = helpers.get_delete_msg() return render.petition(p, u, sf, wf, captcha_html, msg)
def POST_sign(self, pid): form = forms.signform() i = web.input() if form.validates(i): user = save_signature(i, pid) sendmail_to_signatory(user, pid) return web.seeother('/%s' % pid) else: return self.GET(pid, signform=form)
def GET(self, pid, signform=None, passwordform=None): i = web.input() options = ['signatories', 'unsign', 'edit', 'delete'] if i.get('m', None) in options: handler = getattr(self, 'GET_'+i.m) return handler(pid) try: p = db.select('petition', where='id=$pid', vars=locals())[0] except: raise web.notfound p.signatory_count = db.query('select count(*) from signatory where petition_id=$pid', vars=locals())[0].count if not signform: signform = forms.signform() fill_user_details(signform, ['name', 'email']) if askforpasswd(p.owner_id) and not passwordform: passwordform = forms.passwordform() msg, msg_type = helpers.get_delete_msg() return render.petition(p, signform, passwordform, msg)