Making user pic configurable (bug 549483)

This commit is contained in:
Fred Wenzel 2010-03-15 19:48:35 +01:00
Родитель fda5ce4029
Коммит ba0f401c5f
4 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -3,6 +3,7 @@ import hashlib
import random import random
import re import re
import string import string
import time
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User as DjangoUser from django.contrib.auth.models import User as DjangoUser
@ -75,11 +76,13 @@ class UserProfile(amo.models.ModelBase):
@property @property
def picture_url(self): def picture_url(self):
# TODO this used to be /user/1234/picture, and the regex stuff was
# in htaccess. Should we let the web server take care of it again?
split_id = re.match(r'((\d*?)(\d{0,3}?))\d{1,3}$', str(self.id)) split_id = re.match(r'((\d*?)(\d{0,3}?))\d{1,3}$', str(self.id))
return (settings.MEDIA_URL + 'img/uploads/userpics/%s/%s/%s.jpg' % ( if not self.picture_type:
split_id.group(2) or 0, split_id.group(1) or 0, self.id)) return settings.MEDIA_URL + '/img/zamboni/anon_user.png'
else:
return settings.USER_PIC_URL % (
split_id.group(2) or 0, split_id.group(1) or 0, self.id,
int(time.mktime(self.modified.timetuple())))
@amo.cached_property @amo.cached_property
def is_developer(self): def is_developer(self):

Просмотреть файл

@ -1,3 +1,4 @@
from datetime import date
import hashlib import hashlib
from django import test from django import test
@ -42,6 +43,21 @@ class TestUserProfile(test.TestCase):
u.save() u.save()
assert u.resetcode_expires assert u.resetcode_expires
def test_picture_url(self):
"""
Test for a preview URL if image is set, or default image otherwise.
"""
u = UserProfile(id=1234, picture_type='image/png',
modified=date.today())
u.picture_url.index('/userpics/0/1/1234.jpg?modified=')
u = UserProfile(id=1234567890, picture_type='image/png',
modified=date.today())
u.picture_url.index('/userpics/1234/1234567/1234567890.jpg?modified=')
u = UserProfile(id=1234, picture_type=None)
assert u.picture_url.endswith('/anon_user.png')
class TestPasswords(test.TestCase): class TestPasswords(test.TestCase):

Двоичные данные
media/img/zamboni/anon_user.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.0 KiB

Просмотреть файл

@ -324,6 +324,7 @@ PREVIEW_THUMBNAIL_URL = (STATIC_URL +
'/img/uploads/previews/thumbs/%s/%d.png?modified=%d') '/img/uploads/previews/thumbs/%s/%d.png?modified=%d')
PREVIEW_FULL_URL = (STATIC_URL + PREVIEW_FULL_URL = (STATIC_URL +
'/img/uploads/previews/full/%s/%d.png?modified=%d') '/img/uploads/previews/full/%s/%d.png?modified=%d')
USER_PIC_URL = STATIC_URL + '/img/uploads/userpics/%s/%s/%s.jpg?modified=%d'
# paths for uploaded extensions # paths for uploaded extensions
FILES_URL = STATIC_URL + "/downloads/file/%d/%s?src=%s" FILES_URL = STATIC_URL + "/downloads/file/%d/%s?src=%s"
COLLECTION_ICON_URL = ('%s/%s/%s/images/collection_icon/%%s/%%s' % COLLECTION_ICON_URL = ('%s/%s/%s/images/collection_icon/%%s/%%s' %