Skip to content

Commit

Permalink
share my email checkbox. first and last name on same line in sign and…
Browse files Browse the repository at this point in the history
… new-petition forms. login screen after new-petition page.
  • Loading branch information
Simon Carstensen committed Sep 16, 2008
1 parent 345eed6 commit 73fee6f
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 65 deletions.
108 changes: 74 additions & 34 deletions petition.py
Expand Up @@ -13,6 +13,8 @@
'', 'redir',
'/', 'index',
'/new', 'new',
'/login', 'login',
'/signup', 'signup',
'/verify', 'checkID',
'/(.*)/share', 'share',
'/(.*)/signatories', 'signatories',
Expand Down Expand Up @@ -43,16 +45,6 @@ def GET(self):
msg, msg_type = helpers.get_delete_msg()
return render.petition_list(petitions, msg)

def save_petition(p):
p.pid = p.pid.replace(' ', '_')
tocongress = p.get('tocongress', 'off') == 'on'
email = helpers.get_loggedin_email()
u = helpers.get_user_by_email(email)
with db.transaction():
db.insert('petition', seqname=False, id=p.pid, title=p.ptitle, description=p.msg,
owner_id=u.id, to_congress=tocongress)
db.insert('signatory', user_id=u.id, share_with='A', petition_id=p.pid)

def fill_user_details(form, fillings=['email', 'name', 'contact']):
details = {}
email = helpers.get_loggedin_email() or helpers.get_unverified_email()
Expand Down Expand Up @@ -84,38 +76,79 @@ def send_to_congress(p, pform, wyrform):
wyr = write_your_rep()
return wyr.send_msg(p, wyrform, pform)

def create_petition(i, email):
tocongress = i.get('tocongress', 'off') == 'on'
if tocongress:
pform, wyrform = forms.petitionform(), forms.wyrform()
pform.fill(i), wyrform.fill(i)
sent_status = send_to_congress(i, pform, wyrform)
if not isinstance(sent_status, bool):
return sent_status

i.pid = i.pid.replace(' ', '_')
u = helpers.get_user_by_email(email)
with db.transaction():
db.insert('petition', seqname=False, id=i.pid, title=i.ptitle, description=i.msg,
owner_id=u.id, to_congress=tocongress)
db.insert('signatory', user_id=u.id, share_with='A', petition_id=i.pid)
msg = """Congratulations, you've created your petition.
Now sign and share it with all your friends."""
helpers.set_msg(msg)

class new:
@auth.require_login
def GET(self):
pform = forms.petitionform()
cform = forms.wyrform()
fill_user_details(pform)
email = helpers.get_loggedin_email() or helpers.get_unverified_email()
return render.petitionform(pform, cform)

@auth.require_login
def POST(self):
def POST(self, input=None):
from webapp import get_wyrform
i = web.input()
i = input or web.input()
tocongress = i.get('tocongress', 'off') == 'on'
pform = forms.petitionform()
wyrform = get_wyrform(i)
email = helpers.get_loggedin_email()
wyr_valid = (not(tocongress) or wyrform.validates(i))
if not pform.validates(i) or not wyr_valid:
return render.petitionform(pform, wyrform)

if tocongress:
sent_status = send_to_congress(i, pform, wyrform)
if not isinstance(sent_status, bool):
return sent_status
email = helpers.get_loggedin_email()
if not email:
return login().GET(i)

save_petition(i)
helpers.set_login_cookie(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' % i.pid)
create_petition(i, email)
raise web.seeother('/%s' % i.pid)

class login:
def GET(self, i):
lf, sf = forms.loginform(), forms.signupform()
pf, wf = forms.petitionform(), forms.wyrform()
pf.fill(i), wf.fill(i)
return render.petitionlogin(lf, sf, pf, wf)

def POST(self):
i = web.input()
lf, pf, wf = forms.loginform(), forms.petitionform(), forms.wyrform()
if not lf.validates(i):
sf, wf = forms.signupform()
lf.fill(i), pf.fill(i), wf.fill(i)
return render.petitionlogin(lf, sf, pf, wf)
create_petition(i, i.useremail)
raise web.seeother('/%s' % i.pid)

class signup:
def POST(self):
i = web.input()
sf = forms.signupform()
if not sf.validates(i):
lf, pf, wf = forms.loginform(), forms.petitionform(), forms.wyrform()
sf.fill(i), pf.fill(i), wf.fill(i)
return render.petitionlogin(lf, sf, pf, wf)
user = auth.new_user( i.fname, i.lname, i.email, i.password)
helpers.set_login_cookie(i.email)
create_petition(i, i.email)
raise web.seeother('/%s' % i.pid)

def askforpasswd(user_id):
useremail = helpers.get_loggedin_email()
Expand All @@ -136,9 +169,10 @@ def save_signature(forminput, pid):
user = web.storage(id=user_id, lname=forminput.lname, fname=forminput.fname, email=forminput.email)

signed = db.select('signatory', where='petition_id=$pid AND user_id=$user.id', vars=locals())
share_with = (forminput.get('share_with', 'off') == 'on' and 'N') or 'A'
if not signed:
signature = dict(petition_id=pid, user_id=user.id,
share_with='N', comment=forminput.comment)
share_with=share_with, comment=forminput.comment)
db.insert('signatory', **signature)
helpers.set_msg('Thanks for your signing! Why don\'t you tell your friends about it now?')
helpers.unverified_login(user.email)
Expand All @@ -163,17 +197,20 @@ def is_author(email, pid):
else:
return user_id == owner_id

