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.
This commit is contained in:
Ross Poulton 2009-03-08 06:18:03 +00:00
parent f6be2403f5
commit 9e13b42a4d

View File

@ -552,12 +552,9 @@ def attachment_path(instance, filename):
from django.conf import settings from django.conf import settings
os.umask(0) os.umask(0)
path = 'helpdesk/attachments/%s/%s' % (instance.followup.ticket.ticket_for_url, instance.followup.id ) path = 'helpdesk/attachments/%s/%s' % (instance.followup.ticket.ticket_for_url, instance.followup.id )
try: att_path = os.path.join(settings.MEDIA_ROOT, path)
os.makedirs(os.path.join(settings.MEDIA_ROOT, path), 0777) if not os.path.exists(att_path):
except OSError,e: os.makedirs(att_path, 0777)
if e[0] != 17:
# 17 = 'File exists'
raise e
return os.path.join(path, filename) return os.path.join(path, filename)