Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/djlint/djLint
rev: v1.34.1
hooks:
- id: djlint-reformat-django
- id: djlint-django
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/adamchainz/djade-pre-commit
rev: "1.3.2"
hooks:
- id: djade
args: [--target-version, "5.1"]
20 changes: 18 additions & 2 deletions bullet/bullet_admin/mixins.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
from typing import Callable, Protocol

from competitions.models import Venue
from django.contrib.auth.views import redirect_to_login
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.db.models import QuerySet
from django.http import HttpResponseNotFound
from django.http import HttpRequest, HttpResponseNotFound
from django.urls import reverse
from users.models.organizers import User

from bullet_admin.utils import get_active_competition, get_redirect_url, is_admin


class AccessMixin:
class MixinProtocol(Protocol):
request: HttpRequest
get_context_data: Callable[..., dict]
get_object: Callable
get_queryset: Callable
get_model: Callable
dispatch: Callable


class AuthedHttpRequest(HttpRequest):
user: User # type: ignore


class AccessMixin(MixinProtocol):
def can_access(self):
raise NotImplementedError()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load components %}
<div class="flex gap-2 items-center flex-wrap">
<div class="flex gap-2 items-center shrink-0">
<span class="iconify shrink-0 shadow-lg"
data-icon="flag:{{ attributes.code|lower }}-4x3"></span>
<span>{{ attributes.name }}</span>
Expand Down
13 changes: 7 additions & 6 deletions bullet/bullet_admin/templates/bullet_admin/components/link.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% load utils %}
{% query_transform next=request.get_full_path as back %}
<a href="{{ attributes.url }}{% if not attributes.disable_back %}{{ back }}{% endif %}"
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 %}"
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 %}">
<span class="iconify w-5 h-5 shrink-0"
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>
<a href="{{ attributes.url }}"
class="p-2 -m-2
{% if attributes.color == "green" %}text-green-600 hover:text-green-800
{% elif attributes.color == "red" %}text-red-600 hover:text-red-800
{% elif attributes.color == "blue" %}text-blue-600 hover:text-blue-800{% endif %}"
title="{{ attributes.label }}">
<span class="iconify w-5 h-5 shrink-0" data-icon="{{ attributes.icon }}"></span>
</a>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load countries %}
<div class="flex gap-4">
<div class="flex gap-4 flex-wrap">
{% for country in object.countries %}
{% get_country country as country_info %}
{% #country name=country_info.name code=country_info.code %}
Expand Down

This file was deleted.

249 changes: 52 additions & 197 deletions bullet/bullet_admin/templates/bullet_admin/generic/list.html
Original file line number Diff line number Diff line change
@@ -1,203 +1,58 @@
{% extends "bullet_admin/base.html" %}
{% load countries %}
{% load utils %}
{% load i18n %}
{% load badmin %}
{% load access %}
{% load access badmin countries i18n utils %}
{% block title %}
{{ list_title }}
{% endblock title %}

{% block content %}
{% get_active_competition as competition %}
<div class="p-8 mx-auto max-w-7xl">
{% aheader show_subtitle=subtitle is not None %}
{% slot title %}
{{ list_title }}
{% if count %}
<span class="text-gray-400 font-normal">{{ count|floatformat:"g" }}</span>
{% endif %}
{% endslot %}
{% slot buttons %}
{% query_replace next=request.get_full_path as back %}
{% if help_url %}
{% #abtn icon="mdi:help" label="Help" url=help_url|add:back %}
{% endif %}
{% if new_folder_url %}
{% #abtn icon="mdi:folder-plus" label="New folder" url=new_folder_url|add:back %}
{% endif %}
{% if assign_numbers_url %}
{% #abtn icon="mdi:numeric" label="Assign numbers" url=assign_numbers_url|add:back %}
{% endif %}
{% if export_url %}
{% #abtn color="blue" icon="mdi:export" label="Export" url=export_url|add:back %}
{% endif %}
{% if create_url %}
{% if object_name %}
{% #abtn color="green" icon="mdi:plus" label="New "|add:object_name url=create_url|add:back %}
{% else %}
{% #abtn color="green" icon="mdi:plus" label="New" url=create_url|add:back %}
{% endif %}
{% endif %}
{% if upload_url %}
{% #abtn color="green" icon="mdi:upload" label="Upload File" url=upload_url|add:back %}
{% endif %}
{% comment %}
Add buttons if needed.
{% endcomment %}
{% endslot %}
{{ subtitle }}
{% endaheader %}
{% block navigation %}
{% if countries %}
{% anav class="-mt-4 mb-8" %}
{% query_transform country="" as url %}
{% if not request.GET.country %}
{% anavitem url=url active=True %}
(all)
{% endanavitem %}
{% else %}
{% anavitem url=url active=False %}
(all)
{% endanavitem %}
{% endif %}
{% for country in countries %}
{% get_country country as country_info %}
{% query_transform country=country as url %}
{% if request.GET.country == country %}
{% anavitem url=url active=True %}
<div class="flex gap-2 items-center flex-wrap">
<span class="iconify shrink-0 shadow-lg"
data-icon="flag:{{ country_info.code|lower }}-4x3"></span>
<span>{{ country_info.name }}</span>
</div>
{% endanavitem %}
{% else %}
{% anavitem url=url active=False %}
<div class="flex gap-2 items-center flex-wrap">
<span class="iconify shrink-0 shadow-lg"
data-icon="flag:{{ country_info.code|lower }}-4x3"></span>
<span>{{ country_info.name }}</span>
</div>
{% endanavitem %}
{% endif %}
{% endfor %}
{% endanav %}
{% endif %}
{% if languages %}
{% anav class="-mt-4 mb-8" %}
{% query_transform language="" as url %}
{% if not request.GET.language %}
{% anavitem url=url active=True %}
(all)
{% endanavitem %}
{% else %}
{% anavitem url=url active=False %}
(all)
{% endanavitem %}
{% endif %}
{% for lang in languages %}
{% get_language_info for lang as lang_info %}
{% query_transform language=lang as url %}
{% if request.GET.language == lang %}
{% anavitem url=url active=True %}
{{ lang_info.name }}
{% endanavitem %}
{% else %}
{% anavitem url=url active=False %}
{{ lang_info.name }}
{% endanavitem %}
{% endif %}
{% endfor %}
{% endanav %}
{% endif %}
{% endblock navigation %}
{% block before_list %}
<form class="flex mb-4 items-center gap-2">
{% for name, list in request.GET.lists %}
{% if name != "q" %}
<input type="hidden"
name="{{ name }}"
value="{{ list.0 }}">
{% endif %}
{% endfor %}
<input type="search"
name="q"
placeholder="Search {{ list_title|lower }}"
class="input"
value="{{ request.GET.q }}">
</form>
{% endblock before_list %}
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="text-left bg-gray-100 border-t border-b">
<tr>
{% for label, field in labels %}
<th class="p-0 whitespace-nowrap">
{% if orderby == field %}
{% query_transform orderby="-"|add:field as url %}
{% else %}
{% query_transform orderby=field as url %}
{% endif %}
<a href="{{ url }}"
class="p-3 pr-1 flex items-center hover:bg-gray-200">
{{ label }}
{% if orderby == field %}
<span class="iconify w-5 h-5 shrink-0"
data-icon="mdi:arrow-down-drop"></span>
{% elif orderby == "-"|add:field %}
<span class="iconify w-5 h-5 shrink-0"
data-icon="mdi:arrow-drop-up"></span>
{% endif %}
</a>
</th>
{% endfor %}
<th></th>
</tr>
</thead>
<tbody class="divide-y">
{% for object, edit_url, delete_url, view_url, download_url, generate_url in table_row %}
<tr class="even:bg-gray-50 relative hover:bg-gray-100">
{% for item in object %}
<td class="p-3">
{% if forloop.first %}
{% if view_url %}
<a class="link absolute inset-0"
href="{{ view_url }}{% query_transform next=request.get_full_path %}"></a>
{% elif edit_url %}
<a class="link absolute inset-0"
href="{{ edit_url }}{% query_transform next=request.get_full_path %}"></a>
{% elif delete_url %}
<a class="link absolute inset-0"
href="{{ delete_url }}{% query_transform next=request.get_full_path %}"></a>
{% endif %}
{% endif %}
{% if item or item == 0 %}{{ item }}{% endif %}
</td>
{% endfor %}
<td class="p-3 whitespace-nowrap z-10 relative">
<div class="flex items-center justify-end gap-2">
{% if edit_url %}
{% #alink type="edit" url=edit_url %}
{% endif %}
{% if delete_url %}
{% #alink type="delete" url=delete_url %}
{% endif %}
{% if view_url %}
{% #alink type=view_type url=view_url %}
{% endif %}
{% if download_url %}
{% #alink type="download" url=download_url %}
{% endif %}
{% if generate_url %}
{% #alink type="generate" url=generate_url %}
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% admin_paginator page_obj %}
</div>
{% get_active_competition as competition %}
<div class="p-8 mx-auto max-w-7xl">
{% aheader show_subtitle=list_subtitle is not None %}
{% slot title %}
{{ list_title }}

{% if count %}
<span class="text-gray-400 font-normal">{{ count|floatformat:"g" }}</span>
{% endif %}
{% endslot %}

{% slot buttons %}
{% query_replace next=request.get_full_path as back %}
{% for link in list_links %}
{% #abtn icon=link.icon label=link.label color=link.color url=link.url|add:back %}
{% endfor %}
{% endslot %}

{{ list_subtitle }}
{% endaheader %}

{% block navigation %}
{% if countries %}
{% include "bullet_admin/generic/list_countries.html" %}
{% endif %}
{% if languages %}
{% include "bullet_admin/generic/list_languages.html" %}
{% endif %}
{% endblock navigation %}

{% block before_list %}
<form class="flex mb-4 items-center gap-2">
{% for name, list in request.GET.lists %}
{% if name != "q" %}
<input type="hidden"
name="{{ name }}"
value="{{ list.0 }}">
{% endif %}
{% endfor %}
<input type="search"
name="q"
placeholder="Search {{ list_title|lower }}"
class="input"
value="{{ request.GET.q }}">
</form>
{% endblock before_list %}

{% include "bullet_admin/generic/list_table.html" %}
{% admin_paginator page_obj %}
</div>
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% load countries utils %}

{% anav class="-mt-4 mb-8" %}
{% query_transform country="" as url %}

{% if not request.GET.country %}
{% anavitem url=url active=True %}
(all)
{% endanavitem %}
{% else %}
{% anavitem url=url active=False %}
(all)
{% endanavitem %}
{% endif %}

{% for country in countries %}
{% get_country country as country_info %}
{% query_transform country=country as url %}

{% if request.GET.country == country %}
{% anavitem url=url active=True %}
<div class="flex gap-2 items-center flex-wrap">
<span class="iconify shrink-0 shadow-lg"
data-icon="flag:{{ country_info.code|lower }}-4x3"></span>
<span>{{ country_info.name }}</span>
</div>
{% endanavitem %}
{% else %}
{% anavitem url=url active=False %}
<div class="flex gap-2 items-center flex-wrap">
<span class="iconify shrink-0 shadow-lg"
data-icon="flag:{{ country_info.code|lower }}-4x3"></span>
<span>{{ country_info.name }}</span>
</div>
{% endanavitem %}
{% endif %}
{% endfor %}
{% endanav %}
Loading
Loading