예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #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)
         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)
예제 #10
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)
예제 #11
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)
예제 #12
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)
예제 #13
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)
예제 #14
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)
예제 #15
0
 def GET(self):
     pform = forms.petitionform()
     fill_user_details(pform, 'email')
     return render.petitionform(pform)