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 create_petition(i, email): tocongress = i.get("tocongress", "off") == "on" i.pid = i.pid.replace(" ", "-") u = helpers.get_user_by_email(email) is_draft = "save" in i published = None if is_draft else datetime.now() try: db.insert( "petition", seqname=False, id=i.pid, title=i.ptitle, created=datetime.now(), published=published, description=i.msg, owner_id=u.id, to_congress=tocongress, ) except: return if is_draft: msg = """Petition saved for publishing later.""" helpers.set_msg(msg) else: create_first_signature(i, u.email)
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, 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 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 create_first_signature(i, email): tocongress = i.get('tocongress', 'off') == 'on' i.pid = i.pid.replace(' ', '-') u = helpers.get_user_by_email(email) signid = save_signature(i, i.pid, u.id) if tocongress: send_to_congress(u.id, i, signid) sendmail_to_signatory(u, i.pid) msg = """Congratulations, you've created your petition. Now share it with all your friends.""" helpers.set_msg(msg)
def create_first_signature(i, email): tocongress = i.get("tocongress", "off") == "on" i.pid = i.pid.replace(" ", "-") u = helpers.get_user_by_email(email) signid = save_signature(i, i.pid, u.id) if tocongress: send_to_congress(u.id, i, signid) sendmail_to_signatory(u, i.pid) msg = """Congratulations, you've created your petition. Now share it with all your friends.""" helpers.set_msg(msg)
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 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(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_unsign(self, pid): i = web.input() user = helpers.get_user_by_email(i.email) if user: signatory = db.select('signatory', where='petition_id=$pid and user_id=$user.id', vars=locals()) if not (user and signatory and auth.check_secret_token(i.email, i.token)): msg = "Invalid token or there is no signature for this petition with this email." msg_type = 'error' else: msg = render_plain.confirm_unsign(pid, user.id) msg_type = '' helpers.set_msg(msg, msg_type) raise web.seeother('/%s' % pid)
def create_petition(i, email, wyrform): tocongress = i.get('tocongress', 'off') == 'on' i.pid = i.pid.replace(' ', '_') u = helpers.get_user_by_email(email) try: db.insert('petition', seqname=False, id=i.pid, title=i.ptitle, description=i.msg, owner_id=u.id, to_congress=tocongress) except: return signid = save_signature(i, i.pid, u.id, tocongress) if tocongress and captcha_to_be_filled(i): wyrform.fill(signid=signid) if tocongress: send_to_congress(i, wyrform, signid) msg = """Congratulations, you've created your petition. Now sign and share it with all your friends.""" helpers.set_msg(msg)
def GET_unsign(self, pid): i = web.input() user = helpers.get_user_by_email(i.email) if user: where = "petition_id=$pid and user_id=$user.id and deleted is null" signatory = db.select("signatory", where=where, vars=locals()) valid_token = auth.check_secret_token(i.get("email", ""), i.get("token", "@")) if not (user and signatory and valid_token): msg = "Invalid token or there is no signature for this petition with this email." msg_type = "error" else: msg = str(render_plain.confirm_unsign(pid, user.id)) msg_type = "" helpers.set_msg(msg, msg_type) raise web.seeother("/%s" % pid)
def GET_unsign(self, pid): i = web.input() user = helpers.get_user_by_email(i.email) if user: where = 'petition_id=$pid and user_id=$user.id and deleted is null' signatory = db.select('signatory', where=where, vars=locals()) valid_token = auth.check_secret_token(i.get('email', ''), i.get('token', '@')) if not (user and signatory and valid_token): msg = "Invalid token or there is no signature for this petition with this email." msg_type = 'error' else: msg = str(render_plain.confirm_unsign(pid, user.id)) msg_type = '' helpers.set_msg(msg, msg_type) 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) 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 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 create_petition(i, email): tocongress = i.get('tocongress', 'off') == 'on' i.pid = i.pid.replace(' ', '-') u = helpers.get_user_by_email(email) is_draft = 'save' in i published = None if is_draft else datetime.now() try: db.insert('petition', seqname=False, id=i.pid, title=i.ptitle, created=datetime.now(), published=published, description=i.msg, owner_id=u.id, to_congress=tocongress) except: return if is_draft: msg = """Petition saved for publishing later.""" helpers.set_msg(msg) else: create_first_signature(i, u.email)
def is_signatory(email, pid): user = email and helpers.get_user_by_email(email) where = 'petition_id=$pid and user_id=$user.id and deleted is null' return user and bool(db.select('signatory', where=where, vars=locals()))
def is_signatory(email, pid): user = email and helpers.get_user_by_email(email) where = "petition_id=$pid and user_id=$user.id and deleted is null" return user and bool(db.select("signatory", where=where, vars=locals()))
def is_author(email, pid): user = email and helpers.get_user_by_email(email) where = "id=$pid and owner_id=$user.id and deleted is null" return user and bool(db.select("petition", where=where, vars=locals()))
def is_author(email, pid): user = email and helpers.get_user_by_email(email) where = 'id=$pid and owner_id=$user.id and deleted is null' return user and bool(db.select('petition', where=where, vars=locals()))