Skip to content

Commit 0460e47

Browse files
authored
refactor: refactor GenericList (#995)
1 parent e6b618b commit 0460e47

33 files changed

+734
-666
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
repos:
2-
- repo: https://github.com/charliermarsh/ruff-pre-commit
3-
rev: v0.1.13
4-
hooks:
5-
- id: ruff
6-
args: [--fix]
7-
- id: ruff-format
8-
- repo: https://github.com/djlint/djLint
9-
rev: v1.34.1
10-
hooks:
11-
- id: djlint-reformat-django
12-
- id: djlint-django
2+
- repo: https://github.com/charliermarsh/ruff-pre-commit
3+
rev: v0.1.13
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
- id: ruff-format
8+
- repo: https://github.com/adamchainz/djade-pre-commit
9+
rev: "1.3.2"
10+
hooks:
11+
- id: djade
12+
args: [--target-version, "5.1"]

bullet/bullet_admin/mixins.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
from typing import Callable, Protocol
2+
13
from competitions.models import Venue
24
from django.contrib.auth.views import redirect_to_login
35
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
46
from django.db.models import QuerySet
5-
from django.http import HttpResponseNotFound
7+
from django.http import HttpRequest, HttpResponseNotFound
68
from django.urls import reverse
9+
from users.models.organizers import User
710

811
from bullet_admin.utils import get_active_competition, get_redirect_url, is_admin
912

1013

11-
class AccessMixin:
14+
class MixinProtocol(Protocol):
15+
request: HttpRequest
16+
get_context_data: Callable[..., dict]
17+
get_object: Callable
18+
get_queryset: Callable
19+
get_model: Callable
20+
dispatch: Callable
21+
22+
23+
class AuthedHttpRequest(HttpRequest):
24+
user: User # type: ignore
25+
26+
27+
class AccessMixin(MixinProtocol):
1228
def can_access(self):
1329
raise NotImplementedError()
1430

bullet/bullet_admin/templates/bullet_admin/categories/max_teams_per_school.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

bullet/bullet_admin/templates/bullet_admin/components/country.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load components %}
2-
<div class="flex gap-2 items-center flex-wrap">
2+
<div class="flex gap-2 items-center shrink-0">
33
<span class="iconify shrink-0 shadow-lg"
44
data-icon="flag:{{ attributes.code|lower }}-4x3"></span>
55
<span>{{ attributes.name }}</span>
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{% load utils %}
2-
{% query_transform next=request.get_full_path as back %}
3-
<a href="{{ attributes.url }}{% if not attributes.disable_back %}{{ back }}{% endif %}"
4-
class="p-2 -m-2 {% if attributes.type == "edit" %} text-green-600 hover:text-green-400 {% elif attributes.type == "delete" %} text-red-600 hover:text-red-400 {% else %} text-blue-600 hover:text-blue-400 {% endif %}"
5-
title="{% if attributes.type == "edit" %}Edit{% elif attributes.type == "delete" %}Delete{% elif attributes.type == "view" %}View{% elif attributes.type == "history" %}History{% elif attributes.type == "internal-view" %}View{% elif attributes.type == "download" %}Download sources{% elif attributes.type == "generate" %}Generate documents{% endif %}">
6-
<span class="iconify w-5 h-5 shrink-0"
7-
data-icon="{% if attributes.type == "edit" %}mdi:square-edit-outline{% elif attributes.type == "delete" %}mdi:delete{% elif attributes.type == "view" %}mdi:export{% elif attributes.type == "history" %}mdi:history{% elif attributes.type == "internal-view" %}mdi:eye{% elif attributes.type == "download" %}mdi:download{% elif attributes.type == "generate" %}mdi:play{% endif %}"></span>
2+
<a href="{{ attributes.url }}"
3+
class="p-2 -m-2
4+
{% if attributes.color == "green" %}text-green-600 hover:text-green-800
5+
{% elif attributes.color == "red" %}text-red-600 hover:text-red-800
6+
{% elif attributes.color == "blue" %}text-blue-600 hover:text-blue-800{% endif %}"
7+
title="{{ attributes.label }}">
8+
<span class="iconify w-5 h-5 shrink-0" data-icon="{{ attributes.icon }}"></span>
89
</a>

