Skip to content

Commit

Permalink
Merge pull request #55 from unicef/develop
Browse files Browse the repository at this point in the history
Db alignment
  • Loading branch information
srugano authored Oct 8, 2024
2 parents 1a06a70 + d5647ea commit 5a7a7a2
Show file tree
Hide file tree
Showing 34 changed files with 560 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
elif [ ${{ github.ref }} == 'refs/heads/staging' ]; then
pipelineId=1286
elif [ ${{ github.ref }} == 'refs/heads/master' ]; then
pipelineId=1233
pipelineId=1483,1233
else
echo "No pipeline to trigger for ref ${{ github.ref }}"
exit 0
Expand Down
21 changes: 4 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
Copyright (c) 2014 - 2024 UNICEF. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License below for more details.

------------------------------------------------------------------------
GNU AFFERO GENERAL PUBLIC LICENSE
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -656,7 +643,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

Expand All @@ -671,4 +658,4 @@ specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
1 change: 1 addition & 0 deletions compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
- CACHE_URL=redis://redis:6379/1
- AZURE_TENANT_ID=
- AZURE_CLIENT_KEY=
- FLOWER_URL=http://flower:5555
depends_on:
db:
condition: service_healthy
Expand Down
23 changes: 23 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ x-django-env: &django-env
- REDIS_URL=redis://redis:6379/0
- ALLOWED_HOSTS=backend,localhost
- STATIC_ROOT=/
- CACHE_URL=redis://redis:6379/1
- STATIC_URL=/static/
- EMAIL_BACKEND=
- EMAIL_HOST=
- EMAIL_PORT=
- EMAIL_USE_TLS=
- EMAIL_USE_SSL=
- SENTRY_ENVIRONMENT=local
- CELERY_BROKER_URL=redis://redis:6379/0
- MAILJET_API_KEY=
- MAILJET_SECRET_KEY=
- WP_PRIVATE_KEY=
- SECURE_SSL_REDIRECT=False
- AZURE_TENANT_ID=
- AZURE_CLIENT_KEY=
- FLOWER_URL=http://flower:5555
- STATIC_FILE_STORAGE=hope_country_report.apps.power_query.storage.DataSetStorage

services:
backend:
Expand Down Expand Up @@ -125,3 +129,22 @@ services:
condition: service_healthy
redis:
condition: service_healthy

flower:
build:
context: .
dockerfile: docker/Dockerfile
target: dev
command: celery_flower
environment: *django-env
restart: unless-stopped
ports:
- 5555:5555
depends_on:
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://flower:5555/"]
interval: 10s
timeout: 5s
retries: 5
3 changes: 3 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ case "$1" in
celery_beat)
celery -A hope_country_report.config.celery beat -l info
;;
celery_flower)
celery -A hope_country_report.config.celery flower
;;
*)
exec "$@"
;;
Expand Down
1 change: 1 addition & 0 deletions src/hope_country_report/api/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SimpleRouterWithNesting(NestedRouterMixin, DefaultRouter):


router.register(r"queries", views.QueryViewSet)
router.register(r"charts", views.ChartViewSet)
#
# office_router = routers.ExtendedSimpleRouter()
#
Expand Down
23 changes: 21 additions & 2 deletions src/hope_country_report/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from rest_framework_gis.serializers import GeoFeatureModelSerializer

from hope_country_report.apps.core.models import CountryOffice, CountryShape
from hope_country_report.apps.power_query.models import Dataset, Query, ReportConfiguration, ReportDocument
from hope_country_report.apps.power_query.models import ChartPage, Dataset, Query, ReportConfiguration, ReportDocument
from hope_country_report.apps.power_query.utils import to_dataset


class SelectedOfficeSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -58,9 +59,14 @@ class Meta:


class DatasetSerializer(serializers.ModelSerializer):
data = serializers.SerializerMethodField()

class Meta:
model = Dataset
fields = ["hash", "last_run"]
fields: list[str] = ["hash", "last_run", "data"]

def get_data(self, obj: Dataset) -> str:
return to_dataset(obj.data).export("json")


class ReportConfigurationSerializer(SelectedOfficeSerializer):
Expand Down Expand Up @@ -134,3 +140,16 @@ class Meta:
model = CountryShape
geo_field = "mpoly"
fields = ("name", "mpoly", "iso2", "iso3", "un")


class ChartPageSerializer(serializers.ModelSerializer):
detail_url = serializers.SerializerMethodField()

class Meta:
model = ChartPage
fields = ["id", "country_office", "title", "params", "detail_url"]

def get_detail_url(self, obj: ChartPage) -> str:
return self.context["request"].build_absolute_uri(
reverse("office-chart", args=[obj.country_office.slug, obj.pk])
)
9 changes: 8 additions & 1 deletion src/hope_country_report/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from rest_framework_extensions.mixins import NestedViewSetMixin

from ..apps.core.models import CountryOffice, CountryShape
from ..apps.power_query.models import Dataset, Query, ReportConfiguration, ReportDocument
from ..apps.power_query.models import ChartPage, Dataset, Query, ReportConfiguration, ReportDocument
from .serializers import (
BoundarySerializer,
ChartPageSerializer,
CountryOfficeSerializer,
DatasetSerializer,
LocationSerializer,
Expand Down Expand Up @@ -104,6 +105,12 @@ class QueryViewSet(NestedViewSetMixin, viewsets.ReadOnlyModelViewSet):
permission_classes = [permissions.DjangoObjectPermissions]


class ChartViewSet(NestedViewSetMixin, viewsets.ReadOnlyModelViewSet):
queryset = ChartPage.objects.all().order_by("-pk")
serializer_class = ChartPageSerializer
permission_classes = [permissions.DjangoObjectPermissions]


class DatasetViewSet(NestedViewSetMixin, viewsets.ReadOnlyModelViewSet):
queryset = Dataset.objects.all().order_by("-pk")
serializer_class = DatasetSerializer
Expand Down
Loading

0 comments on commit 5a7a7a2

Please sign in to comment.