Skip to content

Commit 3a109f7

Browse files
Merge pull request #1845 from IFRCGo/develop
Release 1.1.483 (July 2023)
2 parents 7d452d4 + bebe168 commit 3a109f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4601
-1776
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- run:
2727
name: Run tests
2828
command: |
29-
docker-compose run --rm serve ./manage.py test --keepdb -v 2 --pattern="test_fake.py" &&
29+
time docker-compose run --rm serve ./manage.py test --keepdb -v 2 --pattern="test_fake.py" &&
3030
docker-compose run --rm serve pytest --reuse-db --durations=10
3131
- run:
3232
name: Push image to Docker Hub

CHANGELOG.md

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

77
## Unreleased
88

9+
## 1.1.483
10+
11+
### Added
12+
- Add global endpoint for fetching enums
13+
- Update logic for new translation API
14+
- Replace old doc page with redoc (OpenAPI)
15+
- Add OpenAPI endpoint using drf_yasg
16+
- Rename DREF serializer to active
17+
- Fix Project CSV importing
18+
919
## 1.1.482
1020
- Add more columns to AppealDocument Admin list
1121
- Put back caching
@@ -2252,7 +2262,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
22522262

22532263
## 0.1.20
22542264

2255-
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.482...HEAD
2265+
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.483...HEAD
2266+
[1.1.483]: https://github.com/IFRCGo/go-api/compare/1.1.482...1.1.483
22562267
[1.1.482]: https://github.com/IFRCGo/go-api/compare/1.1.481...1.1.482
22572268
[1.1.481]: https://github.com/IFRCGo/go-api/compare/1.1.480...1.1.481
22582269
[1.1.480]: https://github.com/IFRCGo/go-api/compare/1.1.479...1.1.480

api/drf_views.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pytz import utc
33
from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK
44
from rest_framework.generics import GenericAPIView, CreateAPIView, UpdateAPIView
5+
from rest_framework.views import APIView
56
from rest_framework.response import Response
67
from rest_framework.authentication import TokenAuthentication
78
from rest_framework.permissions import IsAuthenticated
@@ -13,8 +14,12 @@
1314
from django.db import models
1415
from django.db.models import Prefetch, Count, Q, OuterRef
1516
from django.utils import timezone
17+
from django.utils.translation import get_language as django_get_language
18+
from drf_spectacular.utils import extend_schema
1619

1720
from main.utils import is_tableau
21+
from main.enums import GlobalEnumSerializer, get_enum_values
22+
from main.translation import TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME
1823
from deployments.models import Personnel
1924
from databank.serializers import CountryOverviewSerializer
2025

@@ -1000,7 +1005,9 @@ def save_meta(self, fieldreport, meta, is_update=False):
10001005
for action_taken in meta["actions_taken"]:
10011006
actions = action_taken["actions"]
10021007
del action_taken["actions"]
1008+
action_taken[TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME] = django_get_language()
10031009
actions_taken = ActionsTaken.objects.create(field_report=fieldreport, **action_taken)
1010+
CreateFieldReportSerializer.trigger_field_translation(actions_taken)
10041011
actions_taken.actions.add(*actions)
10051012

10061013
if "contacts" in meta:
@@ -1030,7 +1037,9 @@ def create_event(self, report):
10301037
auto_generated=True,
10311038
auto_generated_source=SOURCES["new_report"],
10321039
visibility=report.visibility,
1040+
**{TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME: django_get_language()},
10331041
)
1042+
CreateFieldReportSerializer.trigger_field_translation(event)
10341043
report.event = event
10351044
report.save()
10361045
return event
@@ -1049,7 +1058,10 @@ def create(self, request, *args, **kwargs):
10491058

10501059
try:
10511060
# TODO: Use serializer to create fieldreport
1052-
fieldreport = FieldReport.objects.create(**data)
1061+
data[TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME] = django_get_language()
1062+
fieldreport = FieldReport.objects.create(
1063+
**data,
1064+
)
10531065
CreateFieldReportSerializer.trigger_field_translation(fieldreport)
10541066
except Exception as e:
10551067
try:
@@ -1185,3 +1197,16 @@ class UsersViewset(viewsets.ReadOnlyModelViewSet):
11851197

11861198
def get_queryset(self):
11871199
return User.objects.filter(is_active=True)
1200+
1201+
1202+
class GlobalEnumView(APIView):
1203+
"""
1204+
Provide a single endpoint to fetch enum metadata
1205+
"""
1206+
1207+
@extend_schema(responses=GlobalEnumSerializer)
1208+
def get(self, _):
1209+
"""
1210+
Return a list of all enums.
1211+
"""
1212+
return Response(get_enum_values())

api/enums.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from . import models
2+
3+
enum_register = {
4+
'region_name': models.RegionName,
5+
'country_type': models.CountryType,
6+
'visibility_choices': models.VisibilityChoices,
7+
'visibility_char_choices': models.VisibilityCharChoices,
8+
'position_type': models.PositionType,
9+
'tab_number': models.TabNumber,
10+
'alert_level': models.AlertLevel,
11+
'appeal_type': models.AppealType,
12+
'appeal_status': models.AppealStatus,
13+
'request_choices': models.RequestChoices,
14+
'episource_choices': models.EPISourceChoices,
15+
'field_report_status': models.FieldReport.Status,
16+
'field_report_recent_affected': models.FieldReport.RecentAffected,
17+
'action_org': models.ActionOrg,
18+
'action_type': models.ActionType,
19+
'action_category': models.ActionCategory,
20+
'profile_org_types': models.Profile.OrgTypes,
21+
}

api/management/commands/index_and_notify.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ def construct_template_record(self, rtype, record):
609609
}
610610
elif rtype == RecordType.WEEKLY_DIGEST:
611611
rec_obj = {
612+
'resource_uri': settings.FRONTEND_URL,
612613
'active_dref': self.get_weekly_digest_data('dref'),
613614
'active_ea': self.get_weekly_digest_data('ea'),
614615
'funding_coverage': self.get_weekly_digest_data('fund'),
@@ -647,7 +648,7 @@ def notify(self, records, rtype, stype, uid=None):
647648

648649
# Decide if it is a personal notification or batch
649650
if uid is None:
650-
emails = self.gather_subscribers(records, rtype, stype)
651+
emails = list(set(self.gather_subscribers(records, rtype, stype)))
651652
if not len(emails):
652653
return
653654
else:

0 commit comments

Comments
 (0)