Minor changes

Introduce new settings:
- ACCOUNT_HOME_URL, used by 'Site name' link on templates.
- ACCOUNT_DETAILS_URL, used on templates when user is connected.

'username' is registered as extra_data too for Clipper provider.

Template tag 'get_accounts_by_providers' is cleaner.

Remove useless account/settings view. Its content should be displayed
by some profile view.

SOCIALACCOUNT_ENABLED settings (of allauth package) doesn't work well.
Template tag 'is_socialaccount_enabled' provides a better check.
This commit is contained in:
Aurélien Delobelle 2017-09-16 02:33:40 +02:00
parent e66920ed4e
commit 7932da906e
5 changed files with 53 additions and 21 deletions

View file

@ -35,6 +35,7 @@ class ClipperProvider(CASProvider):
def extract_extra_data(self, data):
extra = super(ClipperProvider, self).extract_extra_data(data)
extra['username'] = data[0]
extra['email'] = self.extract_email(data)
return extra

View file

@ -0,0 +1,24 @@
import django
from django import template
from django.conf import settings
from django.urls import reverse
register = template.Library()
if django.VERSION >= (1, 9):
simple_tag = register.simple_tag
else:
simple_tag = register.assignment_tag
@simple_tag
def get_home_url():
home_url = getattr(settings, 'ACCOUNT_HOME_URL', None)
return reverse(home_url) if home_url is not None else '/'
@simple_tag
def get_profile_url():
profile_url = getattr(settings, 'ACCOUNT_DETAILS_URL', None)
return reverse(profile_url) if profile_url is not None else '/'

View file

@ -1,6 +1,9 @@
from collections import OrderedDict
import django
from django import template
from allauth import app_settings as allauth_settings
from allauth.socialaccount.templatetags import socialaccount as tt_social
@ -13,16 +16,18 @@ else:
@simple_tag
def get_providers_with_accounts(user):
def is_socialaccount_enabled():
return allauth_settings.SOCIALACCOUNT_ENABLED and tt_social.get_providers()
@simple_tag
def get_accounts_by_providers(user):
providers = tt_social.get_providers()
accounts = tt_social.get_social_accounts(user)
providers_with_accounts = [
{
'provider': provider,
'accounts': accounts.get(provider.id, []),
}
providers_with_accounts = OrderedDict(
(provider, accounts.get(provider.id, []))
for provider in providers
]
)
return providers_with_accounts

View file

@ -1,8 +1,3 @@
from django.conf.urls import include, url
from . import views
from allauth.urls import urlpatterns as allauth_urlpatterns
urlpatterns = [
url(r'^settings/$', views.account_settings,
name="account_settings"),
url(r'^', include('allauth.urls')),
]
urlpatterns = allauth_urlpatterns

View file

@ -1,11 +1,18 @@
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from django.core.urlresolvers import reverse_lazy
from django.views.generic import RedirectView
@method_decorator(login_required, name="dispatch")
class SettingsAccount(TemplateView):
template_name = 'account/settings.html'
class CaptureLogin(RedirectView):
url = reverse_lazy('account_login')
query_string = True
account_settings = SettingsAccount.as_view()
capture_login = CaptureLogin.as_view()
class CaptureLogout(RedirectView):
url = reverse_lazy('account_logout')
query_string = True
capture_logout = CaptureLogout.as_view()