def GET(self, wyrform=None): pform = forms.petitionform() cform = wyrform or forms.wyrform() fill_user_details(cform) add_captcha(cform) email = helpers.get_loggedin_email() or helpers.get_unverified_email() return render.petitionform(pform, cform)
def GET(self, emailform=None, loadcontactsform=None): i = web.input() url = i.get('url', '/') title = i.get('title', 'The good government site with teeth') user_id = helpers.get_loggedin_userid() contacts = get_contacts(user_id) sender = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email()) page_or_petition = 'page' isdraft = False if not emailform: emailform = forms.emailform() track_id, description = None, None if url.startswith('/c/') and url != '/c/': url = url.rstrip('/') pid = web.lstrips(url, '/c/') p = get_petition_by_id(pid) isdraft = is_draft(p) description = p and p.description track_id = helpers.get_trackid(user_id, pid) if not isdraft else None contacts = filter(lambda c: not is_signatory(c.email, pid), contacts) page_or_petition = 'petition' msg = render_plain.share_mail(title, url, sender, description, isdraft, track_id) emailform.fill(subject=title, body=msg) loadcontactsform = loadcontactsform or forms.loadcontactsform() msg, msg_type = helpers.get_delete_msg() return render.share(title, url, emailform, contacts, loadcontactsform, page_or_petition, msg)
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): user_email = helpers.get_loggedin_email() p = get_petition_by_id(pid) if not p: raise web.notfound ptitle = p.title signs = get_signs(pid).list() return render.signature_list(pid, ptitle, signs, is_author(user_email, pid))
def GET(self, emailform=None, loadcontactsform=None): i = web.input() url = i.get('url', '/') title = i.get('title', 'The good government site with teeth') user_id = helpers.get_loggedin_userid() contacts = get_contacts(user_id) sender = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email()) page_or_petition = 'page' if not emailform: emailform = forms.emailform() track_id, description = None, None if url.startswith('/c/') and url != '/c/': url = url.rstrip('/') pid = web.lstrips(url, '/c/') p = get_petition_by_id(pid) description = p and p.description track_id = helpers.get_trackid(user_id, pid) contacts = filter(lambda c: not is_signatory(c.email, pid), contacts) page_or_petition = 'petition' msg = render_plain.share_mail(title, url, sender, description, track_id) emailform.fill(subject=title, body=msg) loadcontactsform = loadcontactsform or forms.loadcontactsform() msg, msg_type = helpers.get_delete_msg() return render.share(title, url, emailform, contacts, loadcontactsform, page_or_petition, msg)
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, emailform=None, loadcontactsform=None): i = web.input() url = i.get("url", "/") title = i.get("title", "The good government site with teeth") user_id = helpers.get_loggedin_userid() contacts = get_contacts(user_id) sender = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email()) page_or_petition = "page" isdraft = False if not emailform: emailform = forms.emailform() track_id, description = None, None if url.startswith("/c/") and url != "/c/": url = url.rstrip("/") pid = web.lstrips(url, "/c/") p = get_petition_by_id(pid) isdraft = is_draft(p) description = p and p.description track_id = helpers.get_trackid(user_id, pid) if not isdraft else None contacts = filter(lambda c: not is_signatory(c.email, pid), contacts) page_or_petition = "petition" msg = render_plain.share_mail(title, url, sender, description, isdraft, track_id) emailform.fill(subject=title, body=msg) loadcontactsform = loadcontactsform or forms.loadcontactsform() msg, msg_type = helpers.get_delete_msg() return render.share(title, url, emailform, contacts, loadcontactsform, page_or_petition, msg)
def fill_user_details(form, fillings): details = {} if 'email' in fillings: email = helpers.get_loggedin_email() or helpers.get_unverified_email() if email: details['email'] = email if email and 'name' in fillings: name = db.select('users', what='name', where='email=$email', vars=locals())[0].name if name: details['name'] = name form.fill(**details) if helpers.get_loggedin_email(): for i in form.inputs: if i.name in details.keys(): i.attrs['readonly'] = 'true'
def POST(self, input=None): i = input or web.input() tocongress = i.get('tocongress', 'off') == 'on' pform, wyrform = forms.petitionform(), forms.wyrform() i.email = '*****@*****.**' # to make wyrform valid, find a better work around wyr_valid = (not(tocongress) or wyrform.validates(i)) if 'signid' in i: signid = i.signid send_to_congress(i, wyrform, signid) raise web.seeother('/%s' % i.pid) if not pform.validates(i) or not wyr_valid: return render.petitionform(pform, wyrform) email = helpers.get_loggedin_email() if not email: return login().GET(i) try: create_petition(i, email, wyrform) except CaptchaException: msg, msg_type = helpers.get_delete_msg() return render.petitionform(pform, wyrform, msg) raise web.seeother('/%s' % i.pid)
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 GET(self, pid): user_email = helpers.get_loggedin_email() p = get_petition_by_id(pid) if not p: raise web.notfound() ptitle = p.title signs = get_signs(pid).list() return render.signature_list(pid, ptitle, signs, is_author(user_email, pid))
def GET_delete(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): msg = str(render_plain.confirm_deletion(pid)) helpers.set_msg(msg) else: login_link = '<a href="/u/login">Login</a>' helpers.set_msg('Only author of this petition can delete it. %s if you are.' % login_link, msg_type='error') raise web.seeother('/%s' % pid)
def GET_signatories(self, pid): user_email = helpers.get_loggedin_email() ptitle = db.select('petition', what='title', where='id=$pid', vars=locals())[0].title signs = db.select(['signatory', 'users'], what='users.name, users.email, ' 'signatory.share_with, signatory.comment', where='petition_id=$pid AND user_id=users.id', order='signtime desc', vars=locals()).list() return render.signature_list(pid, ptitle, signs, is_author(user_email, pid))
def GET_delete(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): msg = str(render_plain.confirm_deletion(pid)) elif user_email: msg = "You don't have permissions to delete this petition." else: login_link = '<a href="/u/login">Login</a>' msg = 'Only author of this petition can delete it. %s if you are.' % login_link helpers.set_msg(msg) raise web.seeother('/%s' % pid)
def GET_delete(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): msg = str(render_plain.confirm_deletion(pid)) elif user_email: msg = "You don't have permissions to delete this petition." else: login_link = '<a href="/u/login">Login</a>' msg = "Only author of this petition can delete it. %s if you are." % login_link helpers.set_msg(msg) raise web.seeother("/%s" % pid)
def get_signid(pid): uemail = helpers.get_loggedin_email() or helpers.get_unverified_email() user = helpers.get_user_by_email(uemail) uid = user and user.id try: sign = db.select('signatory', what='id', where="petition_id=$pid and user_id=$uid", vars=locals())[0] except IndexError: pass else: return sign.id
def POST_edit(self, pid): i = web.input() tocongress = i.get('tocongress', 'off') == 'on' pform = forms.petitionform() pform.inputs = filter(lambda i: i.name != 'pid', pform.inputs) wyrform = forms.wyrform() i.email = helpers.get_loggedin_email() wyr_valid = (not(tocongress) or wyrform.validates(i)) if not pform.validates(i) or not wyr_valid: title = "Edit petition" return render.petitionform(pform, wyrform, title, target='/c/%s?m=edit' % (pid)) db.update('petition', where='id=$pid', title=i.ptitle, description=i.msg, to_congress=tocongress, vars=locals()) update_user_details(i) raise web.seeother('/%s' % pid)
def GET_edit(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): p = db.select('petition', where='id=$pid', vars=locals())[0] pform = forms.petitionform() pform.fill(email=user_email, pid=p.id, ptitle=p.title, pdescription=p.description) for i in pform.inputs: if i.id in ['pid', 'email']: i.attrs['readonly'] = 'true' title = "Edit petition" return render.petitionform(pform, title, target='/c/%s?m=edit' % (pid)) else: login_link = '<a href="/login">Login</a>' helpers.set_msg('Only author of this petition can edit it. %s if you are.' % login_link, msg_type='error') raise web.seeother('/%s' % pid)
def POST(self): i = web.input() emailform, loadcontactsform = forms.emailform(), forms.loadcontactsform() if emailform.validates(i): url, msg, subject = i.url, i.body, i.subject emails = [e.strip() for e in i.emails.strip(", ").split(",")] u = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email()) from_address = u and "%s %s <%s>" % (u.fname, u.lname, u.email) or config.from_address for email in emails: web.sendmail(from_address, email, subject, msg) page_or_petition = url.startswith("/c/") and "petition" or "page" helpers.set_msg("Thanks for sharing this %s with your friends!" % page_or_petition) raise web.seeother(url) else: return self.GET(emailform=emailform, loadcontactsform=loadcontactsform)
def GET_edit(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): p = get_petition_by_id(pid) u = helpers.get_user_by_email(user_email) pform = forms.petitionform() pform.fill(userid=u.id, email=user_email, pid=p.id, ptitle=p.title, msg=p.description, tocongress=p.to_congress) cform = forms.wyrform() fill_user_details(cform) title = "Edit your petition" return render.petitionform(pform, cform, title, target='/c/%s?m=edit' % (pid)) else: login_link = '<a href="/u/login">Login</a>' helpers.set_msg('Only author of this petition can edit it. %s if you are.' % login_link, msg_type='error') raise web.seeother('/%s' % pid)
def POST_edit(self, pid): i = web.input() tocongress = i.get('tocongress', 'off') == 'on' pf = forms.petitionform() pf.inputs = filter(lambda i: i.name != 'pid', pf.inputs) wf = forms.wyrform() i.email = helpers.get_loggedin_email() wyr_valid = (not (tocongress) or wf.validates(i)) if not pf.validates(i) or not wyr_valid: return render.petitionform(pf, wf, is_new=False, is_draft=is_draft) p = dict(title=i.ptitle, description=i.msg, to_congress=tocongress) if 'publish' in i: p['published'] = datetime.now() db.update('petition', where='id=$pid', vars=locals(), **p) if 'publish' in i: create_first_signature(i, i.email) update_user_details(i) raise web.seeother('/%s' % pid)
def POST_edit(self, pid): i = web.input() tocongress = i.get("tocongress", "off") == "on" pf = forms.petitionform() pf.inputs = filter(lambda i: i.name != "pid", pf.inputs) wf = forms.wyrform() i.email = helpers.get_loggedin_email() wyr_valid = not (tocongress) or wf.validates(i) if not pf.validates(i) or not wyr_valid: return render.petitionform(pf, wf, is_new=False, is_draft=is_draft) p = dict(title=i.ptitle, description=i.msg, to_congress=tocongress) if "publish" in i: p["published"] = datetime.now() db.update("petition", where="id=$pid", vars=locals(), **p) if "publish" in i: create_first_signature(i, i.email) update_user_details(i) raise web.seeother("/%s" % pid)
def GET_edit(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): p = get_petition_by_id(pid) u = helpers.get_user_by_email(user_email) pf = forms.petitionform() pf.fill( userid=u.id, email=user_email, pid=p.id, ptitle=p.title, msg=p.description, tocongress=p.to_congress ) wf = forms.wyrform() fill_user_details(wf) isdraft = is_draft(p) return render.petitionform(pf, wf, is_new=False, is_draft=isdraft) elif user_email: msg = "You don't have permissions to edit this petition." else: login_link = '<a href="/u/login">Login</a>' msg = "Only author of this petition can edit it. %s if you are." % login_link helpers.set_msg(msg) raise web.seeother("/%s" % pid)
def POST(self): i = web.input() emailform, loadcontactsform = forms.emailform( ), forms.loadcontactsform() if emailform.validates(i): url, msg, subject = i.url, i.body, i.subject emails = [e.strip() for e in i.emails.strip(', ').split(',')] u = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email()) from_address = u and "%s %s <%s>" % ( u.fname, u.lname, u.email) or config.from_address for email in emails: web.sendmail(from_address, email, subject, msg) page_or_petition = url.startswith('/c/') and 'petition' or 'page' helpers.set_msg('Thanks for sharing this %s with your friends!' % page_or_petition) raise web.seeother(url) else: return self.GET(emailform=emailform, loadcontactsform=loadcontactsform)
def POST(self): i = web.input() tocongress = i.get('tocongress', 'off') == 'on' pf, wf = forms.petitionform(), forms.wyrform() i.email = '*****@*****.**' # to make wf valid, find a better work around wyr_valid = (not (tocongress) or wf.validates(i)) captcha_needed = require_captcha(i) wyr_valid = wyr_valid and not captcha_needed if not pf.validates(i) or not wyr_valid: if captcha_needed: wf.valid, wf.note = False, 'Please fill the captcha below' pf.fill(i), wf.fill(i) return self.GET(pf, wf) email = helpers.get_loggedin_email() if not email: return login().GET(i) create_petition(i, email) raise web.seeother('/%s' % i.pid)
def POST(self): i = web.input() tocongress = i.get("tocongress", "off") == "on" pf, wf = forms.petitionform(), forms.wyrform() i.email = "*****@*****.**" # to make wf valid, find a better work around wyr_valid = not (tocongress) or wf.validates(i) captcha_needed = require_captcha(i) wyr_valid = wyr_valid and not captcha_needed if not pf.validates(i) or not wyr_valid: if captcha_needed: wf.valid, wf.note = False, "Please fill the captcha below" pf.fill(i), wf.fill(i) return self.GET(pf, wf) email = helpers.get_loggedin_email() if not email: return login().GET(i) create_petition(i, email) raise web.seeother("/%s" % i.pid)
def GET_edit(self, pid): user_email = helpers.get_loggedin_email() if is_author(user_email, pid): p = get_petition_by_id(pid) u = helpers.get_user_by_email(user_email) pf = forms.petitionform() pf.fill(userid=u.id, email=user_email, pid=p.id, ptitle=p.title, msg=p.description, tocongress=p.to_congress) wf = forms.wyrform() fill_user_details(wf) isdraft = is_draft(p) return render.petitionform(pf, wf, is_new=False, is_draft=isdraft) elif user_email: msg = "You don't have permissions to edit this petition." else: login_link = '<a href="/u/login">Login</a>' msg = 'Only author of this petition can edit it. %s if you are.' % login_link helpers.set_msg(msg) raise web.seeother('/%s' % pid)
def askforpasswd(user_id): useremail = helpers.get_loggedin_email() #if the current user is the owner of the petition and has not set the password r = db.select('users', where='id=$user_id AND email=$useremail AND password is NULL', vars=locals()) return bool(r)