예제 #1
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)
예제 #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, 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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #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)
예제 #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)
         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)
예제 #9
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)