Compare commits
6 Commits
878a1e1a49
...
b68ebd54dd
| Author | SHA1 | Date | |
|---|---|---|---|
| b68ebd54dd | |||
| 8b6c595184 | |||
| 3f5c332ecd | |||
| 8b37877b3e | |||
| 023966bc5b | |||
| 68caea5937 |
@@ -20,6 +20,8 @@ from bot.utils import create_bot_instance
|
|||||||
from .views import view_draw_results
|
from .views import view_draw_results
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
if not logger.handlers:
|
if not logger.handlers:
|
||||||
@@ -36,9 +38,11 @@ def add_participants_view(request):
|
|||||||
return HttpResponse("Не указан параметр lottery_id", status=400)
|
return HttpResponse("Не указан параметр lottery_id", status=400)
|
||||||
lottery = get_object_or_404(Lottery, id=lottery_id)
|
lottery = get_object_or_404(Lottery, id=lottery_id)
|
||||||
|
|
||||||
|
# Все доступные счета, не участвующие в этой лотерее
|
||||||
used_invoice_ids = LotteryParticipant.objects.filter(lottery=lottery).values_list("invoice_id", flat=True)
|
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)
|
qs = Invoice.objects.filter(used=False).exclude(id__in=used_invoice_ids)
|
||||||
|
|
||||||
|
# Фильтрация
|
||||||
deposit_min = request.GET.get("deposit_min")
|
deposit_min = request.GET.get("deposit_min")
|
||||||
deposit_max = request.GET.get("deposit_max")
|
deposit_max = request.GET.get("deposit_max")
|
||||||
created_after = request.GET.get("created_after")
|
created_after = request.GET.get("created_after")
|
||||||
@@ -48,21 +52,30 @@ def add_participants_view(request):
|
|||||||
qs = qs.filter(deposit_sum__gte=deposit_min)
|
qs = qs.filter(deposit_sum__gte=deposit_min)
|
||||||
if deposit_max:
|
if deposit_max:
|
||||||
qs = qs.filter(deposit_sum__lte=deposit_max)
|
qs = qs.filter(deposit_sum__lte=deposit_max)
|
||||||
|
|
||||||
if created_after:
|
if created_after:
|
||||||
try:
|
try:
|
||||||
dt = parse_date(created_after)
|
dt = parse_date(created_after)
|
||||||
if dt:
|
if dt:
|
||||||
qs = qs.filter(created_at__gte=dt)
|
qs = qs.filter(created_at__date__gte=dt)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if created_before:
|
if created_before:
|
||||||
try:
|
try:
|
||||||
dt = parse_date(created_before)
|
dt = parse_date(created_before)
|
||||||
if dt:
|
if dt:
|
||||||
qs = qs.filter(created_at__lte=dt)
|
qs = qs.filter(created_at__date__lte=dt)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
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":
|
if request.method == "POST":
|
||||||
form = AddParticipantsForm(request.POST)
|
form = AddParticipantsForm(request.POST)
|
||||||
form.fields["invoices"].queryset = qs
|
form.fields["invoices"].queryset = qs
|
||||||
@@ -78,10 +91,13 @@ def add_participants_view(request):
|
|||||||
form = AddParticipantsForm()
|
form = AddParticipantsForm()
|
||||||
form.fields["invoices"].queryset = qs
|
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)
|
return render(request, "admin/add_participants.html", context)
|
||||||
|
|
||||||
|
|
||||||
def get_client_by_invoice(invoice):
|
def get_client_by_invoice(invoice):
|
||||||
try:
|
try:
|
||||||
return Client.objects.get(club_card_number=invoice.client_club_card_number)
|
return Client.objects.get(club_card_number=invoice.client_club_card_number)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class AddParticipantsForm(forms.Form):
|
|||||||
deposit_min = forms.DecimalField(label="Минимальный депозит", required=False)
|
deposit_min = forms.DecimalField(label="Минимальный депозит", required=False)
|
||||||
deposit_max = forms.DecimalField(label="Максимальный депозит", required=False)
|
deposit_max = forms.DecimalField(label="Максимальный депозит", required=False)
|
||||||
invoices = forms.ModelMultipleChoiceField(
|
invoices = forms.ModelMultipleChoiceField(
|
||||||
queryset=Invoice.objects.none(),
|
queryset=Invoice.objects.none(), # устанавливается в представлении
|
||||||
widget=forms.CheckboxSelectMultiple,
|
widget=forms.CheckboxSelectMultiple,
|
||||||
required=False,
|
required=False,
|
||||||
label="Доступные счета"
|
label="Доступные счета"
|
||||||
|
|||||||
@@ -48,6 +48,18 @@
|
|||||||
<input type="date" name="created_before" value="{{ request.GET.created_before }}" class="form-control">
|
<input type="date" name="created_before" value="{{ request.GET.created_before }}" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-md-3 form-check mt-2">
|
||||||
|
<input type="checkbox" class="form-check-input" name="without_bonus" id="without_bonus" {% if request.GET.without_bonus %}checked{% endif %}>
|
||||||
|
<label class="form-check-label" for="without_bonus">Только без бонуса</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 form-check mt-2">
|
||||||
|
<input type="checkbox" class="form-check-input" name="without_fd" id="without_fd" {% if request.GET.without_fd %}checked{% endif %}>
|
||||||
|
<label class="form-check-label" for="without_fd">Только без ФД</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<button type="submit" class="btn btn-primary">Применить фильтр</button>
|
<button type="submit" class="btn btn-primary">Применить фильтр</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -55,17 +67,17 @@
|
|||||||
|
|
||||||
<p><strong>Найдено подходящих счетов: {{ invoice_count }}</strong></p>
|
<p><strong>Найдено подходящих счетов: {{ invoice_count }}</strong></p>
|
||||||
|
|
||||||
<!-- Форма добавления участников -->
|
<!-- Форма добавления участников -->
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped table-bordered table-sm">
|
<table class="table table-striped table-bordered table-sm align-middle">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><input type="checkbox" id="select-all" /></th>
|
<th><input type="checkbox" id="select-all" /></th>
|
||||||
<th>Создан</th>
|
<th>Создан</th>
|
||||||
<th>Закрыт</th>
|
<th>Закрыт</th>
|
||||||
<th>Счет</th>
|
<th>Счёт</th>
|
||||||
<th>Клиент</th>
|
<th>Клиент</th>
|
||||||
<th>Номер клиента</th>
|
<th>Номер клиента</th>
|
||||||
<th>Сумма счета</th>
|
<th>Сумма счета</th>
|
||||||
@@ -78,15 +90,9 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for invoice in form.fields.invoices.queryset %}
|
{% for invoice in form.fields.invoices.queryset %}
|
||||||
<tr>
|
<tr>
|
||||||
<input type="checkbox" name="invoices" value="{{ invoice.id }}">
|
<td><input type="checkbox" name="invoices[]" value="{{ invoice.id }}"></td>
|
||||||
<td>{{ invoice.created_at|date:"d.m.Y H:i" }}</td>
|
<td>{{ invoice.created_at|date:"d.m.Y H:i" }}</td>
|
||||||
<td>
|
<td>{% if invoice.closed_at %}{{ invoice.closed_at|date:"d.m.Y H:i"}}{% else %}—{% endif %}</td>
|
||||||
{% if invoice.closed_at %}
|
|
||||||
{{ invoice.closed_at|date:"d.m.Y H:i" }}
|
|
||||||
{% else %}
|
|
||||||
—
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td>{{ invoice.ext_id|default:"—" }}</td>
|
<td>{{ invoice.ext_id|default:"—" }}</td>
|
||||||
<td>{{ invoice.client.name|default:"Не указан" }}</td>
|
<td>{{ invoice.client.name|default:"Не указан" }}</td>
|
||||||
<td>{{ invoice.client.club_card_number|default:"—" }}</td>
|
<td>{{ invoice.client.club_card_number|default:"—" }}</td>
|
||||||
@@ -105,9 +111,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Добавить выбранные счета</button>
|
<button type="submit" class="btn btn-primary">Добавить выбранные счета</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a href="{% url 'admin:draw_lotteryparticipant_changelist' %}" class="btn btn-secondary mt-3">Вернуться к списку участников</a>
|
<a href="{% url 'admin:draw_lotteryparticipant_changelist' %}" class="btn btn-secondary mt-3">Вернуться к списку участников</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user