• 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

46.28
src/bpp/views/api/__init__.py
1
from django.db import transaction
1✔
2
from django.http import JsonResponse
1✔
3
from django.http.response import HttpResponseNotFound
1✔
4
from django.views.generic import View
1✔
5

6
from bpp.models import Autor, Autor_Dyscyplina, Uczelnia, Zrodlo
1✔
7
from bpp.models.abstract import POLA_PUNKTACJI
1✔
8
from bpp.models.praca_habilitacyjna import Praca_Habilitacyjna
1✔
9
from bpp.models.zrodlo import Punktacja_Zrodla
1✔
10

11

12
class RokHabilitacjiView(View):
1✔
13
    def post(self, request, *args, **kw):
1✔
UNCOV
14
        try:
×
UNCOV
15
            autor = Autor.objects.get(pk=int(request.POST.get("autor_pk")))
×
UNCOV
16
        except Autor.DoesNotExist:
×
UNCOV
17
            return HttpResponseNotFound("Autor")
×
18

UNCOV
19
        try:
×
UNCOV
20
            habilitacja = autor.praca_habilitacyjna
×
UNCOV
21
        except Praca_Habilitacyjna.DoesNotExist:
×
UNCOV
22
            return HttpResponseNotFound("Habilitacja")
×
23

UNCOV
24
        return JsonResponse({"rok": habilitacja.rok})
×
25

26

27
class PunktacjaZrodlaView(View):
1✔
28
    def post(self, request, zrodlo_id, rok, *args, **kw):
1✔
UNCOV
29
        try:
×
UNCOV
30
            z = Zrodlo.objects.get(pk=zrodlo_id)
×
UNCOV
31
        except Zrodlo.DoesNotExist:
×
UNCOV
32
            return HttpResponseNotFound("Zrodlo")
×
33

UNCOV
34
        try:
×
UNCOV
35
            pz = Punktacja_Zrodla.objects.get(zrodlo=z, rok=rok)
×
UNCOV
36
        except Punktacja_Zrodla.DoesNotExist:
×
UNCOV
37
            return HttpResponseNotFound("Rok")
×
38

39
        # d = dict([(pole, str(getattr(pz, pole))) for pole in POLA_PUNKTACJI])
UNCOV
40
        d = {pole: getattr(pz, pole) for pole in POLA_PUNKTACJI}
×
UNCOV
41
        return JsonResponse(d)
×
42

43

44
class UploadPunktacjaZrodlaView(View):
1✔
45
    def ok(self):
1✔
UNCOV
46
        return JsonResponse({"result": "ok"})
×
47

48
    @transaction.atomic
1✔
49
    def post(self, request, zrodlo_id, rok, *args, **kw):
1✔
UNCOV
50
        try:
×
UNCOV
51
            z = Zrodlo.objects.get(pk=zrodlo_id)
×
UNCOV
52
        except Zrodlo.DoesNotExist:
×
UNCOV
53
            return HttpResponseNotFound("Zrodlo")
×
54

UNCOV
55
        kw_punktacji = {}
×
UNCOV
56
        for element in list(request.POST.keys()):
×
UNCOV
57
            if element in POLA_PUNKTACJI:
×
UNCOV
58
                if request.POST.get(element) != "":
×
UNCOV
59
                    kw_punktacji[element] = request.POST.get(element) or "0.0"
×
60

UNCOV
61
        try:
×
UNCOV
62
            pz = Punktacja_Zrodla.objects.get(zrodlo=z, rok=rok)
×
UNCOV
63
        except Punktacja_Zrodla.DoesNotExist:
×
UNCOV
64
            Punktacja_Zrodla.objects.create(zrodlo=z, rok=rok, **kw_punktacji)
×
UNCOV
65
            return self.ok()
×
66

UNCOV
67
        if request.POST.get("overwrite") == "1":
×
UNCOV
68
            for key, value in list(kw_punktacji.items()):
×
UNCOV
69
                setattr(pz, key, value or "0.0")
×
UNCOV
70
            pz.save()
×
UNCOV
71
            return self.ok()
×
UNCOV
72
        return JsonResponse(dict(result="exists"))
×
73

74

75
def ostatnia_jednostka(request, a):
1✔
76
    uczelnia = Uczelnia.objects.get_for_request(request)
1✔
77

78
    jed = a.aktualna_jednostka
1✔
79
    if jed is None:
1!
80
        # Brak aktualnej jednostki, spróbuj podpowiedzieć obcą jednostkę:
81
        if uczelnia is None:
1!
UNCOV
82
            return None
×
83

84
        else:
85
            # uczelnia is not None
86
            if uczelnia.obca_jednostka_id is not None:
1!
87
                return uczelnia.obca_jednostka
×
88
    else:
UNCOV
89
        return jed
×
90

91

92
def ostatnia_dyscyplina(request, a, rok):
1✔
93
    uczelnia = Uczelnia.objects.get_for_request(request)
1✔
94

95
    if uczelnia is not None and uczelnia.podpowiadaj_dyscypliny and rok:
1!
96
        ad = Autor_Dyscyplina.objects.filter(autor=a, rok=rok)
1✔
97

98
        if ad.exists():
1✔
99
            # Jest wpis Autor_Dyscyplina dla tego autora i roku.
100
            ad = ad.first()
1✔
101
            if (
1!
102
                ad.dyscyplina_naukowa_id is not None
103
                and ad.subdyscyplina_naukowa_id is not None
104
            ):
UNCOV
105
                return None
×
106

107
            return ad.dyscyplina_naukowa or ad.subdyscyplina_naukowa
1✔
108

109

110
class OstatniaJednostkaIDyscyplinaView(View):
1✔
111
    """Zwraca jako JSON ostatnią jednostkę danego autora oraz ewentualnie jego
112
    dyscyplinę naukową, w sytuacji gdy jest ona jedna i określona na dany rok.
113
    """
114

115
    def post(self, request, *args, **kw):
1✔
116
        try:
1✔
117
            a = Autor.objects.get(pk=int(request.POST.get("autor_id", None)))
1✔
UNCOV
118
        except (Autor.DoesNotExist, TypeError, ValueError):
×
UNCOV
119
            return JsonResponse({"status": "error", "reason": "autor nie istnieje"})
×
120

121
        ost_jed = ostatnia_jednostka(request, a)
1✔
122

123
        ret = {}
1✔
124

125
        if ost_jed is None:
1!
126
            ret.update(dict(jednostka_id=None, nazwa=None, status="ok"))
1✔
127
        else:
UNCOV
128
            ret.update(
×
129
                dict(
130
                    jednostka_id=ost_jed.pk,
131
                    nazwa=ost_jed.nazwa,
132
                    status="ok",
133
                )
134
            )
135

136
        try:
1✔
137
            rok = int(request.POST.get("rok"))
1✔
UNCOV
138
        except (TypeError, ValueError):
×
UNCOV
139
            rok = None
×
140

141
        ost_dys = ostatnia_dyscyplina(request, a, rok)
1✔
142

143
        if ost_dys is not None:
1✔
144
            ret["dyscyplina_nazwa"] = ost_dys.nazwa
1✔
145
            ret["dyscyplina_id"] = ost_dys.pk
1✔
146
            ret["status"] = "ok"
1✔
147

148
        return JsonResponse(ret)
1✔
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