Skip to content

Commit c76130b

Browse files
Merge pull request #1683 from IFRCGo/develop
DREF hotfix and some small fixes
2 parents f0de16d + d9700b8 commit c76130b

File tree

18 files changed

+1998
-2210
lines changed

18 files changed

+1998
-2210
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88

9+
## 1.1.471
10+
11+
### Added
12+
- Hotfix for DREF permissions
13+
914
## 1.1.470
1015

1116
### Added
@@ -2158,7 +2163,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
21582163

21592164
## 0.1.20
21602165

2161-
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.470...HEAD
2166+
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.471...HEAD
2167+
[1.1.471]: https://github.com/IFRCGo/go-api/compare/1.1.470...1.1.471
21622168
[1.1.470]: https://github.com/IFRCGo/go-api/compare/1.1.469...1.1.470
21632169
[1.1.469]: https://github.com/IFRCGo/go-api/compare/1.1.468...1.1.469
21642170
[1.1.468]: https://github.com/IFRCGo/go-api/compare/1.1.467...1.1.468

api/drf_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ class GoHistoricalViewSet(viewsets.ReadOnlyModelViewSet):
10951095
def get_queryset(self):
10961096
return Event.objects.filter(appeals__isnull=False)
10971097

1098+
10981099
class CountryOfFieldReportToReviewViewset(viewsets.ReadOnlyModelViewSet):
10991100
queryset = CountryOfFieldReportToReview.objects.order_by('country')
11001101
serializer_class = CountryOfFieldReportToReviewSerializer

api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def get_organizations_from(obj):
652652
deployments = [d for d in obj.personneldeployment_set.all()]
653653
personnels = []
654654
for d in deployments:
655-
for p in d.personnel_set.filter(end_date__gte=timezone.now(), is_active=True):
655+
for p in d.personnel_set.filter(end_date__gte=timezone.now(), start_date__lte=timezone.now(), is_active=True):
656656
personnels.append(p)
657657
return list(set([p.country_from.society_name for p in personnels if p.country_from and p.country_from.society_name != '']))
658658

dref/admin.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,68 @@
1212

1313
@admin.register(DrefFile)
1414
class DrefFileAdmin(admin.ModelAdmin):
15-
search_fields = ('file',)
15+
search_fields = ("file",)
1616

1717

1818
@admin.register(Dref)
1919
class DrefAdmin(CompareVersionAdmin, TranslationAdmin, admin.ModelAdmin):
20-
search_fields = ('title',)
21-
list_display = ('title', 'national_society', 'disaster_type',
22-
'ns_request_date', 'submission_to_geneva', 'status',)
20+
search_fields = ("title",)
21+
list_display = (
22+
"title",
23+
"national_society",
24+
"disaster_type",
25+
"ns_request_date",
26+
"submission_to_geneva",
27+
"status",
28+
)
2329
autocomplete_fields = (
24-
'national_society',
25-
'disaster_type',
26-
'users',
27-
'event_map',
28-
'images',
29-
'budget_file',
30-
'cover_image',
30+
"national_society",
31+
"disaster_type",
32+
"users",
33+
"event_map",
34+
"images",
35+
"budget_file",
36+
"cover_image",
3137
)
3238

