Skip to content

Commit fc2f57f

Browse files
authored
Merge pull request #64 from unicef/feature/history
Feature/history
2 parents bb1f89f + 4270f37 commit fc2f57f

Some content is hidden

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

51 files changed

+5445
-400
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
-v "./tests:/app/tests" \
150150
-v "./pytest.ini:/app/pytest.ini" \
151151
-t ${{env.IMAGE}} \
152-
pytest tests/ --create-db --selenium -n auto -v --maxfail=5 --migrations --cov-report xml:./output/coverage.xml --record-mode none
152+
pytest tests/ --create-db --selenium -v --maxfail=5 --migrations --cov-report xml:./output/coverage.xml --record-mode none
153153
154154
- name: Upload coverage to Codecov
155155
uses: codecov/codecov-action@v4

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies = [
5151
"sentry-sdk>=2.7.1",
5252
"social-auth-app-django",
5353
"unicef-security>=1.5.1",
54+
"django-pghistory>=3.5.4",
5455
]
5556
[project.scripts]
5657
celery-monitor = "country_workspace.__monitor__:run"

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ section-order = ["future", "standard-library", "third-party", "first-party", "l
9090
[lint.per-file-ignores]
9191
"tests/**.py" = ["S101", "PLR2004", "S", "SIM117", "D", "UP", "PLR0913", "ANN", "N999"]
9292
"src/**/versioning/**.py" = ["N999", ]
93+
"src/**/migrations/**.py" = ["E501", ]

src/country_workspace/admin/beneficiary_group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.http import HttpRequest
33

44
from country_workspace.models import BeneficiaryGroup
5+
56
from .base import BaseModelAdmin
67

78

src/country_workspace/admin/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.db.models import Q, QuerySet
44
from django.http import HttpRequest, JsonResponse
55
from unicef_security.admin import UserAdminPlus
6+
67
from ..models import User
78

89

src/country_workspace/cache/middleware.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ def process_response(self, request: HttpRequest, response: HttpResponse) -> Http
3636
timeout = self.page_timeout
3737
patch_response_headers(response, timeout)
3838
if response.status_code == 200:
39-
cache_key = self.manager.build_key_from_request(request, "view", getattr(request.user, "pk", ""))
40-
response.headers["Etag"] = cache_key
39+
if "Etag" in response.headers:
40+
cache_key = response.headers["Etag"]
41+
else:
42+
cache_key = self.manager.build_key_from_request(request, "view", getattr(request.user, "pk", ""))
43+
response.headers["Etag"] = cache_key
4144
if hasattr(response, "render") and callable(response.render):
4245
response.add_post_render_callback(lambda r: self.manager.store(cache_key, r))
4346
else:

src/country_workspace/config/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"debug_toolbar",
3030
"django_sysinfo",
3131
"flags",
32-
"reversion",
32+
"pghistory",
33+
"pgtrigger",
34+
"pghistory.admin",
3335
"tailwind",
3436
"django_select2",
3537
"social_django",
@@ -65,6 +67,7 @@
6567
"country_workspace.middleware.state.StateSetMiddleware",
6668
"country_workspace.cache.middleware.UpdateCacheMiddleware",
6769
"django.middleware.common.CommonMiddleware",
70+
"country_workspace.middleware.history.HistoryMiddleware",
6871
"csp.middleware.CSPMiddleware",
6972
"debug_toolbar.middleware.DebugToolbarMiddleware",
7073
"django.middleware.csrf.CsrfViewMiddleware",

src/country_workspace/contrib/aurora/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from country_workspace.contrib.aurora.client import AuroraClient
66
from country_workspace.models import AsyncJob, Batch, Household, Individual
77
from country_workspace.utils.config import BatchNameConfig, FailIfAlienConfig
8-
from country_workspace.utils.fields import uppercase_field_value, clean_field_names
8+
from country_workspace.utils.fields import clean_field_names, uppercase_field_value
99

1010

1111
class Config(BatchNameConfig, FailIfAlienConfig):

src/country_workspace/contrib/hope/push.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
from collections.abc import Callable, Iterator
2-
from typing import Any
3-
from itertools import batched
42
from dataclasses import dataclass, field
3+
from itertools import batched
4+
from json import JSONDecodeError
5+
from typing import Any
56

7+
from django.db import DatabaseError, transaction
68
from django.db.models import QuerySet
7-
from django.db import transaction, DatabaseError
8-
9+
from requests.exceptions import RequestException
910

1011
from country_workspace.contrib.hope.client import HopeClient
12+
from country_workspace.contrib.hope.constants import HOUSEHOLD_PUSH_BATCH_SIZE
13+
from country_workspace.exceptions import RemoteError
1114
from country_workspace.models import AsyncJob
1215
from country_workspace.workspaces.models import CountryHousehold
1316

14-
from requests.exceptions import RequestException
15-
from json import JSONDecodeError
16-
from country_workspace.exceptions import RemoteError
17-
from country_workspace.contrib.hope.constants import HOUSEHOLD_PUSH_BATCH_SIZE
18-
1917

2018
@dataclass
2119
class PushProcessor:

src/country_workspace/contrib/kobo/forms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any
22

3-
from country_workspace.contrib.kobo.sync import make_client
43
from django import forms
54

5+
from country_workspace.contrib.kobo.sync import make_client
6+
67

78
class ImportKoboForm(forms.Form):
89
batch_name = forms.CharField(required=False, help_text="Label for this batch")

0 commit comments

Comments
 (0)