add gravator support
This commit is contained in:
parent
f1159a6369
commit
0b91ca61a0
4 changed files with 32 additions and 5 deletions
|
@ -11,6 +11,8 @@ USERS_PAGE_SIZE = get('USERS_PAGE_SIZE', 20)
|
|||
AVATARS_UPLOAD_TO = get('AVATARS_UPLOAD_TO', 'forum/avatars')
|
||||
AVATAR_WIDTH = get('AVATAR_WIDTH', 60)
|
||||
AVATAR_HEIGHT = get('AVATAR_HEIGHT', 60)
|
||||
GRAVATOR_SUPPORT = get('GRAVATOR_SUPPORT', True)
|
||||
GRAVATOR_DEFAULT = get('GRAVATOR_DEFAULT', 'identicon')
|
||||
DEFAULT_TIME_ZONE = get('DEFAULT_TIME_ZONE', 3)
|
||||
SIGNATURE_MAX_LENGTH = get('SIGNATURE_MAX_LENGTH', 1024)
|
||||
SIGNATURE_MAX_LINES = get('SIGNATURE_MAX_LINES', 3)
|
||||
|
|
|
@ -38,7 +38,9 @@
|
|||
{{ post.user|forum_stars }}
|
||||
</dd>
|
||||
{% if post.user.forum_profile.avatar and post.user.forum_profile.show_avatar %}
|
||||
<dd class="postavatar"><img src="{{ post.user.forum_profile.avatar.url }}" /></dd>
|
||||
<dd class="postavatar"><img src="{{ post.user.forum_profile.avatar.url }}" /></dd>
|
||||
{% else %}
|
||||
<dd class="postavatar"><img src="{% gravator post.user.email %}" /></dd>
|
||||
{% endif %}
|
||||
{% if post.user.forum_profile.location %}
|
||||
<dd>{% trans "From:" %} {{ post.user.forum_profile.location }}</dd>
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
# -*- coding: utf-8
|
||||
from datetime import datetime, timedelta
|
||||
import urllib
|
||||
try:
|
||||
from hashlib import md5
|
||||
except ImportError:
|
||||
import md5
|
||||
md5 = md5.new
|
||||
|
||||
from django import template
|
||||
from django.core.urlresolvers import reverse
|
||||
|
@ -110,7 +116,6 @@ def link(object, anchor=u''):
|
|||
anchor = anchor or smart_unicode(object)
|
||||
return mark_safe('<a href="%s">%s</a>' % (url, escape(anchor)))
|
||||
|
||||
|
||||
@register.filter
|
||||
def has_unreads(topic, user):
|
||||
"""
|
||||
|
@ -221,14 +226,32 @@ def forum_stars(user):
|
|||
else:
|
||||
return mark_safe('<img src="%sforum/img/stars/Star_0.gif" alt="" >' % (settings.MEDIA_URL))
|
||||
|
||||
|
||||
@register.filter
|
||||
def online(user):
|
||||
return cache.get(str(user.id))
|
||||
|
||||
|
||||
@register.filter
|
||||
def pm_unreads(user):
|
||||
return PrivateMessage.objects.filter(dst_user=user, read=False).count()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def new_reports():
|
||||
return Report.objects.filter(zapped=False).count()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def gravator(email):
|
||||
if forum_settings.GRAVATOR_SUPPORT:
|
||||
size = max(forum_settings.AVATAR_WIDTH, forum_settings.AVATAR_HEIGHT)
|
||||
url = "http://www.gravatar.com/avatar.php?"
|
||||
url += urllib.urlencode({
|
||||
'gravatar_id': md5(email.lower()).hexdigest(),
|
||||
'size': size,
|
||||
'default': forum_settings.GRAVATOR_DEFAULT,
|
||||
})
|
||||
return url
|
||||
else:
|
||||
return ''
|
|
@ -21,7 +21,7 @@ from apps.forum import settings as forum_settings
|
|||
@render_to('forum/index.html')
|
||||
def index(request):
|
||||
users_online = []
|
||||
|
||||
#TODO: refactoring
|
||||
for user in User.objects.all():
|
||||
if cache.get(str(user.id)):
|
||||
users_online.append(user)
|
||||
|
@ -345,8 +345,8 @@ def user(request, username):
|
|||
form.save()
|
||||
return HttpResponseRedirect(reverse('forum_profile', args=[user.username]))
|
||||
return {'form': form,
|
||||
'avatar_width': forum_settings.FORUM_AVATAR_WIDTH,
|
||||
'avatar_height': forum_settings.FORUM_AVATAR_HEIGHT,
|
||||
'avatar_width': forum_settings.AVATAR_WIDTH,
|
||||
'avatar_height': forum_settings.AVATAR_HEIGHT,
|
||||
}, 'forum/upload_avatar.html'
|
||||
elif action == 'delete_avatar':
|
||||
profile = get_object_or_404(Profile, user=request.user)
|
||||
|
|
Reference in a new issue