From 9e13b42a4dff2704b0787089b5e12d9da5f9f760 Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Sun, 8 Mar 2009 06:18:03 +0000 Subject: [PATCH] Fixes issue #48: when saving attachments, the 'path exists' checking was not compatible with Windows. This patch is a much cleaner way of checking the path before creating it, rather than relying on an exception which we were previously doing. Thanks to 'rukeba' for the patch. --- models.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/models.py b/models.py index 41821cbd..80295a00 100644 --- a/models.py +++ b/models.py @@ -552,12 +552,9 @@ def attachment_path(instance, filename): from django.conf import settings os.umask(0) path = 'helpdesk/attachments/%s/%s' % (instance.followup.ticket.ticket_for_url, instance.followup.id ) - try: - os.makedirs(os.path.join(settings.MEDIA_ROOT, path), 0777) - except OSError,e: - if e[0] != 17: - # 17 = 'File exists' - raise e + att_path = os.path.join(settings.MEDIA_ROOT, path) + if not os.path.exists(att_path): + os.makedirs(att_path, 0777) return os.path.join(path, filename)