From 68caea5937cc43b598638967ad1ec8aacd532387 Mon Sep 17 00:00:00 2001 From: "Andrew K. Choi" Date: Wed, 6 Aug 2025 11:55:15 +0900 Subject: [PATCH 1/5] add_participants: Refactor admin interface for participant management --- lottery/draw/admin.py | 24 +++- lottery/draw/forms.py | 2 +- lottery/templates/admin/add_participants.html | 106 +++++++++--------- 3 files changed, 76 insertions(+), 56 deletions(-) diff --git a/lottery/draw/admin.py b/lottery/draw/admin.py index 9bacd3a..9c6ebc3 100644 --- a/lottery/draw/admin.py +++ b/lottery/draw/admin.py @@ -20,6 +20,8 @@ from bot.utils import create_bot_instance from .views import view_draw_results import os +from django.db.models import Q + logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) if not logger.handlers: @@ -36,9 +38,11 @@ def add_participants_view(request): return HttpResponse("Не указан параметр lottery_id", status=400) lottery = get_object_or_404(Lottery, id=lottery_id) + # Все доступные счета, не участвующие в этой лотерее used_invoice_ids = LotteryParticipant.objects.filter(lottery=lottery).values_list("invoice_id", flat=True) qs = Invoice.objects.filter(used=False).exclude(id__in=used_invoice_ids) + # Фильтрация deposit_min = request.GET.get("deposit_min") deposit_max = request.GET.get("deposit_max") created_after = request.GET.get("created_after") @@ -48,21 +52,30 @@ def add_participants_view(request): qs = qs.filter(deposit_sum__gte=deposit_min) if deposit_max: qs = qs.filter(deposit_sum__lte=deposit_max) + if created_after: try: dt = parse_date(created_after) if dt: - qs = qs.filter(created_at__gte=dt) + qs = qs.filter(created_at__date__gte=dt) except ValueError: pass + if created_before: try: dt = parse_date(created_before) if dt: - qs = qs.filter(created_at__lte=dt) + qs = qs.filter(created_at__date__lte=dt) except ValueError: pass + if request.GET.get("without_bonus"): + qs = qs.filter(Q(bonus__isnull=True) | Q(bonus=0)) + + if request.GET.get("without_fd"): + qs = qs.filter(Q(start_bonus__isnull=True) | Q(start_bonus=0)) + + # Обработка формы if request.method == "POST": form = AddParticipantsForm(request.POST) form.fields["invoices"].queryset = qs @@ -78,10 +91,13 @@ def add_participants_view(request): form = AddParticipantsForm() form.fields["invoices"].queryset = qs - context = {"form": form, "lottery": lottery} + context = { + "form": form, + "lottery": lottery, + "invoice_count": qs.count(), # Для отображения числа найденных + } return render(request, "admin/add_participants.html", context) - def get_client_by_invoice(invoice): try: return Client.objects.get(club_card_number=invoice.client_club_card_number) diff --git a/lottery/draw/forms.py b/lottery/draw/forms.py index 69edc69..fdc0c5f 100644 --- a/lottery/draw/forms.py +++ b/lottery/draw/forms.py @@ -6,7 +6,7 @@ class AddParticipantsForm(forms.Form): deposit_min = forms.DecimalField(label="Минимальный депозит", required=False) deposit_max = forms.DecimalField(label="Максимальный депозит", required=False) invoices = forms.ModelMultipleChoiceField( - queryset=Invoice.objects.none(), + queryset=Invoice.objects.none(), # устанавливается в представлении widget=forms.CheckboxSelectMultiple, required=False, label="Доступные счета" diff --git a/lottery/templates/admin/add_participants.html b/lottery/templates/admin/add_participants.html index d693b28..f29dfc2 100644 --- a/lottery/templates/admin/add_participants.html +++ b/lottery/templates/admin/add_participants.html @@ -48,6 +48,18 @@ + +
+
+ + +
+
+ + +
+
+
@@ -55,59 +67,51 @@

Найдено подходящих счетов: {{ invoice_count }}

