Commits

luke  committed 23bce46

[project @ 334]
Fixed bug #3 and made uploading icons more robust.

  • Participants
  • Parent commits 59830e2

Comments (0)

Files changed (2)

File cciw/cciwmain/imageutils.py

         pass # don't care if we couldn't delete for some reason
 
 
-def fix_member_icon(filename, username):
+def fix_member_icon(member):
+    filename = settings.MEDIA_ROOT + member.icon
     try:
         img = parse_image(filename)
     except IOError:
     
     ext = filename.split('.')[-1]
     # Remove existing variants
-    for f in glob.glob(settings.MEDIA_ROOT + settings.MEMBER_ICON_PATH + username + ".*"):
+    for f in glob.glob(settings.MEDIA_ROOT + settings.MEMBER_ICON_PATH + member.user_name + ".*"):
         os.unlink(f)
 
-    shutil.move(filename, settings.MEDIA_ROOT + settings.MEMBER_ICON_PATH + username + "." + ext)
+    newrelpath = settings.MEMBER_ICON_PATH + member.user_name + "." + ext
+    newfullpath = settings.MEDIA_ROOT + newrelpath
+    shutil.move(filename, newfullpath)
+    os.chmod(newfullpath, 0777)
+    member.icon = newrelpath
+    member.save()

File cciw/cciwmain/views/memberadmin.py

     elif password2 !=  password1:
         raise ValidationError("The passwords do not match")
     else:
+        iconfilename = user_name + "." + settings.DEFAULT_MEMBER_ICON.split('.')[-1]
         m = Member(user_name=user_name, 
                    last_seen=datetime.datetime.now(),
                    date_joined=datetime.datetime.now(),
-                   password=Member.encrypt_password(password1))
+                   password=Member.encrypt_password(password1),
+                   icon=settings.MEMBER_ICON_PATH + iconfilename)
         m.save()
+
+        # Copy default member icon
+        import shutil
+        shutil.copy(settings.MEDIA_ROOT + settings.DEFAULT_MEMBER_ICON,
+                    settings.MEDIA_ROOT + settings.MEMBER_ICON_PATH + iconfilename)
         return m
 
 def email_hash(email):
             
             if request.FILES:
                 try:
-                    imageutils.fix_member_icon(settings.MEDIA_ROOT + new_current_member.icon, 
-                                                new_current_member.user_name)
+                    imageutils.fix_member_icon(new_current_member)
                 except imageutils.ValidationError, e:
                     c['image_error'] = e.args[0]