diff --git a/config.py b/config.py index 93fdab6..e35ebb4 100644 --- a/config.py +++ b/config.py @@ -49,11 +49,11 @@ TEMPLATES[0]['OPTIONS']['context_processors'].append( OPENID_CREATE_USERS = True OPENID_UPDATE_DETAILS_FROM_SREG = True -SITE_NAME = 'ivatar' +SITE_NAME = os.environ.get('SITE_NAME', 'ivatar') IVATAR_VERSION = '0.1' -SECURE_BASE_URL = 'https://avatars.linux-kernel.at/avatar/' -BASE_URL = 'http://avatars.linux-kernel.at/avatar/' +SECURE_BASE_URL = os.environ.get('SECURE_BASE_URL', 'https://avatars.linux-kernel.at/avatar/') +BASE_URL = os.environ.get('BASE_URL', 'http://avatars.linux-kernel.at/avatar/') LOGIN_REDIRECT_URL = reverse_lazy('profile') MAX_LENGTH_EMAIL = 254 # http://stackoverflow.com/questions/386294 @@ -96,12 +96,17 @@ BOOTSTRAP4 = { }, } -if 'test' not in sys.argv and 'collectstatic' not in sys.argv: - ANYMAIL = { # pragma: no cover - 'MAILGUN_API_KEY': os.environ['IVATAR_MAILGUN_API_KEY'], - 'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'], - } - EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover +if 'EMAIL_BACKEND' in os.environ: + EMAIL_BACKEND = os.environ['EMAIL_BACKEND'] +else: + if 'test' in sys.argv or 'collectstatic' in sys.argv: + EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' + else: + ANYMAIL = { # pragma: no cover + 'MAILGUN_API_KEY': os.environ['IVATAR_MAILGUN_API_KEY'], + 'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'], + } + EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover DEFAULT_FROM_EMAIL = 'ivatar@mg.linux-kernel.at' try: @@ -140,3 +145,5 @@ SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' USE_X_FORWARDED_HOST = True ALLOWED_EXTERNAL_OPENID_REDIRECT_DOMAINS = ['avatars.linux-kernel.at', 'localhost',] + +DEFAULT_AVATAR_SIZE = 80 diff --git a/ivatar/ivataraccount/gravatar.py b/ivatar/ivataraccount/gravatar.py index a1889be..df1cfe6 100644 --- a/ivatar/ivataraccount/gravatar.py +++ b/ivatar/ivataraccount/gravatar.py @@ -5,6 +5,8 @@ from ssl import SSLError from urllib.request import urlopen, HTTPError, URLError import hashlib +from .. settings import AVATAR_MAX_SIZE + URL_TIMEOUT = 5 # in seconds @@ -15,7 +17,7 @@ def get_photo(email): hash_object = hashlib.new('md5') hash_object.update(email.lower().encode('utf-8')) thumbnail_url = 'https://secure.gravatar.com/avatar/' + \ - hash_object.hexdigest() + '?s=80&d=404' + hash_object.hexdigest() + '?s=%i&d=404' % AVATAR_MAX_SIZE image_url = 'https://secure.gravatar.com/avatar/' + hash_object.hexdigest( ) + '?s=512&d=404' @@ -44,8 +46,8 @@ def get_photo(email): return { 'thumbnail_url': thumbnail_url, 'image_url': image_url, - 'width': 80, - 'height': 80, + 'width': AVATAR_MAX_SIZE, + 'height': AVATAR_MAX_SIZE, 'service_url': service_url, 'service_name': 'Gravatar' } diff --git a/ivatar/ivataraccount/migrations/0008_userpreference.py b/ivatar/ivataraccount/migrations/0008_userpreference.py index 5f76f52..5838a97 100644 --- a/ivatar/ivataraccount/migrations/0008_userpreference.py +++ b/ivatar/ivataraccount/migrations/0008_userpreference.py @@ -1,3 +1,4 @@ +# pylint: disable=invalid-name,missing-docstring # Generated by Django 2.0.6 on 2018-07-04 12:32 from django.conf import settings @@ -5,18 +6,18 @@ from django.db import migrations, models import django.db.models.deletion -def add_preference_to_user(apps, schema_editor): +def add_preference_to_user(apps, schema_editor): # pylint: disable=unused-argument ''' Make sure all users have preferences set up ''' from django.contrib.auth.models import User - UserPreference = apps.get_model('ivataraccount', 'UserPreference') - for u in User.objects.filter(userpreference=None): - p = UserPreference.objects.create(user_id=u.pk) - p.save() + UserPreference = apps.get_model('ivataraccount', 'UserPreference') # pylint: disable=invalid-name + for user in User.objects.filter(userpreference=None): + pref = UserPreference.objects.create(user_id=user.pk) # pragma: no cover + pref.save() # pragma: no cover -class Migration(migrations.Migration): +class Migration(migrations.Migration): # pylint: disable=missing-docstring dependencies = [ ('auth', '0009_alter_user_last_name_max_length'), @@ -27,8 +28,16 @@ class Migration(migrations.Migration): migrations.CreateModel( name='UserPreference', fields=[ - ('theme', models.CharField(choices=[('default', 'Default theme'), ('clime', 'Climes theme')], default='default', max_length=10)), - ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('theme', models.CharField( + choices=[ + ('default', 'Default theme'), + ('clime', 'Climes theme')], + default='default', max_length=10)), + ('user', models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + serialize=False, + to=settings.AUTH_USER_MODEL)), ], ), migrations.RunPython(add_preference_to_user), diff --git a/ivatar/ivataraccount/migrations/0013_auto_20181203_1421.py b/ivatar/ivataraccount/migrations/0013_auto_20181203_1421.py new file mode 100644 index 0000000..e857c27 --- /dev/null +++ b/ivatar/ivataraccount/migrations/0013_auto_20181203_1421.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.3 on 2018-12-03 14:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ivataraccount', '0012_auto_20181107_1732'), + ] + + operations = [ + migrations.AlterField( + model_name='userpreference', + name='theme', + field=models.CharField(choices=[('default', 'Default theme'), ('clime', 'climes theme'), ('green', 'green theme'), ('red', 'red theme')], default='default', max_length=10), + ), + ] diff --git a/ivatar/ivataraccount/models.py b/ivatar/ivataraccount/models.py index 304a858..fc4a611 100644 --- a/ivatar/ivataraccount/models.py +++ b/ivatar/ivataraccount/models.py @@ -70,7 +70,8 @@ class UserPreference(models.Model): THEMES = ( ('default', 'Default theme'), ('clime', 'climes theme'), - ('falko', 'falkos theme'), + ('green', 'green theme'), + ('red', 'red theme'), ) theme = models.CharField( @@ -135,7 +136,7 @@ class Photo(BaseAccountModel): image_url = gravatar['image_url'] if service_name == 'Libravatar': - image_url = libravatar_url(email_address) + image_url = libravatar_url(email_address, size=AVATAR_MAX_SIZE) if not image_url: return False # pragma: no cover diff --git a/ivatar/ivataraccount/templates/_import_photo_form.html b/ivatar/ivataraccount/templates/_import_photo_form.html index 77070b2..ef950e4 100644 --- a/ivatar/ivataraccount/templates/_import_photo_form.html +++ b/ivatar/ivataraccount/templates/_import_photo_form.html @@ -25,7 +25,7 @@
{% trans 'Change your password' %}
-{% else %} - -{% endif %} ++
+ + + diff --git a/ivatar/ivataraccount/templates/upload_libravatar_export.html b/ivatar/ivataraccount/templates/upload_libravatar_export.html index c75a1ab..1886a5c 100644 --- a/ivatar/ivataraccount/templates/upload_libravatar_export.html +++ b/ivatar/ivataraccount/templates/upload_libravatar_export.html @@ -5,30 +5,6 @@ {% block title %}{% trans 'Upload an export from libravatar' %} - ivatar{% endblock title %} {% block content %} -