home » zplus/freepost.git
Author zPlus <zplus@peers.community> 2018-07-19 06:45:09
Committer zPlus <zplus@peers.community> 2018-07-19 06:45:09
Commit 79b4349 (patch)
Tree 408741d
Parent(s)

IGNORE email update if value already exists. modified: freepost/__init__.py modified: freepost/database.py


commits diff: 03779d5..79b4349
2 files changed, 17 insertions, 3 deletionsdownload


Diffstat
-rwxr-xr-x freepost/__init__.py 2
-rw-r--r-- freepost/database.py 18

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+1/-1 M   freepost/__init__.py
index 08510dd..24db177
old size: 25K - new size: 25K
@@ -418,7 +418,7 @@ def update_user ():
418 418 if about is None or email is None:
419 419 redirect (application.get_url ('user'))
420 420
421 - # TODO check unique value of emails
421 + # Update user info in the database
422 422 database.update_user (user['id'], about, email, False)
423 423
424 424 redirect (application.get_url ('user'))

+16/-2 M   freepost/database.py
index 0923433..c0ab7f9
old size: 18K - new size: 18K
@@ -281,21 +281,35 @@ def get_user_replies (user_id):
281 281 def update_user (user_id, about, email, email_notifications):
282 282 cursor = db.cursor (MySQLdb.cursors.DictCursor)
283 283
284 + # Update user info, but not email address
284 285 cursor.execute (
285 286 """
286 287 UPDATE user
287 288 SET about = %(about)s,
288 - email = %(email)s,
289 289 email_notifications = %(notifications)s
290 290 WHERE id = %(user)s
291 291 """,
292 292 {
293 293 'about': about,
294 - 'email': email,
295 294 'notifications': email_notifications,
296 295 'user': user_id
297 296 }
298 297 )
298 +
299 + # Update email address
300 + # IGNORE update if the email address is already specified. This is
301 + # necessary to avoid an "duplicate key" exception when updating value.
302 + cursor.execute (
303 + """
304 + UPDATE IGNORE user
305 + SET email = %(email)s
306 + WHERE id = %(user)s
307 + """,
308 + {
309 + 'email': email,
310 + 'user': user_id
311 + }
312 + )
299 313
300 314 # Set user replies as read
301 315 def set_replies_as_read (user_id):