Skip to content

Commit 7e37f22

Browse files
More types in example
1 parent 005a9ac commit 7e37f22

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Django>=3.2.6
2-
django-async-include==0.6.7
2+
django-async-include==0.6.10
33
django-ws-include==0.3.0
44
django-stubs>=1.9.0

shop_list/templates/shop_list/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1>Shop lists</h1>
2020
<a href="{% url 'shop_list:view_shop_list' shop_list.id %}">
2121
{{ shop_list.name }} ({{shop_list.created_at}})
2222
</a>
23-
{% async_include "shop_list/partials/item_list.html" shop_list=shop_list items=shop_list.item_set.all %}
23+
{% async_include "shop_list/partials/item_list.html" shop_list=shop_list items=shop_list.item_set.all food_group_percentages=food_group_percentages item_list_title=item_list_title item_list_title_em=12 item_list_title_color="red" request_time=request_time %}
2424
</li>
2525
{% endfor %}
2626
</ul>
Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
<div>
2-
<h2>Product list</h2>
3-
<ul>
4-
{% for item in items %}
5-
<li>
6-
{{ item.name }}
7-
</li>
2+
<h2 style="font-size: {{ item_list_title_em }}; color: {{ item_list_title_color }}">
3+
{{ item_list_title }}
4+
</h2>
5+
<div>
6+
<em>Requested at: {{ request_time }}</em>
7+
</div>
8+
{{ non_passed_variable }}
9+
<div>
10+
Remember the percentages (number of food groups: {{food_group_percentages|length}}):
11+
<ul>
12+
{% for group, perc in food_group_percentages.items %}
13+
<li>
14+
{{ group }} {{perc}} %
15+
</li>
816
{% endfor %}
9-
</ul>
17+
</ul>
18+
</div>
19+
<div>
20+
<ul>
21+
{% for item in items %}
22+
<li>
23+
{{ item.name }}
24+
</li>
25+
{% endfor %}
26+
</ul>
27+
</div>
1028
</div>

shop_list/views.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
from django.shortcuts import render, get_object_or_404
22
from django.http import HttpRequest, HttpResponse
33
from django.db.models.query import QuerySet
4+
from django.utils import timezone
5+
46
from shop_list.models import ShopList
57

68
DEFAULT_USE_WS = False
7-
DEFAULT_SHOP_LIST_SIZE = 100
8-
SHOP_LIST_SIZES = [20, 50, 100]
9+
DEFAULT_SHOP_LIST_SIZE = 1
10+
SHOP_LIST_SIZES = [1, 20, 50, 100]
911

1012

1113
def index(request: HttpRequest) -> HttpResponse:
1214
use_ws = bool(int(request.GET.get('use_ws', DEFAULT_USE_WS)))
1315
shop_list_size = int(request.GET.get('size', DEFAULT_SHOP_LIST_SIZE))
1416
shop_lists: QuerySet[ShopList] = ShopList.objects.all().order_by('-created_at')[:shop_list_size]
15-
replacements = {'shop_lists': shop_lists, 'sizes': SHOP_LIST_SIZES}
17+
replacements = {
18+
'shop_lists': shop_lists,
19+
'sizes': SHOP_LIST_SIZES,
20+
'food_group_percentages': {
21+
'Carbohydrates': 40,
22+
'Proteins': 35,
23+
'Fats': 25,
24+
},
25+
'item_list_title': 'Product list',
26+
'request_time': timezone.now()
27+
}
1628
if use_ws:
1729
template_path = 'shop_list/index_with_ws.html'
1830
else:
@@ -22,5 +34,8 @@ def index(request: HttpRequest) -> HttpResponse:
2234

2335
def view_shop_list(request: HttpRequest, shop_list_id: int) -> HttpResponse:
2436
shop_list = get_object_or_404(ShopList, id=shop_list_id)
25-
replacements = {'shop_list': shop_list, 'items': shop_list.item_set.all}
37+
replacements = {
38+
'shop_list': shop_list,
39+
'items': shop_list.item_set.all
40+
}
2641
return render(request, 'shop_list/view_shop_list.html', replacements)

0 commit comments

Comments
 (0)