bullet/bullet_admin/templates/bullet_admin/content/countries.html renamed to bullet/bullet_admin/templates/bullet_admin/content/field__countries.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load countries %}
2-
<div class="flex gap-4">
2+
<div class="flex gap-4 flex-wrap">
33
{% for country in object.countries %}
44
{% get_country country as country_info %}
55
{% #country name=country_info.name code=country_info.code %}

bullet/bullet_admin/templates/bullet_admin/content/language.html

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 52 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,58 @@
11
{% extends "bullet_admin/base.html" %}
2-
{% load countries %}
3-
{% load utils %}
4-
{% load i18n %}
5-
{% load badmin %}
6-
{% load access %}
2+
{% load access badmin countries i18n utils %}
73
{% block title %}
84
{{ list_title }}
95
{% endblock title %}
6+
107
{% block content %}
11-
{% get_active_competition as competition %}
12-
<div class="p-8 mx-auto max-w-7xl">
13-
{% aheader show_subtitle=subtitle is not None %}
14-
{% slot title %}
15-
{{ list_title }}
16-
{% if count %}
17-
<span class="text-gray-400 font-normal">{{ count|floatformat:"g" }}</span>
18-
{% endif %}
19-
{% endslot %}
20-
{% slot buttons %}
21-
{% query_replace next=request.get_full_path as back %}
22-
{% if help_url %}
23-
{% #abtn icon="mdi:help" label="Help" url=help_url|add:back %}
24-
{% endif %}
25-
{% if new_folder_url %}
26-
{% #abtn icon="mdi:folder-plus" label="New folder" url=new_folder_url|add:back %}
27-
{% endif %}
28-
{% if assign_numbers_url %}
29-
{% #abtn icon="mdi:numeric" label="Assign numbers" url=assign_numbers_url|add:back %}
30-
{% endif %}
31-
{% if export_url %}
32-
{% #abtn color="blue" icon="mdi:export" label="Export" url=export_url|add:back %}
33-
{% endif %}
34-
{% if create_url %}
35-
{% if object_name %}
36-
{% #abtn color="green" icon="mdi:plus" label="New "|add:object_name url=create_url|add:back %}
37-
{% else %}
38-
{% #abtn color="green" icon="mdi:plus" label="New" url=create_url|add:back %}
39-
{% endif %}
40-
{% endif %}
41-
{% if upload_url %}
42-
{% #abtn color="green" icon="mdi:upload" label="Upload File" url=upload_url|add:back %}
43-
{% endif %}
44-
{% comment %}
45-
Add buttons if needed.
46-
{% endcomment %}
47-
{% endslot %}
48-
{{ subtitle }}
49-
{% endaheader %}
50-
{% block navigation %}
51-
{% if countries %}
52-
{% anav class="-mt-4 mb-8" %}
53-
{% query_transform country="" as url %}
54-
{% if not request.GET.country %}
55-
{% anavitem url=url active=True %}
56-
(all)
57-
{% endanavitem %}
58-
{% else %}
59-
{% anavitem url=url active=False %}
60-
(all)
61-
{% endanavitem %}
62-
{% endif %}
63-
{% for country in countries %}
64-
{% get_country country as country_info %}
65-
{% query_transform country=country as url %}
66-
{% if request.GET.country == country %}
67-
{% anavitem url=url active=True %}
68-
<div class="flex gap-2 items-center flex-wrap">
69-
<span class="iconify shrink-0 shadow-lg"
70-
data-icon="flag:{{ country_info.code|lower }}-4x3"></span>
71-
<span>{{ country_info.name }}</span>
72-
</div>
73-
{% endanavitem %}
74-
{% else %}
75-
{% anavitem url=url active=False %}
76-
<div class="flex gap-2 items-center flex-wrap">
77-
<span class="iconify shrink-0 shadow-lg"
78-
data-icon="flag:{{ country_info.code|lower }}-4x3"></span>
79-
<span>{{ country_info.name }}</span>
80-
</div>
81-
{% endanavitem %}
82-
{% endif %}
83-
{% endfor %}
84-
{% endanav %}
85-
{% endif %}
86-
{% if languages %}
87-
{% anav class="-mt-4 mb-8" %}
88-
{% query_transform language="" as url %}
89-
{% if not request.GET.language %}
90-
{% anavitem url=url active=True %}
91-
(all)
92-
{% endanavitem %}
93-
{% else %}
94-
{% anavitem url=url active=False %}
95-
(all)
96-
{% endanavitem %}
97-
{% endif %}
98-
{% for lang in languages %}
99-
{% get_language_info for lang as lang_info %}
100-
{% query_transform language=lang as url %}
101-
{% if request.GET.language == lang %}
102-
{% anavitem url=url active=True %}
103-
{{ lang_info.name }}
104-
{% endanavitem %}
105-
{% else %}
106-
{% anavitem url=url active=False %}
107-
{{ lang_info.name }}
108-
{% endanavitem %}
109-
{% endif %}
110-
{% endfor %}
111-
{% endanav %}
112-
{% endif %}
113-
{% endblock navigation %}
114-
{% block before_list %}
115-
<form class="flex mb-4 items-center gap-2">
116-
{% for name, list in request.GET.lists %}
117-
{% if name != "q" %}
118-
<input type="hidden"
119-
name="{{ name }}"
120-
value="{{ list.0 }}">
121-
{% endif %}
122-
{% endfor %}
123-
<input type="search"
124-
name="q"
125-
placeholder="Search {{ list_title|lower }}"
126-
class="input"
127-
value="{{ request.GET.q }}">
128-
</form>
129-
{% endblock before_list %}
130-
<div class="overflow-x-auto">
131-
<table class="w-full text-sm">
132-
<thead class="text-left bg-gray-100 border-t border-b">
133-
<tr>
134-
{% for label, field in labels %}
135-
<th class="p-0 whitespace-nowrap">
136-
{% if orderby == field %}
137-
{% query_transform orderby="-"|add:field as url %}
138-
{% else %}
139-
{% query_transform orderby=field as url %}
140-
{% endif %}
141-
<a href="{{ url }}"
142-
class="p-3 pr-1 flex items-center hover:bg-gray-200">
143-
{{ label }}
144-
{% if orderby == field %}
145-
<span class="iconify w-5 h-5 shrink-0"
146-
data-icon="mdi:arrow-down-drop"></span>
147-
{% elif orderby == "-"|add:field %}
148-
<span class="iconify w-5 h-5 shrink-0"
149-
data-icon="mdi:arrow-drop-up"></span>
150-
{% endif %}
151-
</a>
152-
</th>
153-
{% endfor %}
154-
<th></th>
155-
</tr>
156-
</thead>
157-
<tbody class="divide-y">
158-
{% for object, edit_url, delete_url, view_url, download_url, generate_url in table_row %}
159-
<tr class="even:bg-gray-50 relative hover:bg-gray-100">
160-
{% for item in object %}
161-
<td class="p-3">
162-
{% if forloop.first %}
163-
{% if view_url %}
164-
<a class="link absolute inset-0"
165-
href="{{ view_url }}{% query_transform next=request.get_full_path %}"></a>
166-
{% elif edit_url %}
167-
<a class="link absolute inset-0"
168-
href="{{ edit_url }}{% query_transform next=request.get_full_path %}"></a>
169-
{% elif delete_url %}
170-
<a class="link absolute inset-0"
171-
href="{{ delete_url }}{% query_transform next=request.get_full_path %}"></a>
172-
{% endif %}
173-
{% endif %}
174-
{% if item or item == 0 %}{{ item }}{% endif %}
175-
</td>
176-
{% endfor %}
177-
<td class="p-3 whitespace-nowrap z-10 relative">
178-
<div class="flex items-center justify-end gap-2">
179-
{% if edit_url %}
180-
{% #alink type="edit" url=edit_url %}
181-
{% endif %}
182-
{% if delete_url %}
183-
{% #alink type="delete" url=delete_url %}
184-
{% endif %}
185-
{% if view_url %}
186-
{% #alink type=view_type url=view_url %}
187-
{% endif %}
188-
{% if download_url %}
189-
{% #alink type="download" url=download_url %}
190-
{% endif %}
191-
{% if generate_url %}
192-
{% #alink type="generate" url=generate_url %}
193-
{% endif %}
194-
</div>
195-
</td>
196-
</tr>
197-
{% endfor %}
198-
</tbody>
199-
</table>
200-
</div>
201-
{% admin_paginator page_obj %}
202-
</div>
8+
{% get_active_competition as competition %}
9+
<div class="p-8 mx-auto max-w-7xl">
10+
{% aheader show_subtitle=list_subtitle is not None %}
11+
{% slot title %}
12+
{{ list_title }}
13+
14+
{% if count %}
15+
<span class="text-gray-400 font-normal">{{ count|floatformat:"g" }}</span>
16+
{% endif %}
17+
{% endslot %}
18+
19+
{% slot buttons %}
20+
{% query_replace next=request.get_full_path as back %}
21+
{% for link in list_links %}
22+
{% #abtn icon=link.icon label=link.label color=link.color url=link.url|add:back %}
23+
{% endfor %}
24+
{% endslot %}
25+
26+
{{ list_subtitle }}
27+
{% endaheader %}
28+
29+
{% block navigation %}
30+
{% if countries %}
31+
{% include "bullet_admin/generic/list_countries.html" %}
32+
{% endif %}
33+
{% if languages %}
34+
{% include "bullet_admin/generic/list_languages.html" %}
35+
{% endif %}
36+
{% endblock navigation %}
37+
38+
{% block before_list %}
39+
<form class="flex mb-4 items-center gap-2">
40+
{% for name, list in request.GET.lists %}
41+
{% if name != "q" %}
42+
<input type="hidden"
43+
name="{{ name }}"
44+
value="{{ list.0 }}">
45+
{% endif %}
46+
{% endfor %}
47+
<input type="search"
48+
name="q"
49+
placeholder="Search {{ list_title|lower }}"
50+
class="input"
51+
value="{{ request.GET.q }}">
52+
</form>
53+
{% endblock before_list %}
54+
55+
{% include "bullet_admin/generic/list_table.html" %}
56+
{% admin_paginator page_obj %}
57+
</div>
20358
{% endblock content %}

0 commit comments

Comments
 (0)