diff gpp/bio/models.py @ 560:4e891919c63f

Changed the avatar upload_to path to not rely on the user supplied name, as this has caused problems in the past (too long). Now just store avatars under media/avatars/users/username.ext.
author Brian Neal <bgneal@gmail.com>
date Thu, 02 Feb 2012 20:09:19 -0600
parents e0523e17ea43
children 98b373ca09f3
line wrap: on
line diff
--- a/gpp/bio/models.py	Thu Feb 02 19:05:46 2012 -0600
+++ b/gpp/bio/models.py	Thu Feb 02 20:09:19 2012 -0600
@@ -61,11 +61,12 @@
     html.allow_tags = True
 
 
-def avatar_file_path_for_user(username, filename):
-    return os.path.join(settings.AVATAR_DIR, 'users', username, filename)
-
 def avatar_file_path(instance, filename):
-    return avatar_file_path_for_user(instance.user.username, filename)
+    ext = os.path.splitext(filename)[1]
+    if not ext:
+        ext = '.jpg'
+    avatar_name = instance.user.username + ext
+    return os.path.join(settings.AVATAR_DIR, 'users', avatar_name)
 
 
 class UserProfile(models.Model):