mirror of
https://github.com/NaN-tic/trytond-nereid-zz.git
synced 2023-12-14 04:02:59 +01:00
Remove gravatar usage from party #38
The gravatar contrib plugin is removed. The default implementation of profile picture now implements a simple fallback to get_gravatar_url
This commit is contained in:
parent
61382f60e1
commit
ad9decb606
40
party.py
40
party.py
|
@ -11,6 +11,7 @@
|
|||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import urllib
|
||||
|
||||
import pytz
|
||||
from wtforms import Form, TextField, IntegerField, SelectField, validators, \
|
||||
|
@ -20,7 +21,6 @@ from werkzeug import redirect, abort
|
|||
|
||||
from nereid import request, url_for, render_template, login_required, flash, \
|
||||
jsonify
|
||||
from nereid.contrib import gravatar
|
||||
from nereid.globals import session, current_app
|
||||
from nereid.signals import registration
|
||||
from nereid.templating import render_email
|
||||
|
@ -728,24 +728,40 @@ class NereidUser(ModelSQL, ModelView):
|
|||
"""
|
||||
return super(NereidUser, self).write(ids, self._convert_values(values))
|
||||
|
||||
def get_profile_picture(self, user, **kwargs):
|
||||
def get_gravatar_url(self, user, **kwargs):
|
||||
"""
|
||||
By default tries to get the email of the user and construct a gravatar
|
||||
URL from it
|
||||
|
||||
To change the behavior inherit `nereid.user` and change this method to
|
||||
return an URL
|
||||
|
||||
:param user: Browse Record of the user
|
||||
|
||||
Other keyword arguments
|
||||
Return a gravatar url for the given email
|
||||
|
||||
:param https: To get a secure URL
|
||||
:param default: The default image to return if there is no profile pic
|
||||
For example a unisex avatar
|
||||
:param size: The size for the image
|
||||
"""
|
||||
return gravatar.url(user.email, **kwargs)
|
||||
if kwargs.get('https', request.scheme == 'https'):
|
||||
url = 'https://secure.gravatar.com/avatar/%s?'
|
||||
else:
|
||||
url = 'http://www.gravatar.com/avatar/%s?'
|
||||
url = url % hashlib.md5(user.email.lower()).hexdigest()
|
||||
|
||||
params = []
|
||||
default = kwargs.get('default', None)
|
||||
if default:
|
||||
params.append(('d', default))
|
||||
|
||||
size = kwargs.get('size', None)
|
||||
if size:
|
||||
params.append(('s', str(size)))
|
||||
|
||||
return url + urllib.urlencode(params)
|
||||
|
||||
def get_profile_picture(self, user, **kwargs):
|
||||
"""
|
||||
Return the url to the profile picture of the user.
|
||||
|
||||
The default implementation fetches the profile image of the user from
|
||||
gravatar using :meth:`get_gravatar_url`
|
||||
"""
|
||||
return self.get_gravatar_url(user, **kwargs)
|
||||
|
||||
def aslocaltime(self, naive_date, user=None):
|
||||
"""
|
||||
|
|
|
@ -79,12 +79,7 @@ class TestAuth(NereidTestCase):
|
|||
'default_language': en_us,
|
||||
'guest_user': self.guest_user_id,
|
||||
})
|
||||
|
||||
def get_template_source(self, name):
|
||||
"""
|
||||
Return templates
|
||||
"""
|
||||
templates = {
|
||||
self.templates = {
|
||||
'localhost/home.jinja': '{{get_flashed_messages()}}',
|
||||
'localhost/login.jinja':
|
||||
'{{ login_form.errors }} {{get_flashed_messages()}}',
|
||||
|
@ -102,7 +97,13 @@ class TestAuth(NereidTestCase):
|
|||
'localhost/emails/reset-text.jinja': 'reset-email-text',
|
||||
'localhost/emails/reset-html.jinja': 'reset-email-html',
|
||||
}
|
||||
return templates.get(name)
|
||||
|
||||
def get_template_source(self, name):
|
||||
"""
|
||||
Return templates
|
||||
"""
|
||||
|
||||
return self.templates.get(name)
|
||||
|
||||
def test_0005_mock_setup(self):
|
||||
assert get_smtp_server() is self.PatchedSMTP.return_value
|
||||
|
@ -466,6 +467,24 @@ class TestAuth(NereidTestCase):
|
|||
with app.test_request_context():
|
||||
self.assertTrue(test_permission_3())
|
||||
|
||||
def test_0070_gravatar(self):
|
||||
"""
|
||||
Check if the gravatar is returned by the profile picture
|
||||
"""
|
||||
with Transaction().start(DB_NAME, USER, CONTEXT):
|
||||
self.setup_defaults()
|
||||
app = self.get_app()
|
||||
|
||||
self.templates['localhost/home.jinja'] = """
|
||||
{{ request.nereid_user.get_profile_picture(request.nereid_user) }}
|
||||
"""
|
||||
|
||||
with app.test_client() as c:
|
||||
response = c.get('/en_US/')
|
||||
self.assertTrue(
|
||||
'http://www.gravatar.com/avatar/' in response.data
|
||||
)
|
||||
|
||||
|
||||
def suite():
|
||||
"Nereid test suite"
|
||||
|
|
Loading…
Reference in a new issue