File tree Expand file tree Collapse file tree 4 files changed +18
-14
lines changed
tests/pytest/pems/districts Expand file tree Collapse file tree 4 files changed +18
-14
lines changed Original file line number Diff line number Diff line change 1
1
{% extends "districts/index.html" %}
2
2
3
3
{% block headline %}
4
- District {{ url_district }} - {{ district_query .name }}
4
+ District {{ district_number }} - {{ district .name }}
5
5
{% endblock headline %}
6
6
7
7
{% block district-content %}
@@ -15,7 +15,7 @@ <h2>Chart</h2>
15
15
</ div >
16
16
< div class ="row ">
17
17
< div class ="col-lg-4 border ">
18
- < h2 > Details for {{ district_query .name }}</ h2 >
18
+ < h2 > Details for {{ district .name }}</ h2 >
19
19
</ div >
20
20
< div class ="col-lg-8 border ">
21
21
< h2 > Map</ h2 >
Original file line number Diff line number Diff line change 11
11
<!-- Side navigation -->
12
12
< nav aria-labelledby ="navigation-list " class ="side-navigation ">
13
13
< ul class ="list-navigation ">
14
- {% for district in district_queryset %}
14
+ {% for district in districts.all %}
15
15
< li >
16
16
< a href ="{% url 'districts:district' district.number %} "> District {{ district.number }}</ a >
17
17
</ li >
Original file line number Diff line number Diff line change 3
3
from .models import District
4
4
5
5
6
- class IndexView (TemplateView ):
7
- template_name = "districts/index.html"
6
+ class DistrictContextMixin :
8
7
9
8
def get_context_data (self , ** kwargs ):
10
9
context = super ().get_context_data (** kwargs )
11
- context ["district_queryset" ] = District .objects .all ()
10
+ districts_ctx = {}
11
+ districts_ctx ["all" ] = District .objects .all ()
12
+ context ["districts" ] = districts_ctx
12
13
return context
13
14
14
15
15
- class DistrictView (TemplateView ):
16
+ class IndexView (DistrictContextMixin , TemplateView ):
17
+ template_name = "districts/index.html"
18
+
19
+
20
+ class DistrictView (DistrictContextMixin , TemplateView ):
16
21
template_name = "districts/district.html"
17
22
18
23
def get_context_data (self , ** kwargs ):
19
24
context = super ().get_context_data (** kwargs )
20
- district = self .kwargs .get ("district" )
21
- context ["url_district" ] = district
22
- context ["district_queryset" ] = District .objects .all ()
23
- context ["district_query" ] = District .objects .all ().get (number = district )
25
+ district_number = self .kwargs .get ("district" )
26
+ context ["district_number" ] = district_number
27
+ context ["district" ] = context .get ("districts" ).get ("all" ).get (number = district_number )
24
28
return context
Original file line number Diff line number Diff line change 4
4
from pems .districts .models import District
5
5
6
6
7
- class TestIndexViewView :
7
+ class TestIndexView :
8
8
@pytest .fixture
9
9
def view (app_request ):
10
10
v = views .IndexView ()
@@ -17,7 +17,7 @@ def test_get_context_data(self, view):
17
17
18
18
context = view .get_context_data ()
19
19
20
- assert set (context [ "district_queryset" ] ) == set (District .objects .all ())
20
+ assert set (context . get ( "districts" ). get ( "all" ) ) == set (District .objects .all ())
21
21
22
22
def test_template_name (self , view ):
23
23
assert view .template_name == "districts/index.html"
@@ -37,7 +37,7 @@ def test_get_context_data(self, view):
37
37
38
38
context = view .get_context_data ()
39
39
40
- assert context ["url_district " ] == 1
40
+ assert context ["district_number " ] == 1
41
41
42
42
def test_template_name (self , view ):
43
43
assert view .template_name == "districts/district.html"
You can’t perform that action at this time.
0 commit comments