Skip to content

Commit b704759

Browse files
committed
Add number of resources per label
1 parent 2c3024b commit b704759

4 files changed

Lines changed: 43 additions & 28 deletions

File tree

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
@import 'apps/commons/static/commons/css/base';
22

3-
ul {
4-
margin-top: 1rem;
3+
a.label {
4+
display: inline-block;
5+
font-size: 13px;
6+
padding-top: 3px;
7+
padding-bottom: 3px;
8+
padding-left: 9px;
9+
padding-right: 9px;
10+
border-radius: 10px;
511

6-
&.resources {
7-
li {
8-
list-style: initial;
9-
margin-left: 20px;
10-
}
12+
&:hover {
13+
background-color: #154360 !important;
14+
color: white !important;
1115
}
1216

13-
.label {
14-
display: inline-block;
15-
font-size: 13px;
16-
padding-left: 9px;
17-
padding-right: 9px;
18-
border-radius: 10px;
19-
20-
&:hover {
21-
background-color: #154360 !important;
22-
a {
23-
color: white !important;
24-
}
25-
}
17+
span.badge {
18+
background-color: rgba(255, 255, 255, 0.518);
19+
margin-left: 3px;
20+
border-radius: 12px;
21+
padding-top: 2px;
22+
padding-bottom: 2px;
23+
padding-left: 3px;
24+
padding-right: 3px;
2625
}
2726
}
2827

28+
ul {
29+
margin-top: 1rem;
30+
}
31+
2932
.learn-index {
3033
ul li i {
3134
padding-right: 10px;
@@ -38,7 +41,14 @@ ul {
3841
}
3942

4043
.learn-resources_by_label {
41-
.resource {
44+
a.resource {
4245
margin-right: 1rem;
4346
}
47+
48+
ul.resources {
49+
li {
50+
list-style: initial;
51+
margin-left: 20px;
52+
}
53+
}
4454
}

apps/learn/templates/learn/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ <h1 class="title">Aprende Python</h1>
1515
<ul>
1616
{% for label in labels %}
1717
<li>
18-
<span class="label" style="background-color: #{{ label.color }}">
19-
<a style="color: #{{ label.foreground_color }}" href="{% url "learn:resources_by_label" label=label %}">{{ label }}</a>
20-
</span>
18+
<a class="label"
19+
style="background-color: #{{ label.color }}; color: #{{ label.foreground_color }}"
20+
href="{% url "learn:resources_by_label" label=label %}">
21+
{{ label }}
22+
<span class="badge">{{ label.resources.all.count }}</span>
23+
</a>
2124
</li>
2225
{% endfor %}
2326
</ul>

apps/learn/templates/learn/resources_by_label.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ <h1 class="title"><i class="fas fa-tag"></i> {{ label }}</h1>
2222
<li>
2323
<a class="resource" href="{{ resource.url }}">{{ resource }}</a>
2424
{% for label in resource.labels.all %}
25-
<span class="label" style="background-color: #{{ label.color }}">
26-
<a style="color: #{{ label.foreground_color }}" href="{% url "learn:resources_by_label" label=label %}">{{ label }}</a>
27-
</span>
25+
<a class="label"
26+
style="background-color: #{{ label.color }}; color: #{{ label.foreground_color }}"
27+
href="{% url "learn:resources_by_label" label=label %}">
28+
{{ label }}
29+
</a>
2830
{% endfor %}
2931
</li>
3032
{% endfor %}

apps/learn/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def index(request):
7-
labels = Label.objects.all()
7+
labels = Label.objects.prefetch_related('resources').all()
88
return render(request, 'learn/index.html', {'labels': labels})
99

1010

0 commit comments

Comments
 (0)