aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/profile/storage.py
diff options
context:
space:
mode:
authorAlvin Li <liweitianux@gmail.com>2013-08-13 14:13:24 +0800
committerAlvin Li <liweitianux@gmail.com>2013-08-13 14:13:24 +0800
commit9636d4a6767f49384d5c386bc3f1142c88b90613 (patch)
tree3a70f6d9e4be1791d36c87cc7cbfd1d5aa2b39dd /97suifangqa/apps/profile/storage.py
parent9383d9a8a5988d071766c3d08a5c946e9c5b02ae (diff)
download97dev-9636d4a6767f49384d5c386bc3f1142c88b90613.tar.bz2
cloned from 'bitbucket', 2013/08/13
Diffstat (limited to '97suifangqa/apps/profile/storage.py')
-rw-r--r--97suifangqa/apps/profile/storage.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/97suifangqa/apps/profile/storage.py b/97suifangqa/apps/profile/storage.py
new file mode 100644
index 0000000..f5069fc
--- /dev/null
+++ b/97suifangqa/apps/profile/storage.py
@@ -0,0 +1,21 @@
+#-*- coding: utf-8 -*-
+"""
+ 文件存储
+"""
+import os
+import time
+import random
+
+from django.core.files.storage import FileSystemStorage
+
+class OverwriteStorage(FileSystemStorage):
+
+ def _save(self, name, content):
+ if self.exists(name):
+ self.delete(name)
+ ext = os.path.splitext(name)[1]
+ d = os.path.dirname(name)
+ fn = time.strftime("%Y%m%d%H%M%S")
+ fn = fn + "_%d" % random.randint(0,1000)
+ name = os.path.join(d, fn + ext)
+ return super(OverwriteStorage, self)._save(name, content) \ No newline at end of file