home » zplus/freepost.git
Author zPlus <zplus@peers.community> 2018-07-26 14:18:41
Committer zPlus <zplus@peers.community> 2018-07-26 14:18:41
Commit 1dd7699 (patch)
Tree 8b3f993
Parent(s)

Change default charset of mysql connection from latin-1 to utf-8. modified: freepost/__init__.py modified: freepost/database.py


commits diff: c0b3279..1dd7699
2 files changed, 35 insertions, 34 deletionsdownload


Diffstat
-rwxr-xr-x freepost/__init__.py 68
-rw-r--r-- freepost/database.py 1

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+34/-34 M   freepost/__init__.py
index 01b2c0c..d30ca8e
old size: 25K - new size: 25K
@@ -183,8 +183,8 @@ def login_check ():
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,8 +226,8 @@ def register_new_account ():
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,8 +289,8 @@ def password_reset_send_code ():
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,10 +348,10 @@ def validate_new_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,8 +404,8 @@ def update_user_settings ():
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,7 +509,7 @@ def new_comment (hash_id):
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,10 +548,10 @@ def edit_post_check (hash_id):
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,7 +584,7 @@ def edit_comment_check (hash_id):
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,30 +609,30 @@ def submit_check ():
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,7 +672,7 @@ def reply_check (hash_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,15 +699,15 @@ def vote ():
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,7 +722,7 @@ def vote ():
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,15 +737,15 @@ def vote ():
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,7 +760,7 @@ def vote ():
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,10 +781,10 @@ def search ():
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,7 +796,7 @@ def search ():
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

+1/-0 M   freepost/database.py
index ed49217..64aeb1a
old size: 18K - new size: 18K
@@ -6,6 +6,7 @@ db = MySQLdb.connect (
6 6 host = settings['mysql']['host'],
7 7 port = settings['mysql']['port'],
8 8 db = settings['mysql']['schema'],
9 + charset = settings['mysql']['charset'],
9 10 user = settings['mysql']['username'],
10 11 passwd = settings['mysql']['password'],
11 12 autocommit = True)