def get_signs(pid):
return db.select(['signatory', 'users'],
what='users.fname, users.lname, users.email, '
'signatory.share_with, signatory.comment, '
'signatory.signed',
where='petition_id=$pid AND user_id=users.id',
order='signed desc',
vars=locals())

class signatories:
def GET(self, pid):
user_email = helpers.get_loggedin_email()
ptitle = db.select('petition', what='title', where='id=$pid', vars=locals())[0].title
signs = db.select(['signatory', 'users'],
what='users.fname, users.lname, users.email, '
'signatory.share_with, signatory.comment, '
'signatory.signed',
where='petition_id=$pid AND user_id=users.id',
order='signed desc',
vars=locals()).list()
signs = get_signs(pid).list()
return render.signature_list(pid, ptitle, signs, is_author(user_email, pid))

class petition:
Expand Down Expand Up @@ -270,10 +307,13 @@ def POST_password(self, pid):
def POST_sign(self, pid):
form = forms.signform()
i = web.input()
email = helpers.get_loggedin_email() or helpers.get_unverified_email()
if email:
i.email = email
if form.validates(i):
user = save_signature(i, pid)
sendmail_to_signatory(user, pid)
return web.seeother('/%s/share' % pid)
raise web.seeother('/%s/share' % pid)
else:
return self.GET(pid, signform=form)

Expand Down
12 changes: 6 additions & 6 deletions static/css/style.css
Expand Up @@ -53,9 +53,9 @@ img { border:none }


