##// END OF EJS Templates
Converting file name to a preudo-unique number instead of the original name.
neko259 -
r50:9ceb712a default
parent child Browse files
Show More
@@ -1,4 +1,5 b''
1 import os
1 import os
2 from random import random
2 import re
3 import re
3 from django.db import models
4 from django.db import models
4 from django.utils import timezone
5 from django.utils import timezone
@@ -15,14 +16,6 b" NO_IP = '0.0.0.0'"
15 UNKNOWN_UA = ''
16 UNKNOWN_UA = ''
16
17
17
18
18 def update_image_filename(instance, filename):
19 """Get unique image filename"""
20
21 path = 'images/'
22 new_name = str(int(time.mktime(time.gmtime()))) + '_' + filename
23 return os.path.join(path, new_name)
24
25
26 class PostManager(models.Manager):
19 class PostManager(models.Manager):
27 ALL_PAGES = -1
20 ALL_PAGES = -1
28
21
@@ -169,12 +162,26 b' class Tag(models.Model):'
169 class Post(models.Model):
162 class Post(models.Model):
170 """A post is a message."""
163 """A post is a message."""
171
164
165 IMAGES_DIRECTORY = 'images/'
166 FILE_EXTENSION_DELIMITER = '.'
167
172 objects = PostManager()
168 objects = PostManager()
173
169
170 def _update_image_filename(self, filename):
171 """Get unique image filename"""
172
173 path = self.IMAGES_DIRECTORY
174 new_name = str(int(time.mktime(time.gmtime())))
175 new_name += str(int(random() * 1000))
176 new_name += self.FILE_EXTENSION_DELIMITER
177 new_name += filename.split(self.FILE_EXTENSION_DELIMITER)[-1:][0]
178
179 return os.path.join(path, new_name)
180
174 title = models.CharField(max_length=50)
181 title = models.CharField(max_length=50)
175 pub_time = models.DateTimeField()
182 pub_time = models.DateTimeField()
176 text = MarkupField(default_markup_type='markdown', escape_html=True)
183 text = MarkupField(default_markup_type='markdown', escape_html=True)
177 image = thumbs.ImageWithThumbsField(upload_to=update_image_filename,
184 image = thumbs.ImageWithThumbsField(upload_to=_update_image_filename,
178 blank=True, sizes=((200, 150),))
185 blank=True, sizes=((200, 150),))
179 poster_ip = models.IPAddressField()
186 poster_ip = models.IPAddressField()
180 poster_user_agent = models.TextField()
187 poster_user_agent = models.TextField()
General Comments 0
You need to be logged in to leave comments. Login now