Exemple #1
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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
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)
Exemple #7
0
    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)
Exemple #8
0
    def POST_sign(self, pid):
        i = web.input()
        sf = forms.signform()
        tocongress = to_congress(pid)
        p = get_petition_by_id(pid)

        is_new = lambda sid: not isinstance(sid, str)
        get_new = lambda sid: int(web.lstrips(sid, 'old_'))
        if tocongress:
            i.pid, i.ptitle, i.msg = pid, p.title, p.description
            wf = forms.wyrform()
            captcha_needed = require_captcha(i)
            wyr_valid = wf.validates(i) and not captcha_needed
            if captcha_needed:
                wf.valid, wf.note = False, 'Please fill the captcha below'
        else:
            wf, wyr_valid = None, True

        if sf.validates(i) and wyr_valid:
            uid = auth.assert_login(i)
            signid = save_signature(i, pid, uid)
            if is_new(signid):
                user = helpers.get_user_by_id(uid)
                sendmail_to_signatory(user, pid)
            else:
                signid = get_new(signid)
            if tocongress: send_to_congress(uid, i, signid)
            query = urllib.urlencode(dict(url='/c/%s' % pid, title=p.title))
            raise web.seeother('/share?%s' % query, absolute=True)
        else:
            return self.GET(pid, sf=sf, wf=wf)
Exemple #9
0
    def POST_sign(self, pid):
        i = web.input()
        sf = forms.signform()
        tocongress = to_congress(pid)
        p = get_petition_by_id(pid)

        is_new = lambda sid: not isinstance(sid, str)
        get_new = lambda sid: int(web.lstrips(sid, "old_"))
        if tocongress:
            i.pid, i.ptitle, i.msg = pid, p.title, p.description
            wf = forms.wyrform()
            captcha_needed = require_captcha(i)
            wyr_valid = wf.validates(i) and not captcha_needed
            if captcha_needed:
                wf.valid, wf.note = False, "Please fill the captcha below"
        else:
            wf, wyr_valid = None, True

        if sf.validates(i) and wyr_valid:
            uid = auth.assert_login(i)
            signid = save_signature(i, pid, uid)
            if is_new(signid):
                user = helpers.get_user_by_id(uid)
                sendmail_to_signatory(user, pid)
            else:
                signid = get_new(signid)
            if tocongress:
                send_to_congress(uid, i, signid)
            query = urllib.urlencode(dict(url="/c/%s" % pid, title=p.title))
            raise web.seeother("/share?%s" % query, absolute=True)
        else:
            return self.GET(pid, sf=sf, wf=wf)
Exemple #10
0
    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)
Exemple #11
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)
Exemple #12
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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
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)
Exemple #17
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())
Exemple #18
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)
Exemple #19
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)
Exemple #20
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)
Exemple #21
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)
Exemple #22
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)
Exemple #23
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)
Exemple #24
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)
Exemple #25
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)
Exemple #26
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)
Exemple #27
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)