simplify url dispatcher
we can include all the urls (as usual) AFTER overiding some of them giving a special rule first.
This commit is contained in:
parent
d6b5041573
commit
d3724032e1
@ -1,13 +1,10 @@
|
|||||||
from django.conf.urls import patterns, include, url
|
from django.conf.urls import patterns, include, url
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.views.generic.base import TemplateView
|
|
||||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
|
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
|
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
from registration.backends.default.views import ActivationView
|
|
||||||
from registration.backends.default.views import RegistrationView
|
from registration.backends.default.views import RegistrationView
|
||||||
from registration.forms import RegistrationForm
|
from registration.forms import RegistrationForm
|
||||||
|
|
||||||
@ -24,75 +21,33 @@ class Html5AuthenticationForm(AuthenticationForm):
|
|||||||
self.fields['username'].widget.attrs.update(dict(autofocus=None))
|
self.fields['username'].widget.attrs.update(dict(autofocus=None))
|
||||||
|
|
||||||
|
|
||||||
def html5_login(*args, **kwargs):
|
|
||||||
kwargs['authentication_form'] = Html5AuthenticationForm
|
|
||||||
return auth_views.login(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class Html5PasswordChangeForm(PasswordChangeForm):
|
class Html5PasswordChangeForm(PasswordChangeForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Html5PasswordChangeForm, self).__init__(*args, **kwargs)
|
super(Html5PasswordChangeForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['old_password'].widget.attrs.update(dict(autofocus=None))
|
self.fields['old_password'].widget.attrs.update(dict(autofocus=None))
|
||||||
|
|
||||||
|
|
||||||
def html5_password_change(*args, **kwargs):
|
|
||||||
kwargs['password_change_form'] = Html5PasswordChangeForm
|
|
||||||
kwargs['template_name'] = 'registration/password_change.html' # own template
|
|
||||||
kwargs['post_change_redirect'] = reverse('account_profile')
|
|
||||||
return auth_views.password_change(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url('', include('social.apps.django_app.urls', namespace='social')),
|
url('', include('social.apps.django_app.urls', namespace='social')),
|
||||||
# registration start
|
# registration start
|
||||||
# this is a modified copy of registration.backends.default.urls:
|
# these are some modified patterns from registration.backends.default.urls:
|
||||||
url(r'^accounts/activate/complete/$',
|
|
||||||
TemplateView.as_view(template_name='registration/activation_complete.html'),
|
|
||||||
name='registration_activation_complete'),
|
|
||||||
# Activation keys get matched by \w+ instead of the more specific
|
|
||||||
# [a-fA-F0-9]{40} because a bad activation key should still get to the view;
|
|
||||||
# that way it can return a sensible "invalid key" message instead of a
|
|
||||||
# confusing 404.
|
|
||||||
url(r'^accounts/activate/(?P<activation_key>\w+)/$',
|
|
||||||
ActivationView.as_view(),
|
|
||||||
name='registration_activate'),
|
|
||||||
url(r'^accounts/register/$',
|
url(r'^accounts/register/$',
|
||||||
RegistrationView.as_view(form_class=Html5RegistrationForm),
|
RegistrationView.as_view(form_class=Html5RegistrationForm),
|
||||||
name='registration_register'),
|
name='registration_register'),
|
||||||
url(r'^accounts/register/complete/$',
|
|
||||||
TemplateView.as_view(template_name='registration/registration_complete.html'),
|
|
||||||
name='registration_complete'),
|
|
||||||
url(r'^accounts/register/closed/$',
|
|
||||||
TemplateView.as_view(template_name='registration/registration_closed.html'),
|
|
||||||
name='registration_disallowed'),
|
|
||||||
# from registration.auth_urls:
|
# from registration.auth_urls:
|
||||||
url(r'^accounts/login/$',
|
url(r'^accounts/login/$',
|
||||||
html5_login,
|
auth_views.login,
|
||||||
{'template_name': 'registration/login.html'},
|
{'authentication_form': Html5AuthenticationForm,
|
||||||
|
'template_name': 'registration/login.html'},
|
||||||
name='auth_login'),
|
name='auth_login'),
|
||||||
url(r'^accounts/logout/$',
|
|
||||||
auth_views.logout,
|
|
||||||
{'template_name': 'registration/logout.html'},
|
|
||||||
name='auth_logout'),
|
|
||||||
url(r'^accounts/password/change/$',
|
url(r'^accounts/password/change/$',
|
||||||
html5_password_change,
|
auth_views.password_change,
|
||||||
|
{'password_change_form': Html5PasswordChangeForm,
|
||||||
|
'template_name': 'registration/password_change.html', # own template
|
||||||
|
'post_change_redirect': '/account/profile'}, # reverse() does not work here
|
||||||
name='auth_password_change'),
|
name='auth_password_change'),
|
||||||
url(r'^accounts/password/change/done/$',
|
url(r'^accounts/', include('registration.backends.default.urls')),
|
||||||
auth_views.password_change_done,
|
|
||||||
name='auth_password_change_done'),
|
|
||||||
url(r'^accounts/password/reset/$',
|
|
||||||
auth_views.password_reset,
|
|
||||||
name='auth_password_reset'),
|
|
||||||
url(r'^accounts/password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
|
|
||||||
auth_views.password_reset_confirm,
|
|
||||||
name='auth_password_reset_confirm'),
|
|
||||||
url(r'^accounts/password/reset/complete/$',
|
|
||||||
auth_views.password_reset_complete,
|
|
||||||
name='auth_password_reset_complete'),
|
|
||||||
url(r'^accounts/password/reset/done/$',
|
|
||||||
auth_views.password_reset_done,
|
|
||||||
name='auth_password_reset_done'),
|
|
||||||
# registration end
|
# registration end
|
||||||
url(r'^account/', include('nsupdate.accounts.urls')),
|
url(r'^account/', include('nsupdate.accounts.urls')),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user