Added exception handling for if the directory already exists.

git-svn-id: http://django-avatar.googlecode.com/svn/trunk@12 c76b2324-5f53-0410-85ac-b1078a54aeeb
This commit is contained in:
Eric Florenzano 2008-08-02 23:04:26 +00:00
parent a3ec3aea8e
commit 94e33d6b70

View file

@ -101,7 +101,10 @@ def img(request, email_hash, resize_method=Image.ANTIALIAS):
def change(request, extra_context={}, next_override=None):
if request.method == "POST":
dirname = os.path.join(settings.MEDIA_ROOT, 'avatars')
os.makedirs(dirname)
try:
os.makedirs(dirname)
except OSError:
pass # The dirs already exist.
filename = "%s.jpg" % request.user.avatar.email_hash
full_filename = os.path.join(dirname, filename)
(destination, destination_path) = tempfile.mkstemp()