183
|
183
|
|
Check login form.
|
184
|
184
|
|
"""
|
185
|
185
|
|
|
186
|
|
- |
username = request.forms.get ('username')
|
187
|
|
- |
password = request.forms.get ('password')
|
|
186
|
+ |
username = request.forms.getunicode ('username')
|
|
187
|
+ |
password = request.forms.getunicode ('password')
|
188
|
188
|
|
remember = 'remember' in request.forms
|
189
|
189
|
|
|
190
|
190
|
|
if not username or not password:
|
226
|
226
|
|
Check form for creating new account.
|
227
|
227
|
|
"""
|
228
|
228
|
|
|
229
|
|
- |
username = request.forms.get ('username')
|
230
|
|
- |
password = request.forms.get ('password')
|
|
229
|
+ |
username = request.forms.getunicode ('username')
|
|
230
|
+ |
password = request.forms.getunicode ('password')
|
231
|
231
|
|
|
232
|
232
|
|
# Normalize username
|
233
|
233
|
|
username = username.strip ()
|
289
|
289
|
|
code via email.
|
290
|
290
|
|
"""
|
291
|
291
|
|
|
292
|
|
- |
username = request.forms.get ('username')
|
293
|
|
- |
email = request.forms.get ('email')
|
|
292
|
+ |
username = request.forms.getunicode ('username')
|
|
293
|
+ |
email = request.forms.getunicode ('email')
|
294
|
294
|
|
|
295
|
295
|
|
if not username or not email:
|
296
|
296
|
|
redirect (application.get_url ('change_password'))
|
348
|
348
|
|
is OK change the user password.
|
349
|
349
|
|
"""
|
350
|
350
|
|
|
351
|
|
- |
username = request.forms.get ('username')
|
352
|
|
- |
email = request.forms.get ('email')
|
353
|
|
- |
password = request.forms.get ('password')
|
354
|
|
- |
secret_token = request.forms.get ('token')
|
|
351
|
+ |
username = request.forms.getunicode ('username')
|
|
352
|
+ |
email = request.forms.getunicode ('email')
|
|
353
|
+ |
password = request.forms.getunicode ('password')
|
|
354
|
+ |
secret_token = request.forms.getunicode ('token')
|
355
|
355
|
|
|
356
|
356
|
|
# We must have all fields
|
357
|
357
|
|
if not username or not email or not password or not secret_token:
|
404
|
404
|
|
|
405
|
405
|
|
user = session.user ()
|
406
|
406
|
|
|
407
|
|
- |
about = request.forms.get ('about')
|
408
|
|
- |
email = request.forms.get ('email')
|
|
407
|
+ |
about = request.forms.getunicode ('about')
|
|
408
|
+ |
email = request.forms.getunicode ('email')
|
409
|
409
|
|
|
410
|
410
|
|
if about is None or email is None:
|
411
|
411
|
|
redirect (application.get_url ('user_settings'))
|
509
|
509
|
|
user = session.user ()
|
510
|
510
|
|
|
511
|
511
|
|
# The comment text
|
512
|
|
- |
comment = request.forms.get ('new_comment').strip ()
|
|
512
|
+ |
comment = request.forms.getunicode ('new_comment').strip ()
|
513
|
513
|
|
|
514
|
514
|
|
# Empty comment
|
515
|
515
|
|
if len (comment) == 0:
|
548
|
548
|
|
redirect (application.get_url ('homepage'))
|
549
|
549
|
|
|
550
|
550
|
|
# MUST have a title. If empty, use original title
|
551
|
|
- |
title = request.forms.get ('title').strip ()
|
|
551
|
+ |
title = request.forms.getunicode ('title').strip ()
|
552
|
552
|
|
if len (title) == 0: title = post['title']
|
553
|
|
- |
link = request.forms.get ('link').strip () if 'link' in request.forms else ''
|
554
|
|
- |
text = request.forms.get ('text').strip () if 'text' in request.forms else ''
|
|
553
|
+ |
link = request.forms.getunicode ('link').strip () if 'link' in request.forms else ''
|
|
554
|
+ |
text = request.forms.getunicode ('text').strip () if 'text' in request.forms else ''
|
555
|
555
|
|
|
556
|
556
|
|
# If there is a URL, make sure it has a "scheme"
|
557
|
557
|
|
if len (link) > 0 and urlparse (link).scheme == '':
|
584
|
584
|
|
if comment['userId'] != user['id']:
|
585
|
585
|
|
redirect (application.get_url ('homepage'))
|
586
|
586
|
|
|
587
|
|
- |
text = request.forms.get ('text').strip () if 'text' in request.forms else ''
|
|
587
|
+ |
text = request.forms.getunicode ('text').strip () if 'text' in request.forms else ''
|
588
|
588
|
|
|
589
|
589
|
|
# Only update if the text is not empty
|
590
|
590
|
|
if len (text) > 0:
|
609
|
609
|
|
"""
|
610
|
610
|
|
|
611
|
611
|
|
# Somebody sent a <form> without a title???
|
612
|
|
- |
if not request.forms.get ('title'):
|
|
612
|
+ |
if not request.forms.getunicode ('title'):
|
613
|
613
|
|
abort ()
|
614
|
614
|
|
|
615
|
615
|
|
user = session.user ()
|
616
|
616
|
|
|
617
|
617
|
|
# Retrieve title
|
618
|
|
- |
title = request.forms.get ('title').strip ()
|
|
618
|
+ |
title = request.forms.getunicode ('title').strip ()
|
619
|
619
|
|
|
620
|
620
|
|
# Bad title?
|
621
|
621
|
|
if len (title) == 0:
|
622
|
622
|
|
return template ('submit.html', flash='Title is missing.')
|
623
|
623
|
|
|
624
|
624
|
|
# Retrieve link
|
625
|
|
- |
link = request.forms.get ('link').strip ()
|
|
625
|
+ |
link = request.forms.getunicode ('link').strip ()
|
626
|
626
|
|
|
627
|
627
|
|
# If there is a URL, make sure it has a "scheme"
|
628
|
628
|
|
if len (link) > 0 and urlparse (link).scheme == '':
|
629
|
629
|
|
link = 'http://' + link
|
630
|
630
|
|
|
631
|
631
|
|
# Retrieve topics
|
632
|
|
- |
topics = request.forms.get ('topics')
|
|
632
|
+ |
topics = request.forms.getunicode ('topics')
|
633
|
633
|
|
|
634
|
634
|
|
# Retrieve text
|
635
|
|
- |
text = request.forms.get ('text')
|
|
635
|
+ |
text = request.forms.getunicode ('text')
|
636
|
636
|
|
|
637
|
637
|
|
# Add the new post
|
638
|
638
|
|
post_hash_id = database.new_post (title, link, text, user['id'])
|
672
|
672
|
|
comment = database.get_comment (hash_id)
|
673
|
673
|
|
|
674
|
674
|
|
# The text of the reply
|
675
|
|
- |
text = request.forms.get ('text').strip ()
|
|
675
|
+ |
text = request.forms.getunicode ('text').strip ()
|
676
|
676
|
|
|
677
|
677
|
|
# Empty comment. Redirect to parent post
|
678
|
678
|
|
if len (text) == 0:
|
699
|
699
|
|
user = session.user ()
|
700
|
700
|
|
|
701
|
701
|
|
# Vote a post
|
702
|
|
- |
if request.forms.get ('target') == 'post':
|
|
702
|
+ |
if request.forms.getunicode ('target') == 'post':
|
703
|
703
|
|
# Retrieve the post
|
704
|
|
- |
post = database.get_post (request.forms.get ('post'), user['id'])
|
|
704
|
+ |
post = database.get_post (request.forms.getunicode ('post'), user['id'])
|
705
|
705
|
|
|
706
|
706
|
|
if not post:
|
707
|
707
|
|
return
|
708
|
708
|
|
|
709
|
709
|
|
# If user clicked the "upvote" button...
|
710
|
|
- |
if request.forms.get ('updown') == 'up':
|
|
710
|
+ |
if request.forms.getunicode ('updown') == 'up':
|
711
|
711
|
|
# If user has upvoted this post before...
|
712
|
712
|
|
if post['user_vote'] == 1:
|
713
|
713
|
|
# Remove +1
|
722
|
722
|
|
database.vote_post (post['id'], user['id'], +1)
|
723
|
723
|
|
|
724
|
724
|
|
# If user clicked the "downvote" button...
|
725
|
|
- |
if request.forms.get ('updown') == 'down':
|
|
725
|
+ |
if request.forms.getunicode ('updown') == 'down':
|
726
|
726
|
|
# If user has downvoted this post before...
|
727
|
727
|
|
if post['user_vote'] == -1:
|
728
|
728
|
|
# Remove -1
|
737
|
737
|
|
database.vote_post (post['id'], user['id'], -1)
|
738
|
738
|
|
|
739
|
739
|
|
# Vote a comment
|
740
|
|
- |
if request.forms.get ('target') == 'comment':
|
|
740
|
+ |
if request.forms.getunicode ('target') == 'comment':
|
741
|
741
|
|
# Retrieve the comment
|
742
|
|
- |
comment = database.get_comment (request.forms.get ('comment'), user['id'])
|
|
742
|
+ |
comment = database.get_comment (request.forms.getunicode ('comment'), user['id'])
|
743
|
743
|
|
|
744
|
744
|
|
if not comment:
|
745
|
745
|
|
return
|
746
|
746
|
|
|
747
|
747
|
|
# If user clicked the "upvote" button...
|
748
|
|
- |
if request.forms.get ('updown') == 'up':
|
|
748
|
+ |
if request.forms.getunicode ('updown') == 'up':
|
749
|
749
|
|
# If user has upvoted this comment before...
|
750
|
750
|
|
if comment['user_vote'] == 1:
|
751
|
751
|
|
# Remove +1
|
760
|
760
|
|
database.vote_comment (comment['id'], user['id'], +1)
|
761
|
761
|
|
|
762
|
762
|
|
# If user clicked the "downvote" button...
|
763
|
|
- |
if request.forms.get ('updown') == 'down':
|
|
763
|
+ |
if request.forms.getunicode ('updown') == 'down':
|
764
|
764
|
|
# If user has downvoted this comment before...
|
765
|
765
|
|
if comment['user_vote'] == -1:
|
766
|
766
|
|
# Remove -1
|
781
|
781
|
|
"""
|
782
|
782
|
|
|
783
|
783
|
|
# Get the search query
|
784
|
|
- |
query = request.query.get ('q')
|
|
784
|
+ |
query = request.query.getunicode ('q')
|
785
|
785
|
|
|
786
|
786
|
|
# Get the offset
|
787
|
|
- |
page = int (request.query.get ('page') or 0)
|
|
787
|
+ |
page = int (request.query.getunicode ('page') or 0)
|
788
|
788
|
|
|
789
|
789
|
|
if page < 0:
|
790
|
790
|
|
return "Page cannot be less than zero."
|
796
|
796
|
|
page -= 1
|
797
|
797
|
|
|
798
|
798
|
|
# Results order
|
799
|
|
- |
sort = request.query.get ('sort')
|
|
799
|
+ |
sort = request.query.getunicode ('sort')
|
800
|
800
|
|
if sort not in [ 'newest', 'points' ]:
|
801
|
801
|
|
sort = 'newest'
|
802
|
802
|
|
|