Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 def GET(self, i=None, wf=None):
     i = i or web.input()
     lf, sf = forms.loginform(), forms.signupform()
     pf, wf = forms.petitionform(), (wf or forms.wyrform())
     pf.fill(i), wf.fill(i)
     is_draft = "save" in i
     return render.petitionlogin(lf, sf, pf, wf, is_draft=is_draft)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 def GET(self, i=None, wf=None):
     i = i or web.input()
     lf, sf = forms.loginform(), forms.signupform()
     pf, wf = forms.petitionform(), (wf or forms.wyrform())
     pf.fill(i), wf.fill(i)
     is_draft = 'save' in i
     return render.petitionlogin(lf, sf, pf, wf, is_draft=is_draft)
Ejemplo n.º 5
0
 def POST(self):
     i = web.input()
     lf, wf =  forms.loginform(), forms.wyrform()
     if not lf.validates(i):
         pf, sf = forms.petitionform(), forms.signupform()
         lf.fill(i), pf.fill(i), wf.fill(i)
         return render.petitionlogin(lf, sf, pf, wf)
         
     try:    
         create_petition(i, i.useremail, wf)
     except CaptchaException:
         msg, msg_type = helpers.get_delete_msg()
         pf= forms.petitionform()
         pf.fill(i)
         return render.petitionform(pf, wf, msg)    
         
     raise web.seeother('/%s' % i.pid)
Ejemplo n.º 6
0
 def POST(self):
     i = web.input()
     sf, wf = forms.signupform(), forms.wyrform()
     if not sf.validates(i):
         lf, pf = forms.loginform(), forms.petitionform()
         sf.fill(i), pf.fill(i), wf.fill(i)
         return render.petitionlogin(lf, sf, pf, wf)
     user = auth.new_user(i.email, i.password)
     helpers.set_login_cookie(i.email)
     try:
         create_petition(i, i.email, wf)
     except CaptchaException:
         msg, msg_type = helpers.get_delete_msg()
         pf = forms.petitionform()
         pf.fill(i)
         return render.petitionform(pf, wf, msg)
         
     raise web.seeother('/%s' % i.pid)
Ejemplo n.º 7
0
 def GET(self, pf=None, wf=None):
     pf = pf or forms.petitionform()
     if not wf:
         # create a new form and initialize with current user details
         wf = forms.wyrform()
         u = helpers.get_user()
         u and fill_user_details(wf, u)
     captcha_html = wyrapp.prepare_for_captcha(wf)
     msg, msg_type = helpers.get_delete_msg()
     return render.petitionform(pf, wf, captchas=captcha_html, msg=msg)
Ejemplo n.º 8
0
 def POST(self):
     i = web.input()
     lf, wf = forms.loginform(), forms.wyrform()
     if not lf.validates(i):
         pf, sf = forms.petitionform(), forms.signupform()
         lf.fill(i), pf.fill(i), wf.fill(i)
         is_draft = "save" in i
         return render.petitionlogin(lf, sf, pf, wf, is_draft=is_draft)
     create_petition(i, i.useremail)
     raise web.seeother("/%s" % i.pid)
Ejemplo n.º 9
0
 def POST(self):
     i = web.input()
     lf, wf = forms.loginform(), forms.wyrform()
     if not lf.validates(i):
         pf, sf = forms.petitionform(), forms.signupform()
         lf.fill(i), pf.fill(i), wf.fill(i)
         is_draft = 'save' in i
         return render.petitionlogin(lf, sf, pf, wf, is_draft=is_draft)
     create_petition(i, i.useremail)
     raise web.seeother('/%s' % i.pid)
Ejemplo n.º 10
0
 def GET(self, pf=None, wf=None):
     pf = pf or forms.petitionform()
     if not wf:
         #create a new form and initialize with current user details
         wf = forms.wyrform()
         u = helpers.get_user()
         u and fill_user_details(wf, u)
     captcha_html = wyrapp.prepare_for_captcha(wf)
     msg, msg_type = helpers.get_delete_msg()
     return render.petitionform(pf, wf, captchas=captcha_html, msg=msg)
Ejemplo n.º 11
0
 def POST(self):
     i = web.input()
     sf, wf = forms.signupform(), forms.wyrform()
     if not sf.validates(i):
         lf, pf = forms.loginform(), forms.petitionform()
         sf.fill(i), pf.fill(i), wf.fill(i)
         return render.petitionlogin(lf, sf, pf, wf)
     user = auth.new_user(i.email, i.password)
     helpers.set_login_cookie(i.email)
     create_petition(i, i.email)
     raise web.seeother('/%s' % i.pid)
Ejemplo n.º 12
0
 def POST(self):
     i = web.input()
     sf, wf = forms.signupform(), forms.wyrform()
     if not sf.validates(i):
         lf, pf = forms.loginform(), forms.petitionform()
         sf.fill(i), pf.fill(i), wf.fill(i)
         return render.petitionlogin(lf, sf, pf, wf)
     user = auth.new_user(i.email, i.password)
     helpers.set_login_cookie(i.email)
     create_petition(i, i.email)
     raise web.seeother("/%s" % i.pid)
Ejemplo n.º 13
0
def send_to_congress(i, wyrform, signid=None):
    from utils.writerep import write_your_rep
    
    pform, wyrform = forms.petitionform(), (wyrform or forms.wyrform())
    pform.fill(i), wyrform.fill(i)
    wyr = write_your_rep()
    wyr.set_pol(i)
    if not signid: signid = get_signid(i.pid)
    wyr.set_msg_id(signid, petition=True)
    msg_sent = wyr.send_msg(i, wyrform, pform)
    sent_status = msg_sent and 'S' or 'D'   # Sent or Due for sending
    db.update('signatory', where='id=$signid', sent_to_congress=sent_status, vars=locals())
Ejemplo n.º 14
0
 def POST(self):
     p = web.input()
     pform = forms.petitionform()
     auth.assert_verified(p.email)
     if pform.validates(p):
         save_petition(p)
         helpers.set_login_cookie(p.email)
         msg = """Congratulations, you've created your petition. 
                 Now sign and share it with all your friends."""
         helpers.set_msg(msg)
         return web.seeother('/%s' % p.pid)
     else:
         return render.petitionform(pform)
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
 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)
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
 def GET(self):
     pform = forms.petitionform()
     fill_user_details(pform, 'email')
     return render.petitionform(pform)