diff --git a/freepost/__init__.py b/freepost/__init__.py index 01b2c0c..d30ca8e 100755 --- a/freepost/__init__.py +++ b/freepost/__init__.py @@ -183,8 +183,8 @@ def login_check (): Check login form. """ - username = request.forms.get ('username') - password = request.forms.get ('password') + username = request.forms.getunicode ('username') + password = request.forms.getunicode ('password') remember = 'remember' in request.forms if not username or not password: @@ -226,8 +226,8 @@ def register_new_account (): Check form for creating new account. """ - username = request.forms.get ('username') - password = request.forms.get ('password') + username = request.forms.getunicode ('username') + password = request.forms.getunicode ('password') # Normalize username username = username.strip () @@ -289,8 +289,8 @@ def password_reset_send_code (): code via email. """ - username = request.forms.get ('username') - email = request.forms.get ('email') + username = request.forms.getunicode ('username') + email = request.forms.getunicode ('email') if not username or not email: redirect (application.get_url ('change_password')) @@ -348,10 +348,10 @@ def validate_new_password (): is OK change the user password. """ - username = request.forms.get ('username') - email = request.forms.get ('email') - password = request.forms.get ('password') - secret_token = request.forms.get ('token') + username = request.forms.getunicode ('username') + email = request.forms.getunicode ('email') + password = request.forms.getunicode ('password') + secret_token = request.forms.getunicode ('token') # We must have all fields if not username or not email or not password or not secret_token: @@ -404,8 +404,8 @@ def update_user_settings (): user = session.user () - about = request.forms.get ('about') - email = request.forms.get ('email') + about = request.forms.getunicode ('about') + email = request.forms.getunicode ('email') if about is None or email is None: redirect (application.get_url ('user_settings')) @@ -509,7 +509,7 @@ def new_comment (hash_id): user = session.user () # The comment text - comment = request.forms.get ('new_comment').strip () + comment = request.forms.getunicode ('new_comment').strip () # Empty comment if len (comment) == 0: @@ -548,10 +548,10 @@ def edit_post_check (hash_id): redirect (application.get_url ('homepage')) # MUST have a title. If empty, use original title - title = request.forms.get ('title').strip () + title = request.forms.getunicode ('title').strip () if len (title) == 0: title = post['title'] - link = request.forms.get ('link').strip () if 'link' in request.forms else '' - text = request.forms.get ('text').strip () if 'text' in request.forms else '' + link = request.forms.getunicode ('link').strip () if 'link' in request.forms else '' + text = request.forms.getunicode ('text').strip () if 'text' in request.forms else '' # If there is a URL, make sure it has a "scheme" if len (link) > 0 and urlparse (link).scheme == '': @@ -584,7 +584,7 @@ def edit_comment_check (hash_id): if comment['userId'] != user['id']: redirect (application.get_url ('homepage')) - text = request.forms.get ('text').strip () if 'text' in request.forms else '' + text = request.forms.getunicode ('text').strip () if 'text' in request.forms else '' # Only update if the text is not empty if len (text) > 0: @@ -609,30 +609,30 @@ def submit_check (): """ # Somebody sent a
without a title??? - if not request.forms.get ('title'): + if not request.forms.getunicode ('title'): abort () user = session.user () # Retrieve title - title = request.forms.get ('title').strip () + title = request.forms.getunicode ('title').strip () # Bad title? if len (title) == 0: return template ('submit.html', flash='Title is missing.') # Retrieve link - link = request.forms.get ('link').strip () + link = request.forms.getunicode ('link').strip () # If there is a URL, make sure it has a "scheme" if len (link) > 0 and urlparse (link).scheme == '': link = 'http://' + link # Retrieve topics - topics = request.forms.get ('topics') + topics = request.forms.getunicode ('topics') # Retrieve text - text = request.forms.get ('text') + text = request.forms.getunicode ('text') # Add the new post post_hash_id = database.new_post (title, link, text, user['id']) @@ -672,7 +672,7 @@ def reply_check (hash_id): comment = database.get_comment (hash_id) # The text of the reply - text = request.forms.get ('text').strip () + text = request.forms.getunicode ('text').strip () # Empty comment. Redirect to parent post if len (text) == 0: @@ -699,15 +699,15 @@ def vote (): user = session.user () # Vote a post - if request.forms.get ('target') == 'post': + if request.forms.getunicode ('target') == 'post': # Retrieve the post - post = database.get_post (request.forms.get ('post'), user['id']) + post = database.get_post (request.forms.getunicode ('post'), user['id']) if not post: return # If user clicked the "upvote" button... - if request.forms.get ('updown') == 'up': + if request.forms.getunicode ('updown') == 'up': # If user has upvoted this post before... if post['user_vote'] == 1: # Remove +1 @@ -722,7 +722,7 @@ def vote (): database.vote_post (post['id'], user['id'], +1) # If user clicked the "downvote" button... - if request.forms.get ('updown') == 'down': + if request.forms.getunicode ('updown') == 'down': # If user has downvoted this post before... if post['user_vote'] == -1: # Remove -1 @@ -737,15 +737,15 @@ def vote (): database.vote_post (post['id'], user['id'], -1) # Vote a comment - if request.forms.get ('target') == 'comment': + if request.forms.getunicode ('target') == 'comment': # Retrieve the comment - comment = database.get_comment (request.forms.get ('comment'), user['id']) + comment = database.get_comment (request.forms.getunicode ('comment'), user['id']) if not comment: return # If user clicked the "upvote" button... - if request.forms.get ('updown') == 'up': + if request.forms.getunicode ('updown') == 'up': # If user has upvoted this comment before... if comment['user_vote'] == 1: # Remove +1 @@ -760,7 +760,7 @@ def vote (): database.vote_comment (comment['id'], user['id'], +1) # If user clicked the "downvote" button... - if request.forms.get ('updown') == 'down': + if request.forms.getunicode ('updown') == 'down': # If user has downvoted this comment before... if comment['user_vote'] == -1: # Remove -1 @@ -781,10 +781,10 @@ def search (): """ # Get the search query - query = request.query.get ('q') + query = request.query.getunicode ('q') # Get the offset - page = int (request.query.get ('page') or 0) + page = int (request.query.getunicode ('page') or 0) if page < 0: return "Page cannot be less than zero." @@ -796,7 +796,7 @@ def search (): page -= 1 # Results order - sort = request.query.get ('sort') + sort = request.query.getunicode ('sort') if sort not in [ 'newest', 'points' ]: sort = 'newest' diff --git a/freepost/database.py b/freepost/database.py index ed49217..64aeb1a 100644 --- a/freepost/database.py +++ b/freepost/database.py @@ -6,6 +6,7 @@ db = MySQLdb.connect ( host = settings['mysql']['host'], port = settings['mysql']['port'], db = settings['mysql']['schema'], + charset = settings['mysql']['charset'], user = settings['mysql']['username'], passwd = settings['mysql']['password'], autocommit = True)