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' 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, 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 save_contacts(email, contacts, provider): #Even if the user is not logged-in, but has an account with us, let him import contacts user_id = helpers.get_loggedin_userid() if not user_id: user = db.select('users', what='id', where='email=$email', vars=locals()) if user: user_id = user[0].id if user_id: for c in contacts: cname, cemail = c['name'], c['email'] vars = dict(user_id=user_id, uemail=email, cemail=cemail, cname=cname, provider=provider) e = db.select( 'contacts', where='user_id=$user_id and uemail=$uemail and cemail=$cemail', vars=vars) if not e: n = db.insert('contacts', seqname=False, **vars) elif cname: db.update( 'contacts', cname=cname, where= 'user_id=$user_id and uemail=$uemail and cemail=$cemail', vars=vars)
def save_contacts(email, contacts, provider): user_id = helpers.get_loggedin_userid() for c in contacts: cname, cemail = c['name'], c['email'] vars = dict(user_id=user_id, uemail=email, cemail=cemail, cname=cname, provider=provider) e = db.select('contacts', where='user_id=$user_id and uemail=$uemail and cemail=$cemail', vars=vars) if not e: n = db.insert('contacts', seqname=False, **vars) else: db.update('contacts', cname=cname, where='user_id=$user_id and uemail=$uemail and cemail=$cemail', vars=vars)
def save_contacts(email, contacts, provider): #Even if the user is not logged-in, but has an account with us, let him import contacts user_id = helpers.get_loggedin_userid() if not user_id: user = db.select('users', what='id', where='email=$email', vars=locals()) if user: user_id = user[0].id if user_id: for c in contacts: cname, cemail = c['name'], c['email'] vars = dict(user_id=user_id, uemail=email, cemail=cemail, cname=cname, provider=provider) e = db.select('contacts', where='user_id=$user_id and uemail=$uemail and cemail=$cemail', vars=vars) if not e: n = db.insert('contacts', seqname=False, **vars) elif cname: db.update('contacts', cname=cname, where='user_id=$user_id and uemail=$uemail and cemail=$cemail', vars=vars)
def GET(self, emailform=None, loadcontactsform=None): i = web.input() user_id = helpers.get_loggedin_userid() contacts = get_contacts(user_id) petition = db.select('petition', where='id=$i.pid', vars=locals())[0] petition.url = 'http://watchdog.net/c/%s' %(i.pid) if not emailform: emailform = forms.emailform subject='Share petition "%s"' % (petition.title) msg = render_plain.share_petition_mail(petition) emailform.fill(subject=subject, body=msg) current_providers = set(c.provider.lower() for c in contacts) all_providers = set(['google', 'yahoo']) remaining_providers = all_providers.difference(current_providers) remaining_providers = ' or '.join(p.title() for p in remaining_providers) if remaining_providers and not loadcontactsform: loadcontactsform = forms.loadcontactsform return render.share_petition(petition, emailform, contacts, remaining_providers, loadcontactsform)