3339
def get_queryset(self, request):
34-
return super().get_queryset(request).prefetch_related(
35-
'planned_interventions',
36-
'needs_identified',
37-
'national_society_actions',
38-
'users'
40+
return (
41+
super()
42+
.get_queryset(request)
43+
.prefetch_related("planned_interventions", "needs_identified", "national_society_actions", "users")
3944
)
4045

4146

4247
@admin.register(DrefOperationalUpdate)
4348
class DrefOperationalUpdateAdmin(CompareVersionAdmin, admin.ModelAdmin):
44-
list_display = ('title', 'national_society', 'disaster_type')
49+
list_display = ("title", "national_society", "disaster_type")
4550
autocomplete_fields = (
46-
'national_society',
47-
'disaster_type',
48-
'images',
49-
'users',
50-
'event_map',
51-
'images',
52-
'budget_file',
53-
'cover_image',
51+
"national_society",
52+
"disaster_type",
53+
"images",
54+
"users",
55+
"event_map",
56+
"images",
57+
"budget_file",
58+
"cover_image",
5459
)
55-
list_filter = ['dref']
60+
list_filter = ["dref"]
5661

5762
def get_queryset(self, request):
58-
return super().get_queryset(request).prefetch_related(
59-
'planned_interventions',
60-
'needs_identified',
61-
'national_society_actions',
62-
'users'
63+
return (
64+
super()
65+
.get_queryset(request)
66+
.prefetch_related("planned_interventions", "needs_identified", "national_society_actions", "users")
6367
)
6468

69+
6570
@admin.register(DrefFinalReport)
6671
class DrefFinalReportAdmin(CompareVersionAdmin, admin.ModelAdmin):
67-
list_display = ('title', 'national_society', 'disaster_type')
72+
list_display = ("title", "national_society", "disaster_type")
6873
autocomplete_fields = (
69-
'national_society',
70-
'disaster_type',
71-
'photos',
74+
"national_society",
75+
"disaster_type",
76+
"photos",
7277
)
73-
list_filter = ['dref']
74-
search_fields = ['title', 'national_society__name']
78+
list_filter = ["dref"]
79+
search_fields = ["title", "national_society__name"]

dref/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44

55
class DrefConfig(AppConfig):
6-
name = 'dref'
7-
verbose_name = _('dref')
6+
name = "dref"
7+
verbose_name = _("dref")

dref/factories/dref.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
DrefFile,
1313
DrefOperationalUpdate,
1414
DrefFinalReport,
15-
PlannedInterventionIndicators
15+
PlannedInterventionIndicators,
1616
)
1717

1818

1919
class DrefFactory(factory.django.DjangoModelFactory):
2020
class Meta:
2121
model = Dref
2222

23-
title = fuzzy.FuzzyText(length=50, prefix='title-')
23+
title = fuzzy.FuzzyText(length=50, prefix="title-")
2424
type_of_onset = fuzzy.FuzzyChoice(Dref.OnsetType)
2525
disaster_category = fuzzy.FuzzyChoice(Dref.DisasterCategory)
2626
status = fuzzy.FuzzyChoice(Dref.Status)
@@ -75,18 +75,15 @@ class Meta:
7575
model = DrefFile
7676

7777
file = factory.LazyAttribute(
78-
lambda _: ContentFile(
79-
factory.django.ImageField()._make_data(
80-
{'width': 1024, 'height': 768}
81-
), 'dref.jpg'
82-
)
78+
lambda _: ContentFile(factory.django.ImageField()._make_data({"width": 1024, "height": 768}), "dref.jpg")
8379
)
8480

8581

8682
class PlannedInterventionIndicatorsFactory(factory.django.DjangoModelFactory):
8783
class Meta:
8884
model = PlannedInterventionIndicators
89-
title = fuzzy.FuzzyText(length=50, prefix='title-')
85+
86+
title = fuzzy.FuzzyText(length=50, prefix="title-")
9087

9188

9289
class PlannedInterventionFactory(factory.django.DjangoModelFactory):
@@ -122,7 +119,8 @@ class Meta:
122119
class DrefOperationalUpdateFactory(factory.django.DjangoModelFactory):
123120
class Meta:
124121
model = DrefOperationalUpdate
125-
title = fuzzy.FuzzyText(length=50, prefix='title-')
122+
123+
title = fuzzy.FuzzyText(length=50, prefix="title-")
126124
type_of_onset = fuzzy.FuzzyChoice(Dref.OnsetType)
127125
disaster_category = fuzzy.FuzzyChoice(Dref.DisasterCategory)
128126
national_society = factory.SubFactory(CountryFactory)
@@ -159,7 +157,7 @@ class DrefFinalReportFactory(factory.django.DjangoModelFactory):
159157
class Meta:
160158
model = DrefFinalReport
161159

162-
title = fuzzy.FuzzyText(length=50, prefix='Final-Report-')
160+
title = fuzzy.FuzzyText(length=50, prefix="Final-Report-")
163161
type_of_onset = fuzzy.FuzzyChoice(Dref.OnsetType)
164162
disaster_category = fuzzy.FuzzyChoice(Dref.DisasterCategory)
165163
national_society = factory.SubFactory(CountryFactory)

dref/filter_set.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
import django_filters as filters
22

3-
from dref.models import (
4-
Dref,
5-
DrefOperationalUpdate
6-
)
3+
from dref.models import Dref, DrefOperationalUpdate
74
from api.models import Country
85

96

107
class DrefFilter(filters.FilterSet):
118
status = filters.MultipleChoiceFilter(
129
choices=Dref.Status.choices,
13-
lookup_expr='in',
10+
lookup_expr="in",
1411
widget=filters.widgets.CSVWidget,
1512
)
16-
country = filters.ModelMultipleChoiceFilter(
17-
field_name='country',
18-
queryset=Country.objects.all()
19-
)
13+
country = filters.ModelMultipleChoiceFilter(field_name="country", queryset=Country.objects.all())
2014

2115
class Meta:
2216
model = Dref
23-
fields = ['is_published']
17+
fields = ["is_published"]
2418

2519

2620
class DrefOperationalUpdateFilter(filters.FilterSet):
27-
dref = filters.ModelMultipleChoiceFilter(
28-
field_name='dref',
29-
queryset=Dref.objects.all().distinct()
30-
)
21+
dref = filters.ModelMultipleChoiceFilter(field_name="dref", queryset=Dref.objects.all().distinct())
3122

3223
class Meta:
3324
model = DrefOperationalUpdate
34-
fields = ['is_published']
25+
fields = ["is_published"]

0 commit comments

Comments
 (0)