- -
- {% csrf_token %} -
- - - - - - - - - - - - - - - - - - {% for invoice in form.fields.invoices.queryset %} + + + {% csrf_token %} +
+
СозданЗакрытСчетКлиентНомер клиентаСумма счетаБонусФДДепозитПримечание
+ - - - - - - - - - - - + + + + + + + + + + + - {% empty %} - - - - {% endfor %} - -
{{ invoice.created_at|date:"d.m.Y H:i" }} - {% if invoice.closed_at %} - {{ invoice.closed_at|date:"d.m.Y H:i" }} - {% else %} - — - {% endif %} - {{ invoice.ext_id|default:"—" }}{{ invoice.client.name|default:"Не указан" }}{{ invoice.client.club_card_number|default:"—" }}{{ invoice.sum|default:"—" }}{{ invoice.bonus|default:"—" }}{{ invoice.start_bonus|default:"—" }}{{ invoice.deposit_sum|default:"—" }}{{ invoice.notes|default:"—" }}СозданЗакрытСчётКлиентНомер клиентаСумма счетаБонусФДДепозитПримечание
Нет доступных счетов
-
- -
- - + + + {% for invoice in form.fields.invoices.queryset %} + + + {{ invoice.created_at|date:"d.m.Y H:i" }} + {% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i" }}{% else %}—{% endif %} + {{ invoice.ext_id|default:"—" }} + {{ invoice.client.name|default:"Не указан" }} + {{ invoice.client.club_card_number|default:"—" }} + {{ invoice.sum|default:"—" }} + {{ invoice.bonus|default:"—" }} + {{ invoice.start_bonus|default:"—" }} + {{ invoice.deposit_sum|default:"—" }} + {{ invoice.notes|default:"—" }} + + {% empty %} + + Нет доступных счетов + + {% endfor %} + + + + + Вернуться к списку участников From 023966bc5b65f9c2c495385439c45c7eb5324e19 Mon Sep 17 00:00:00 2001 From: "Andrew K. Choi" Date: Wed, 6 Aug 2025 12:02:48 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BB=D0=BE=D1=82=D0=B5=D1=80=D0=B5=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lottery/templates/admin/add_participants.html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lottery/templates/admin/add_participants.html b/lottery/templates/admin/add_participants.html index f29dfc2..5694254 100644 --- a/lottery/templates/admin/add_participants.html +++ b/lottery/templates/admin/add_participants.html @@ -94,8 +94,21 @@ {{ invoice.created_at|date:"d.m.Y H:i" }} {% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i" }}{% else %}—{% endif %} {{ invoice.ext_id|default:"—" }} - {{ invoice.client.name|default:"Не указан" }} - {{ invoice.client.club_card_number|default:"—" }} + {{ invoice.ext_id|default:"—" }} + + {% if invoice.client %} + {{ invoice.client.name|default:"—" }} + {% else %} + Не указан + {% endif %} + + + {% if invoice.client %} + {{ invoice.client.club_card_number|default:"—" }} + {% else %} + — + {% endif %} + {{ invoice.sum|default:"—" }} {{ invoice.bonus|default:"—" }} {{ invoice.start_bonus|default:"—" }} From 8b37877b3e255bc18789bbcafd2f579a044d11b9 Mon Sep 17 00:00:00 2001 From: "Andrew K. Choi" Date: Wed, 6 Aug 2025 12:05:59 +0900 Subject: [PATCH 3/5] table rafactor --- lottery/templates/admin/add_participants.html | 99 +++++++++---------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/lottery/templates/admin/add_participants.html b/lottery/templates/admin/add_participants.html index 5694254..7f252f2 100644 --- a/lottery/templates/admin/add_participants.html +++ b/lottery/templates/admin/add_participants.html @@ -71,57 +71,54 @@
{% csrf_token %}
- - - - - - - - - - - - - - - - - - {% for invoice in form.fields.invoices.queryset %} - - - - - - - - - - - - - - - {% empty %} - - - - {% endfor %} - -
СозданЗакрытСчётКлиентНомер клиентаСумма счетаБонусФДДепозитПримечание
{{ invoice.created_at|date:"d.m.Y H:i" }}{% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i" }}{% else %}—{% endif %}{{ invoice.ext_id|default:"—" }}{{ invoice.ext_id|default:"—" }} - {% if invoice.client %} - {{ invoice.client.name|default:"—" }} - {% else %} - Не указан - {% endif %} - - {% if invoice.client %} - {{ invoice.client.club_card_number|default:"—" }} - {% else %} - — - {% endif %} - {{ invoice.sum|default:"—" }}{{ invoice.bonus|default:"—" }}{{ invoice.start_bonus|default:"—" }}{{ invoice.deposit_sum|default:"—" }}{{ invoice.notes|default:"—" }}
Нет доступных счетов
+ + + + + + + + + + + + + + + + + + {% for invoice in invoices %} + + + + + + + + + + + + + + {% empty %} + + {% endfor %} + +
СозданЗакрытСчетКлиентНомер клиентаСумма счетаБонусФДДепозитПримечание
{{ invoice.created_at|date:"Y-m-d H:i:s" }}{% if invoice.closed_at %}{{ invoice.closed_at|date:"Y-m-d H:i:s" }}{% else %}—{% endif %}{{ invoice.ext_id }} + {% if invoice.client %} + {{ invoice.client.name|default:"—" }} + {% else %} + Не указан + {% endif %} + + {% if invoice.client %} + {{ invoice.client.club_card_number|default:"—" }} + {% else %} + — + {% endif %} + {{ invoice.sum|floatformat:2 }}{{ invoice.bonus|floatformat:2|default:"—" }}{{ invoice.start_bonus|floatformat:2|default:"—" }}{{ invoice.deposit_sum|floatformat:2|default:"—" }}{{ invoice.notes|default:"—" }}
Нет доступных счетов
From 3f5c332ecd77b269950b0f86a94bfdbcfa636b1e Mon Sep 17 00:00:00 2001 From: "Andrew K. Choi" Date: Wed, 6 Aug 2025 12:09:14 +0900 Subject: [PATCH 4/5] table data dysplay fix --- lottery/templates/admin/add_participants.html | 86 ++++++++----------- 1 file changed, 38 insertions(+), 48 deletions(-) diff --git a/lottery/templates/admin/add_participants.html b/lottery/templates/admin/add_participants.html index 7f252f2..85c83bf 100644 --- a/lottery/templates/admin/add_participants.html +++ b/lottery/templates/admin/add_participants.html @@ -71,54 +71,44 @@
{% csrf_token %}
- - - - - - - - - - - - - - - - - - {% for invoice in invoices %} - - - - - - - - - - - - - - {% empty %} - - {% endfor %} - -
СозданЗакрытСчетКлиентНомер клиентаСумма счетаБонусФДДепозитПримечание
{{ invoice.created_at|date:"Y-m-d H:i:s" }}{% if invoice.closed_at %}{{ invoice.closed_at|date:"Y-m-d H:i:s" }}{% else %}—{% endif %}{{ invoice.ext_id }} - {% if invoice.client %} - {{ invoice.client.name|default:"—" }} - {% else %} - Не указан - {% endif %} - - {% if invoice.client %} - {{ invoice.client.club_card_number|default:"—" }} - {% else %} - — - {% endif %} - {{ invoice.sum|floatformat:2 }}{{ invoice.bonus|floatformat:2|default:"—" }}{{ invoice.start_bonus|floatformat:2|default:"—" }}{{ invoice.deposit_sum|floatformat:2|default:"—" }}{{ invoice.notes|default:"—" }}
Нет доступных счетов
+ + + + + + + + + + + + + + + + + + {% for invoice in form.fields.invoices.queryset %} + + + + + + + + + + + + + + {% empty %} + + + + {% endfor %} + +
СозданЗакрытСчётКлиентНомер клиентаСумма счетаБонусФДДепозитПримечание
{{ invoice.created_at|date:"d.m.Y H:i" }}{% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i" | default: "Счет не закрыт!"}}{% else %}—{% endif %}{{ invoice.ext_id|default:"—" }}{{ invoice.client.name|default:"Не указан" }}{{ invoice.client.club_card_number|default:"—" }}{{ invoice.sum|default:"—" }}{{ invoice.bonus|default:"—" }}{{ invoice.start_bonus|default:"—" }}{{ invoice.deposit_sum|default:"—" }}{{ invoice.notes|default:"—" }}
Нет доступных счетов
From 8b6c59518428e2466d9182e55549702bad84bfd7 Mon Sep 17 00:00:00 2001 From: "Andrew K. Choi" Date: Wed, 6 Aug 2025 12:10:18 +0900 Subject: [PATCH 5/5] bugfix --- lottery/templates/admin/add_participants.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lottery/templates/admin/add_participants.html b/lottery/templates/admin/add_participants.html index 85c83bf..4c91ae5 100644 --- a/lottery/templates/admin/add_participants.html +++ b/lottery/templates/admin/add_participants.html @@ -92,7 +92,7 @@ {{ invoice.created_at|date:"d.m.Y H:i" }} - {% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i" | default: "Счет не закрыт!"}}{% else %}—{% endif %} + {% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i"}}{% else %}—{% endif %} {{ invoice.ext_id|default:"—" }} {{ invoice.client.name|default:"Не указан" }} {{ invoice.client.club_card_number|default:"—" }}