summaryrefslogtreecommitdiff
path: root/taskapp/models.py
diff options
context:
space:
mode:
authornishanth2010-02-26 15:15:16 +0530
committernishanth2010-02-26 15:15:16 +0530
commit17d75d44c428de036655767bae2932075e544d19 (patch)
tree6223be5bcfd5ab1d5a0d47a685e24b4b394cb078 /taskapp/models.py
parent48df951630dcc49119b034c2168f19c098c247b3 (diff)
downloadpytask-17d75d44c428de036655767bae2932075e544d19.tar.gz
pytask-17d75d44c428de036655767bae2932075e544d19.tar.bz2
pytask-17d75d44c428de036655767bae2932075e544d19.zip
modified image storage.
Diffstat (limited to 'taskapp/models.py')
-rw-r--r--taskapp/models.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/taskapp/models.py b/taskapp/models.py
index db7d6ab..6429336 100644
--- a/taskapp/models.py
+++ b/taskapp/models.py
@@ -26,6 +26,13 @@ STATUS_CHOICES = (
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 @@ class CustomImageStorage(FileSystemStorage):
"""
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):