@@ -528,7 +528,7 @@ HTML. You don't have to use it if you don't like it though. :)]
528
528
529
529
530
530
[role="sourcecode small-code"]
531
- .lists/templates/base.html (ch17l012 )
531
+ .lists/templates/base.html (ch19l012 )
532
532
====
533
533
[source,html]
534
534
----
@@ -686,7 +686,7 @@ need to actually add the messages to the page. Something like this:
686
686
687
687
688
688
[role="sourcecode dofirst-ch17l014-4"]
689
- .lists/templates/base.html (ch17l015 )
689
+ .lists/templates/base.html (ch19l015 )
690
690
====
691
691
[source,html]
692
692
----
@@ -924,25 +924,25 @@ So we can insert the token into our email like this:
924
924
925
925
926
926
[role="sourcecode"]
927
- .accounts/views.py (ch17l023 )
927
+ .accounts/views.py (ch19l023 )
928
928
====
929
929
[source,python]
930
930
----
931
- from django.core.urlresolvers import reverse
931
+ from django.urls import reverse
932
932
[...]
933
933
934
934
def send_login_email(request):
935
- email = request.POST[' email' ]
935
+ email = request.POST[" email" ]
936
936
token = Token.objects.create(email=email)
937
- url = request.build_absolute_uri( #<1>
938
- reverse(' login' ) + ' ?token=' + str(token.uid)
937
+ url = request.build_absolute_uri( # <1>
938
+ reverse(" login" ) + " ?token=" + str(token.uid)
939
939
)
940
- message_body = f' Use this link to log in:\n\n{url}'
940
+ message_body = f" Use this link to log in:\n\n{url}"
941
941
send_mail(
942
- ' Your login link for Superlists' ,
942
+ " Your login link for Superlists" ,
943
943
message_body,
944
- ' noreply@superlists' ,
945
- [email]
944
+ " noreply@superlists" ,
945
+ [email],
946
946
)
947
947
[...]
948
948
----
@@ -1849,18 +1849,17 @@ Let's just make sure our base template shows a different nav bar for logged-in
1849
1849
and non–logged-in users (which our FT relies on):
1850
1850
1851
1851
[role="sourcecode small-code"]
1852
- .lists/templates/base.html (ch17l046 )
1852
+ .lists/templates/base.html (ch19l046 )
1853
1853
====
1854
1854
[source,html]
1855
1855
----
1856
- <nav class="navbar navbar-default" role="navigation ">
1856
+ <nav class="navbar">
1857
1857
<div class="container-fluid">
1858
1858
<a class="navbar-brand" href="/">Superlists</a>
1859
1859
{% if user.email %}
1860
- <ul class="nav navbar-nav navbar-right">
1861
- <li class="navbar-text">Logged in as {{ user.email }}</li>
1862
- <li><a href="#">Log out</a></li>
1863
- </ul>
1860
+ <!-- TODO put in a ul -->
1861
+ <span class="navbar-text">Logged in as {{ user.email }}</span>
1862
+ <a href="#">Log out</a>
1864
1863
{% else %}
1865
1864
<form class="navbar-form navbar-right"
1866
1865
method="POST"
@@ -1912,22 +1911,23 @@ with our custom user model, as good a place to have it as any might be
1912
1911
====
1913
1912
[source,python]
1914
1913
----
1915
- from django.test import TestCase
1916
1914
from django.contrib import auth
1915
+ from django.test import TestCase
1916
+
1917
1917
from accounts.models import Token
1918
+
1918
1919
User = auth.get_user_model()
1919
1920
1920
1921
1921
1922
class UserModelTest(TestCase):
1922
-
1923
1923
def test_user_is_valid_with_email_only(self):
1924
1924
[...]
1925
1925
def test_email_is_primary_key(self):
1926
1926
[...]
1927
1927
1928
1928
def test_no_problem_with_auth_login(self):
1929
- user = User.objects.create(email=' [email protected] ' )
1930
- user.backend = ''
1929
+ user = User.objects.create(email=" [email protected] " )
1930
+ user.backend = ""
1931
1931
request = self.client.request().wsgi_request
1932
1932
auth.login(request, user) # should not raise
1933
1933
----
@@ -1952,6 +1952,7 @@ look through the Django source lines listed in the traceback, and have a read up
1952
1952
of Django's https://docs.djangoproject.com/en/1.11/topics/signals/[docs on
1953
1953
signals].
1954
1954
1955
+ // TODO this aint right
1955
1956
1956
1957
The upshot is that we can fix it like this:
1957
1958
@@ -2156,29 +2157,31 @@ http://bit.ly/SuI0hA[built-in logout view], which clears down the user's
2156
2157
session and redirects them to a page of our choice:
2157
2158
2158
2159
[role="sourcecode"]
2159
- .accounts/urls.py (ch17l051 )
2160
+ .accounts/urls.py (ch19l051 )
2160
2161
====
2161
2162
[source,python]
2162
2163
----
2163
- from django.contrib.auth.views import logout
2164
- [...]
2164
+ from django.contrib.auth import views as auth_views
2165
+ from django.urls import path
2166
+
2167
+ from . import views
2165
2168
2166
2169
urlpatterns = [
2167
- url(r'^ send_login_email$' , views.send_login_email, name=' send_login_email' ),
2168
- url(r'^ login$' , views.login, name=' login' ),
2169
- url(r'^ logout$', logout, {'next_page': '/'}, name=' logout' ),
2170
+ path(" send_login_email" , views.send_login_email, name=" send_login_email" ),
2171
+ path(" login" , views.login, name=" login" ),
2172
+ path(" logout", auth_views.LogoutView.as_view(), name=" logout" ),
2170
2173
]
2171
2174
----
2172
2175
====
2173
2176
2174
2177
And in 'base.html', we just make the logout into a real URL link:
2175
2178
2176
2179
[role="sourcecode"]
2177
- .lists/templates/base.html (ch17l052 )
2180
+ .lists/templates/base.html (ch19l052 )
2178
2181
====
2179
2182
[source,python]
2180
2183
----
2181
- <li>< a href="{% url 'logout' %}">Log out</a></li >
2184
+ < a href="{% url 'logout' %}">Log out</a>
2182
2185
----
2183
2186
====
2184
2187
0 commit comments