# HG changeset patch # User nishanth # Date 1267177516 -19800 # Node ID 5bbb29a07b87481d434181931a666d6ba49df2d7 # Parent 58fa1d626d37e53ef8f9bf6a92149aac1d254eda modified image storage. diff -r 58fa1d626d37 -r 5bbb29a07b87 taskapp/models.py --- a/taskapp/models.py Fri Feb 26 15:00:01 2010 +0530 +++ b/taskapp/models.py Fri Feb 26 15:15:16 2010 +0530 @@ -26,6 +26,13 @@ IMAGES_DIR = "./images" UPLOADS_DIR = "./uploads" +def get_key(): + """ generate a 10 character name with random alphabets and digits. + """ + + name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)]) + return name + class CustomImageStorage(FileSystemStorage): def path(self, name): @@ -39,10 +46,10 @@ """ root, ext = os.path.splitext(name) - name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext - while self.exists(name): - name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext - return name + file_name = get_key() + ext + while self.exists(file_name): + file_name = get_key() + ext + return file_name class Profile(models.Model):