/* form elements */
textarea { background-color: #d9eefa; border: 1px solid #83b3d0; color: #999; font-size:14px; font-family:"Georgia"; padding: 5px 6px 5px 6px; margin: 10px 4px 0px 0px; }
textarea { background-color: #d9eefa; border: 1px solid #83b3d0; color: #023; font-size:14px; font-family:"Georgia"; padding: 5px 6px 5px 6px; margin: 10px 4px 0px 0px; }
textarea:focus { background-color: #f0faff; border: 1px solid #83b3d0; color: #EE4400; }
input { background-color: #d9eefa; border: 1px solid #83b3d0; color: #999; font-size:14px; font-family:"Georgia"; padding: 5px 6px 5px 6px; margin-right: 4px; }
input { background-color: #d9eefa; border: 1px solid #83b3d0; color: #023; font-size:14px; font-family:"Georgia"; padding: 5px 6px 5px 6px; margin-right: 4px; }
input:focus { color: #EE4400; background-color: #f0faff; }
input.personalize { background-color: #002233; border: 1px solid #0f5b89; color: #FFF399; font-size:14px; font-family:"Georgia"; padding: 5px 6px 5px 6px; margin-right: 4px; width: 152px; font-size:12px; line-height:20px; font-family:Arial, Helvetica, sans-serif; }
input.personalize:focus { background-color: #0f5b89; border: 1px solid #EE4400; }
Expand All @@ -69,8 +69,8 @@ input.highlight:focus { background-color: #fdf6c5; border: 1px solid #EE4400; }
/* fieldsets */
fieldset { width: 510px; border: 1px solid #ccc; background: #F5F5FD; padding: 0 2em 2em 2em; margin: 0 0 2em 0; }
legend { font-weight: bold; font-size: 1.2em; padding: 0 0.5em; color:#EE4400; }
fieldset label { display: block; font-size: 0.95em; margin: 1em 0 0 0; }
fieldset input { padding: 0.3em; font-weight: bold; font-size: 1.1em; max-width: 500px; margin: 0; }
fieldset label { display: block; font-size: 0.95em; margin: 1em 0 0 0; color: #023; }
fieldset input { padding: 0.3em; font-weight: bold; font-size: 1.1em; max-width: 500px; margin: 0; color: #023; }
fieldset textarea { font-size: 1.1em; width: 505px; padding: 0.2em; height: 200px; margin: 0}
fieldset th { vertical-align: middle; }
fieldset { vertical-align: middle; }
Expand Down Expand Up @@ -233,8 +233,8 @@ h2.repred { color: #EE4400; margin-bottom: 6px; }
#loadcontacts #email { margin-bottom: 0.5em;}
#loadcontacts #provider span { display: block; }

.login { padding-right: 1.5em; border-right: 1px solid #ccc; }
.signup { padding-left: 1.5em; }
.login { padding-right: 2em; border-right: 1px solid #ccc; }
.signup { padding-left: 2em; }
.login th, .signup th { font-weight: normal; }
.login fieldset, .signup fieldset { width: 250px; }
.login input, .signup input { width: 250px; }
Expand Down
18 changes: 15 additions & 3 deletions static/js/petition.js
Expand Up @@ -29,16 +29,28 @@ $('#pid').change( function checkID(){
});
});

$('#tocongress').click(function() {
var tocongress_click = function() {
if ($('#tocongress:checked').val()) {
$('#tocongressform').show();
$('#prefix').focus();
$('#tocongresscheck').css('background-color', '#ccebff');
$('#tocongresscheck').css('background-color', '#beb');
} else {
$('#tocongressform').hide()
$('#tocongresscheck').css('background-color', '#ffc');
}
});
}
$('#tocongress').click(tocongress_click);
tocongress_click();

var share_with_click = function() {
if ($('#share_with:checked').val()) {
$('#share_with_container').css('background-color', '#beb');
} else {
$('#share_with_container').css('background-color', '#ffc');
}
}
$('#share_with').click(share_with_click);
share_with_click();

$('#ptitle').focus();
if ($('#tocongress:checked').val()) {
Expand Down
37 changes: 24 additions & 13 deletions templates/petition.html
Expand Up @@ -2,21 +2,26 @@

$var title: $p.title

<script type="text/javascript" src="/static/js/petition.js"></script>

<style>
fieldset#signpetition input {
width: 500px;
}
fieldset#signpetition {
margin-top: 2em;
}
fieldset#signpetition input { width: 500px; }
fieldset#signpetition { margin-top: 2em; }
#text fieldset td { padding: 0; }
#text fieldset #fname { margin-right: 7px; }
#text fieldset #fname { width: 190px; }
#text fieldset #lname { width: 290px; }
#text fieldset #share_with { width: 13px; }
#text fieldset #share_with_container { margin-top: 1em; background-color: #ffc; width: 23em;}
#text fieldset #share_with_container label { display: inline; }
</style>

$if msg:
$var msg: $:msg

<h2>$p.title</h2>

<p>$:format(p.description)</p>
$:format(p.description)

<div id="upperbar">
$if p.signatory_count == 0:
Expand All @@ -27,7 +32,6 @@ <h2>Be the first to sign this petition!</h2>
$else:
$ ppl = 'people</a></strong> have'
<h2> <strong><a href='/c/$p.id/signatories'>$p.signatory_count $:ppl signed this petition. </h2>

<div id="uppermenu">
<a href="/c/$p.id/share">Share</a>&nbsp;
$if isauthor:
Expand All @@ -42,14 +46,21 @@ <h2> <strong><a href='/c/$p.id/signatories'>$p.signatory_count $:ppl signed this
$if not signform.valid: <p class="error">Please try again after fixing the errors highlighted below:</p>
<fieldset id="signpetition">
<legend>Sign this petition</legend>
<label for="fname">First name</label>
$:signform.fname.render()
<label for="lname">Last name</label>
$:signform.lname.render()
<table>
<tr><td><label for="fname">First name</label>$:signform.fname.render()</td>
<td><label for="lname">Last name</label>$:signform.lname.render()</td></tr>
</table>
<label for="email">Email</label>
$:signform.email.render()
$if useremail:
<div><strong>$useremail</strong></div>
$else:
$:signform.email.render()
<label for="comment">Comment</label>
$:signform.comment.render()
<div id="share_with_container">
$:signform.share_with.render()
<label for="share_with">Do not share my email with the author of this petition</label>
</div>
</fieldset>
<p><button type="submit">Sign this petition</button></p>
</form>
Expand Down

0 comments on commit 73fee6f

Please sign in to comment.