Mercurial > public > sg101
comparison bio/models.py @ 666:ddc189ff96bb
For issue #46, mangle part of current time into avatar name to
bust browser caches.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 25 May 2013 00:22:40 -0500 |
parents | 08d905e38a86 |
children | 9e803323a0d0 |
comparison
equal
deleted
inserted
replaced
665:86d04190ff4e | 666:ddc189ff96bb |
---|---|
62 return u'' | 62 return u'' |
63 html.allow_tags = True | 63 html.allow_tags = True |
64 | 64 |
65 | 65 |
66 def avatar_file_path(instance, filename): | 66 def avatar_file_path(instance, filename): |
67 # The avatar's name is the username plus the current time plus the file | |
68 # extension. The time is used to bust browser caches. | |
69 # Get extension, if it exists: | |
67 ext = os.path.splitext(filename)[1] | 70 ext = os.path.splitext(filename)[1] |
68 if not ext: | 71 if not ext: |
69 ext = '.jpg' | 72 ext = '.jpg' |
70 avatar_name = instance.user.username + ext | 73 avatar_name = "{}{}{}".format(instance.user.username, |
74 datetime.datetime.utcnow().strftime('%S%f'), ext) | |
71 return os.path.join(settings.AVATAR_DIR, 'users', avatar_name) | 75 return os.path.join(settings.AVATAR_DIR, 'users', avatar_name) |
72 | 76 |
73 | 77 |
74 class UserProfile(models.Model): | 78 class UserProfile(models.Model): |
75 """model to represent additional information about users""" | 79 """model to represent additional information about users""" |