Skip to content
Permalink
Browse files

support version 2.0 of django-avatar app and improve the "manage avat…

…ars" page
  • Loading branch information...
evgenyfadeev committed Mar 16, 2015
1 parent 7815540 commit 929cba67ae17fc5183001adf4f732e30c0b635da
@@ -13,6 +13,7 @@
#values - the package qualifier to use for pip
REQUIREMENTS = {
'akismet': 'akismet',
'avatar': 'django-avatar>=2.0',
'bs4': 'beautifulsoup4',
'coffin': 'Coffin>=0.3,<=0.3.8',
'compressor': 'django-compressor==1.2',
@@ -3,6 +3,7 @@ Changes in Askbot

Development version (only in the repository)
--------------------------------------------
* Improved support of uploadable avatars
* Added authentication via MediaWiki
* Added option to specify `ASKBOT_QUESTION_TITLE_RENDERER` function
* Added option to specify `ASKBOT_HTML_MODERATOR` function
@@ -187,10 +187,9 @@ Uploaded avatars
================

To enable uploadable avatars (in addition to :ref:`gravatars <gravatar>`),
please install development version of
application ``django-avatar``, with the following command::

pip install -e git+git://github.com/ericflo/django-avatar.git#egg=django-avatar
please install application ``django-avatar``, with the following command::
pip install django-avatar

Then add ``avatar`` to the list of ``INSTALLED_APPS`` in your ``settings.py`` file
and run (to install database table used by the avatar app):
@@ -231,6 +231,9 @@ body.user-messages {
margin: 0 auto;
padding: 0;
}
.sr-only {
display: none;
}
/* ----- Notify message bar , check blocks/system_messages.html ----- */
.notify {
position: fixed;
@@ -2940,6 +2943,45 @@ ul.js-related-tags li {
.user-profile-page.inbox-forum .message:last-child, .user-profile-page.inbox-flags .message:last-child {
border: none;
}
.user-profile-page ul.avatars {
list-style: none;
margin-left: 0;
}
.user-profile-page ul.avatars li {
display: inline-block;
max-width: 128px;
position: relative;
vertical-align: top;
}
.user-profile-page ul.avatars img {
height: 128px;
width: 128px;
}
.user-profile-page ul.avatars .avatar-delete {
margin-right: 5px;
position: absolute;
right: 0;
top: 0;
}
.user-profile-page ul.avatars form {
text-align: center;
}
.user-profile-page ul.avatars label[for="id_avatar"] {
display: none;
}
.avatar-label {
background: black;
color: white !important;
cursor: help;
padding: 5px;
position: absolute;
}
.avatar-primary-label {
height: 28px;
line-height: 28px !important;
margin: 3px 0 0 0;
text-align: center;
}
.user-profile-page.inbox-forum .new {
background: #FFF8C6;
}
@@ -239,6 +239,10 @@ body.user-messages {
padding: 0;
}

.sr-only {
display: none;
}


/* ----- Notify message bar , check blocks/system_messages.html ----- */

@@ -3146,6 +3150,46 @@ ul.js-related-tags li {
}
}

.user-profile-page ul.avatars {
list-style: none;
margin-left: 0;
li {
display: inline-block;
max-width: 128px;
position: relative;
vertical-align: top;
}
img {
height: 128px;
width: 128px;
}
.avatar-delete {
margin-right: 5px;
position: absolute;
right: 0;
top: 0;
}
form {
text-align: center;
}
label[for="id_avatar"] {
display: none;
}
}
.avatar-label {
background: black;
color: white !important;
cursor: help;
padding: 5px;
position: absolute;
}
.avatar-primary-label {
height: 28px;
line-height: 28px !important;
margin: 3px 0 0 0;
text-align: center;
}

.user-profile-page.inbox-forum {
.new {
background: #FFF8C6;
@@ -289,15 +289,11 @@ def user_get_avatar_url(self, size=48):
"""
if 'avatar' in django_settings.INSTALLED_APPS:
if self.avatar_type == 'n':
import avatar
if askbot_settings.ENABLE_GRAVATAR: #avatar.settings.AVATAR_GRAVATAR_BACKUP:
return self.get_gravatar_url(size)
else:
return self.get_default_avatar_url(size)
return self.get_default_avatar_url(size)
elif self.avatar_type == 'a':
kwargs = {'user_id': self.id, 'size': size}
kwargs = {'user': self.username, 'size': size}
try:
return reverse('avatar_render_primary', kwargs = kwargs)
return reverse('avatar_render_primary', kwargs=kwargs)
except NoReverseMatch:
message = 'Please, make sure that avatar urls are in the urls.py '\
'or update your django-avatar app, '\
@@ -600,12 +600,7 @@ def test_avatar():
"""if "avatar" is in the installed apps,
checks that the module is actually installed"""
if 'avatar' in django_settings.INSTALLED_APPS:
try_import('Image', 'PIL', short_message = True)
try_import(
'avatar',
'-e git+git://github.com/ericflo/django-avatar.git#egg=avatar',
short_message = True
)
try_import('avatar', 'django-avatar', short_message=True)

def test_haystack():
if 'haystack' in django_settings.INSTALLED_APPS:

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,7 @@
<img src="{{ avatar.url }}" height="128" width="128"
{% if avatar.is_primary %}
alt="{% trans username=view_user.username|escape %}{{ username }}'s primary avatar{% endtrans %}"
{% else %}
alt="{% trans username=view_user.username|escape %}{{ username }}'s avatar{% endtrans %}"
{% endif %}
/>

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,70 @@
{% extends "user_profile/user.html" %}
{% block profilesection %}
{% trans %}manage avatars{% endtrans %}
{% endblock %}
{% block usercontent %}
<ul class="avatars">
{% for avatar in avatar_data %}
<li {% if avatar.is_primary %}class="avatar-primary"{% endif %}>
{% if avatar.avatar_type == 'default_avatar' %}
<p class="avatar-label" title="{% trans %}This is a default avatar image, shown at your account because you have not yet uploaded an avatar.{% endtrans %}">{% trans %}Default avatar{% endtrans %}</p>
{# show default avatar #}
{% include "avatar/avatar.html" %}
{% if not avatar.is_primary %}
{# select this avatar as primary #}
<form method="POST" action="{% url askbot_avatar_enable_default_avatar view_user.id %}">
{% csrf_token %}
<input type="submit" class="btn btn-primary"
value="{% trans %}Set as primary{% endtrans %}" />
</form>
{% endif %}
{% elif avatar.avatar_type == 'gravatar' %}
{% spaceless %}
<p class="avatar-label" title="{% trans email=view_user.email %}This image, called 'gravatar', is linked to the email address {{ email }}. It can be changed at http://gravatar.com{% endtrans %}">{% trans %}Gravatar{% endtrans %}</p>
{% endspaceless %}
{# show gravatar #}
{% include "avatar/avatar.html" %}
{% if not avatar.is_primary %}
{# select this avatar as primary #}
<form method="POST" action="{% url askbot_avatar_enable_gravatar view_user.id %}">
{% csrf_token %}
<input type="submit" class="btn btn-primary"
value="{% trans %}Set as primary{% endtrans %}" />
</form>
{% endif %}
{% else %}
{# show uploaded avatar #}
{% include "avatar/avatar.html" %}
{% if not avatar.is_primary %}
{# select this avatar as primary #}
<form method="POST" action="{% url askbot_avatar_set_primary view_user.id %}">{% csrf_token %}
<input type="hidden" name="choice" value="{{ avatar.id }}" />
<p><input type="submit" class="btn btn-primary" value="{% trans %}Set as primary{% endtrans %}" /></p>
</form>
{% endif %}
{# delete avatar button #}
<form method="POST" action="{% url askbot_avatar_delete avatar.id %}">
{% csrf_token %}
<input type="submit" class="btn btn-primary avatar-delete" value="x" />
<span class="sr-only">{% trans %}Remove{% endtrans %}</span>
</form>
{% endif %}
{% if avatar.is_primary %}
<p class="avatar-primary-label">{% trans %}Primary avatar{% endtrans %}</p>
{% endif %}
</li>
{% endfor %}
<li>
{% if avatars|length < max_avatars %}
{% if not has_uploaded_avatar %}
<p>{% trans %}You haven't uploaded an avatar yet.{% endtrans %}</p>
{% endif %}
<form enctype="multipart/form-data" method="POST" action="{% url askbot_avatar_upload view_user.id %}">
{% csrf_token %}
{{ upload_avatar_form.as_p() }}
<p><input type="submit" class="btn btn-primary" value="{% trans %}Upload an avatar{% endtrans %}" /></p>
</form>
{% endif %}
</li>
</ul>
{% endblock %}
@@ -7,17 +7,11 @@
{% if request.user.pk == view_user.pk %}
<p><a
{% if support_custom_avatars %}
href="{% url avatar_change %}"
href="{% url askbot_avatar_show_list view_user.id %}"
{% else %}
href="{% url faq %}#gravatar"
{% endif %}
>{% trans %}change picture{% endtrans %}</a></p>
{% if support_custom_avatars %}
<p><a
href="{% url avatar_delete %}"
>{% trans %}remove{% endtrans %}</a>
</p>
{% endif %}
{% endif %}
</div>
{% if can_show_karma %}
@@ -577,12 +577,11 @@ def test_user_page_with_groups_disabled(self):
class AvatarTests(AskbotTestCase):

def test_avatar_for_two_word_user_works(self):
if 'avatar' in settings.INSTALLED_APPS:
self.user = self.create_user('john doe')
response = self.client.get(
'avatar_render_primary',
kwargs = {'user': 'john doe', 'size': 48}
)
self.user = self.create_user('john doe')
response = self.client.get(
'avatar_render_primary',
kwargs = {'user': 'john doe', 'size': 48}
)


class QuestionViewTests(AskbotTestCase):
@@ -691,24 +691,43 @@
)

if 'avatar' in settings.INSTALLED_APPS:
#unforturately we have to wire avatar urls here,
#because views add and change are adapted to
#use jinja2 templates
urlpatterns += (
service_url('^avatar/add/$', views.avatar_views.add, name='avatar_add'),
#avatar views are added here, because some need
#either dynamic extra context or custom redirect
#or extra parameter in the urls
service_url(
'^avatar/change/$',
views.avatar_views.change,
name='avatar_change'
'^avatar/upload/(?P<user_id>\d+)/$',
views.avatar_views.upload,
name='askbot_avatar_upload'
),
service_url(
'^avatar/delete/$',
'^avatar/list/(?P<user_id>\d+)/$',
views.avatar_views.show_list,
name='askbot_avatar_show_list'
),
service_url(
'^avatar/set-primary/(?P<user_id>\d+)/$',
views.avatar_views.set_primary,
name='askbot_avatar_set_primary'
),
service_url(
'^avatar/delete/(?P<avatar_id>\d+)/$',
views.avatar_views.delete,
name='avatar_delete'
name='askbot_avatar_delete'
),
service_url(#this urs we inherit from the original avatar app
'^avatar/render_primary/(?P<user_id>[\+\d]+)/(?P<size>[\d]+)/$',
views.avatar_views.render_primary,
service_url(#this url is used without changes as in the avatar app
'^avatar/render-primary/(?P<user>[\w\d\.\-_]+)/(?P<size>[\d]+)/$',
'avatar.views.render_primary',
name='avatar_render_primary'
),
service_url(
'^avatar/enable-gravatar/(?P<user_id>[\d]+)/$',
views.avatar_views.enable_gravatar,
name='askbot_avatar_enable_gravatar'
),
service_url(
'^avatar/enable-default-avatar/(?P<user_id>[\d]+)/$',
views.avatar_views.enable_default_avatar,
name='askbot_avatar_enable_default_avatar'
)
)
Oops, something went wrong.

0 comments on commit 929cba6

Please sign in to comment.
You can’t perform that action at this time.