aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/profile/storage.py
blob: f5069fc88b161a9c1640a3e12c80b1827d8b1394 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)