• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iplweb / bpp / 18634744198

19 Oct 2025 07:00PM UTC coverage: 31.618% (-29.9%) from 61.514%
18634744198

push

github

mpasternak
Merge branch 'release/v202510.1270'

657 of 9430 branches covered (6.97%)

Branch coverage included in aggregate %.

229 of 523 new or added lines in 42 files covered. (43.79%)

11303 existing lines in 316 files now uncovered.

14765 of 39346 relevant lines covered (37.53%)

0.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.42
src/pbn_export_queue/admin.py
1
from django import forms
1✔
2
from django.contrib import admin, messages
1✔
3
from django.contrib.auth import get_user_model
1✔
4
from django.http import HttpResponseRedirect
1✔
5
from django.urls import reverse
1✔
6
from django.utils.safestring import mark_safe
1✔
7

8
from bpp.admin.core import DynamicAdminFilterMixin
1✔
9

10
from .models import PBN_Export_Queue
1✔
11

12
User = get_user_model()
1✔
13

14

15
class ZamowilUniqueFilter(admin.SimpleListFilter):
1✔
16
    """Custom filter that shows only users who have ordered PBN exports"""
17

18
    title = "zamówił"
1✔
19
    parameter_name = "zamowil"
1✔
20

21
    def lookups(self, request, model_admin):
1✔
22
        # Get unique user IDs from PBN_Export_Queue
NEW
23
        user_ids = (
×
24
            PBN_Export_Queue.objects.values_list("zamowil", flat=True)
25
            .distinct()
26
            .order_by("zamowil")
27
        )
28

29
        # Fetch only those users and return as choices
NEW
30
        users = User.objects.filter(id__in=user_ids).order_by("username")
×
NEW
31
        return [(user.id, str(user)) for user in users]
×
32

33
    def queryset(self, request, queryset):
1✔
NEW
34
        if self.value():
×
NEW
35
            return queryset.filter(zamowil=self.value())
×
NEW
36
        return queryset
×
37

38

39
class RenderHTMLWidget(forms.Textarea):
1✔
40
    def render(self, name, value, renderer, attrs=None):
1✔
UNCOV
41
        return mark_safe((value or "").replace("\n", "<br>"))
×
42

43

44
@admin.register(PBN_Export_Queue)
1✔
45
class PBN_Export_QueueAdmin(DynamicAdminFilterMixin, admin.ModelAdmin):
1✔
46
    list_per_page = 10
1✔
47
    list_display = [
1✔
48
        "rekord_do_wysylki",
49
        "object_id",
50
        "zamowil",
51
        "wysylke_podjeto",
52
        "wysylke_zakonczono",
53
        "ilosc_prob",
54
        "zakonczono_pomyslnie",
55
        "retry_after_user_authorised",
56
    ]
57

58
    search_fields = ["zamowil__username", "zamowil__email"]
1✔
59

60
    list_filter = [
1✔
61
        ZamowilUniqueFilter,
62
        "zakonczono_pomyslnie",
63
        "retry_after_user_authorised",
64
    ]
65

66
    date_hierarchy = "zamowiono"
1✔
67

68
    readonly_fields = [
1✔
69
        "object_id",
70
        "content_type",
71
        "zamowiono",
72
        "zamowil",
73
        "wysylke_podjeto",
74
        "wysylke_zakonczono",
75
        "ilosc_prob",
76
        "zakonczono_pomyslnie",
77
        "retry_after_user_authorised",
78
    ]
79

80
    def has_delete_permission(self, request, obj=None):
1✔
81
        if request.user.is_superuser:
1!
82
            return True
1✔
UNCOV
83
        if obj is not None and obj.zamowil == request.user:
×
84
            return True
×
UNCOV
85
        return False
×
86

87
    from django.db import models
1✔
88

89
    formfield_overrides = {models.TextField: {"widget": RenderHTMLWidget}}
1✔
90

91
    def _resend_single_item(self, obj: PBN_Export_Queue, user, message_suffix=""):
1✔
92
        """Common logic for resending a single PBN export queue item"""
UNCOV
93
        obj.prepare_for_resend(user=user, message_suffix=message_suffix)
×
UNCOV
94
        obj.sprobuj_wyslac_do_pbn()
×
95

96
    def resend_to_pbn_action(self, request, queryset):
1✔
UNCOV
97
        count = 0
×
UNCOV
98
        for obj in queryset:
×
UNCOV
99
            self._resend_single_item(obj, request.user, " (akcja masowa)")
×
UNCOV
100
            count += 1
×
101

UNCOV
102
        self.message_user(request, f"Ponowiono wysyłkę do PBN dla {count} elementów")
×
103

104
    resend_to_pbn_action.short_description = "Wyślij ponownie"
1✔
105

106
    actions = [resend_to_pbn_action]
1✔
107

108
    def save_form(self, request, form, change):
1✔
UNCOV
109
        return form.save(commit=False)
×
110

111
    def response_change(self, request, obj):
1✔
UNCOV
112
        if "_resend_to_pbn" in request.POST:
×
UNCOV
113
            self._resend_single_item(obj, request.user)
×
UNCOV
114
            self.message_user(request, f"Ponowiono wysyłkę do PBN: {obj}")
×
UNCOV
115
            return HttpResponseRedirect(
×
116
                reverse(
117
                    f"admin:{obj._meta.app_label}_{obj._meta.model_name}_change",
118
                    args=[obj.pk],
119
                )
120
            )
UNCOV
121
        return super().response_change(request, obj)
×
122

123
    def has_add_permission(self, request):
1✔
124
        return False
1✔
125

126
    def save_model(self, request, obj, form, change):
1✔
127
        # Uczyń FAKTYCZNIE readonly :-)
UNCOV
128
        messages.error(
×
129
            request,
130
            "Obiekt NIE został zapisany -- nie można edytować tej części serwisu.",
131
        )
UNCOV
132
        return
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc