@@ -386,6 +386,8 @@ Currently there's no place in our base template for us to put any new content.
386
386
Also, the "My Lists" page doesn't need the new item form,
387
387
so we'll put that into a block too, making it optional:
388
388
389
+
390
+
389
391
[role="sourcecode"]
390
392
.src/lists/templates/base.html (ch22l011-1)
391
393
====
@@ -442,6 +444,8 @@ so we'll put that into a block too, making it optional:
442
444
Meanwhile, in _my_lists.html_ we override the `list_form`
443
445
and say it should be empty...
444
446
447
+ // TODO: proper commits for these
448
+
445
449
[role="sourcecode"]
446
450
.src/lists/templates/my_lists.html
447
451
====
@@ -540,18 +544,20 @@ In this case, the list owner:
540
544
[source,python]
541
545
----
542
546
from django.contrib.auth import get_user_model
547
+
543
548
User = get_user_model()
544
549
[...]
545
- class MyListsTest(TestCase):
546
550
551
+
552
+ class MyListsTest(TestCase):
547
553
def test_my_lists_url_renders_my_lists_template(self):
548
554
[...]
549
555
550
556
def test_passes_correct_owner_to_template(self):
551
- User.objects.create(email=' [email protected] ' )
552
- correct_user = User.objects.create(email=' [email protected] ' )
553
- response = self.client.get(' /lists/users/[email protected] /' )
554
- self.assertEqual(response.context[' owner' ], correct_user)
557
+ User.objects.create(email=" [email protected] " )
558
+ correct_user = User.objects.create(email=" [email protected] " )
559
+ response = self.client.get(" /lists/users/[email protected] /" )
560
+ self.assertEqual(response.context[" owner" ], correct_user)
555
561
----
556
562
====
557
563
@@ -569,12 +575,14 @@ So:
569
575
[source,python]
570
576
----
571
577
from django.contrib.auth import get_user_model
578
+
572
579
User = get_user_model()
573
580
[...]
574
581
582
+
575
583
def my_lists(request, email):
576
584
owner = User.objects.get(email=email)
577
- return render(request, ' my_lists.html' , {' owner' : owner})
585
+ return render(request, " my_lists.html" , {" owner" : owner})
578
586
----
579
587
====
580
588
@@ -588,7 +596,7 @@ the previous test. We just need to add a user for it as well:
588
596
[source,python]
589
597
----
590
598
def test_my_lists_url_renders_my_lists_template(self):
591
- User.objects.create(email=' [email protected] ' )
599
+ User.objects.create(email=" [email protected] " )
592
600
[...]
593
601
----
594
602
====
@@ -666,7 +674,8 @@ But it won't actually work, because we don't know how to save a list owner yet:
666
674
667
675
668
676
----
669
- self.assertEqual(list_.owner, user)
677
+ self.assertEqual(new_list.owner, user)
678
+ ^^^^^^^^^^^^^^
670
679
AttributeError: 'List' object has no attribute 'owner'
671
680
----
672
681
@@ -722,30 +731,31 @@ Let's write a test for that:
722
731
723
732
724
733
[role="sourcecode"]
725
- .lists/tests/test_models.py (ch22l018)
734
+ .src/ lists/tests/test_models.py (ch22l018)
726
735
====
727
736
[source,python]
728
737
----
729
738
from django.contrib.auth import get_user_model
739
+
730
740
User = get_user_model()
731
741
[...]
732
742
733
- class ListModelTest(TestCase):
734
743
744
+ class ListModelTest(TestCase):
735
745
def test_get_absolute_url(self):
736
746
[...]
737
747
738
748
def test_lists_can_have_owners(self):
739
- user = User.objects.create(email=' [email protected] ' )
740
- list_ = List.objects.create(owner=user)
741
- self.assertIn(list_ , user.list_set.all())
749
+ user = User.objects.create(email=" [email protected] " )
750
+ mylist = List.objects.create(owner=user)
751
+ self.assertIn(mylist , user.list_set.all())
742
752
----
743
753
====
744
754
745
755
And that gives us a new unit test failure:
746
756
747
757
----
748
- list_ = List.objects.create(owner=user)
758
+ mylist = List.objects.create(owner=user)
749
759
[...]
750
760
TypeError: 'owner' is an invalid keyword argument for this function
751
761
----
@@ -768,7 +778,7 @@ that too:
768
778
769
779
770
780
[role="sourcecode"]
771
- .lists/tests/test_models.py (ch22l020)
781
+ .src/ lists/tests/test_models.py (ch22l020)
772
782
====
773
783
[source,python]
774
784
----
@@ -780,7 +790,7 @@ that too:
780
790
The correct implementation is this:
781
791
782
792
[role="sourcecode"]
783
- .lists/models.py (ch22l021)
793
+ .src/ lists/models.py (ch22l021)
784
794
====
785
795
[source,python]
786
796
----
@@ -845,7 +855,7 @@ Django represents users using a class called `AnonymousUser`, whose
845
855
846
856
847
857
[role="sourcecode"]
848
- .lists/views.py (ch22l023)
858
+ .src/ lists/views.py (ch22l023)
849
859
====
850
860
[source,python]
851
861
----
@@ -891,7 +901,7 @@ which wanted to be able to access a list "name" based on the text of
891
901
its first item:
892
902
893
903
[role="sourcecode"]
894
- .lists/tests/test_models.py (ch19l024)
904
+ .src/ lists/tests/test_models.py (ch19l024)
895
905
====
896
906
[source,python]
897
907
----
@@ -905,7 +915,7 @@ its first item:
905
915
906
916
907
917
[role="sourcecode"]
908
- .lists/models.py (ch19l025)
918
+ .src/ lists/models.py (ch19l025)
909
919
====
910
920
[source,python]
911
921
----
0 commit comments