Skip to content

Commit 0caf554

Browse files
committed
Fix tags dropdown on the homepage and abstract away logic
1 parent 55c52aa commit 0caf554

File tree

1 file changed

+19
-48
lines changed

1 file changed

+19
-48
lines changed

pgcommitfest/commitfest/views.py

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@
4949
)
5050

5151

52+
def get_tags_data():
53+
"""Generate JSON data for enhanced selectize dropdown with tag colors and descriptions."""
54+
return json.dumps(
55+
[
56+
{
57+
"id": tag.id,
58+
"name": tag.name,
59+
"color": tag.color,
60+
"description": tag.description,
61+
}
62+
for tag in Tag.objects.all().order_by("name")
63+
]
64+
)
65+
66+
5267
@transaction.atomic
5368
def home(request):
5469
curs = connection.cursor()
@@ -117,6 +132,7 @@ def home(request):
117132
"form": form,
118133
"patches": patch_list.patches,
119134
"statussummary": statussummary,
135+
"tags_data": get_tags_data(),
120136
"all_tags": {t.id: t for t in Tag.objects.all()},
121137
"has_filter": patch_list.has_filter,
122138
"grouping": patch_list.sortkey == 0,
@@ -605,21 +621,6 @@ def commitfest(request, cfid):
605621
# the user is logged in. XXX: Figure out how to avoid doing that..
606622
form = CommitFestFilterForm(request.GET)
607623

608-
# Prepare tag data for enhanced selectize dropdown
609-
import json
610-
611-
tags_data = json.dumps(
612-
[
613-
{
614-
"id": tag.id,
615-
"name": tag.name,
616-
"color": tag.color,
617-
"description": tag.description,
618-
}
619-
for tag in Tag.objects.all().order_by("name")
620-
]
621-
)
622-
623624
return render(
624625
request,
625626
"commitfest.html",
@@ -628,7 +629,7 @@ def commitfest(request, cfid):
628629
"form": form,
629630
"patches": patch_list.patches,
630631
"statussummary": statussummary,
631-
"tags_data": tags_data,
632+
"tags_data": get_tags_data(),
632633
"all_tags": {t.id: t for t in Tag.objects.all()},
633634
"has_filter": patch_list.has_filter,
634635
"title": f"{cf.title} ({cf.periodstring})",
@@ -822,21 +823,6 @@ def patchform(request, patchid):
822823
else:
823824
form = PatchForm(instance=patch)
824825

825-
# Prepare tag data for enhanced selectize dropdown
826-
import json
827-
828-
tags_data = json.dumps(
829-
[
830-
{
831-
"id": tag.id,
832-
"name": tag.name,
833-
"color": tag.color,
834-
"description": tag.description,
835-
}
836-
for tag in Tag.objects.all().order_by("name")
837-
]
838-
)
839-
840826
return render(
841827
request,
842828
"base_form.html",
@@ -845,7 +831,7 @@ def patchform(request, patchid):
845831
"form": form,
846832
"patch": patch,
847833
"title": "Edit patch",
848-
"tags_data": tags_data,
834+
"tags_data": get_tags_data(),
849835
"breadcrumbs": [
850836
{"title": cf.title, "href": "/%s/" % cf.pk},
851837
{"title": "View patch", "href": "/%s/%s/" % (cf.pk, patch.pk)},
@@ -894,28 +880,13 @@ def newpatch(request, cfid):
894880
else:
895881
form = NewPatchForm(request=request)
896882

897-
# Prepare tag data for enhanced selectize dropdown
898-
import json
899-
900-
tags_data = json.dumps(
901-
[
902-
{
903-
"id": tag.id,
904-
"name": tag.name,
905-
"color": tag.color,
906-
"description": tag.description,
907-
}
908-
for tag in Tag.objects.all().order_by("name")
909-
]
910-
)
911-
912883
return render(
913884
request,
914885
"base_form.html",
915886
{
916887
"form": form,
917888
"title": "New patch",
918-
"tags_data": tags_data,
889+
"tags_data": get_tags_data(),
919890
"breadcrumbs": [
920891
{"title": f"{cf.title} ({cf.periodstring})", "href": "/%s/" % cf.pk},
921892
],

0 commit comments

Comments
 (0)