Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1427] Implemented OpenZaak status translation #748

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/open_inwoner/cms/cases/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
fetch_single_case_type,
fetch_single_status_type,
)
from open_inwoner.openzaak.models import OpenZaakConfig
from open_inwoner.openzaak.models import OpenZaakConfig, StatusTranslation
from open_inwoner.openzaak.utils import format_zaak_identificatie, is_zaak_visible
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import LogMixin
Expand Down Expand Up @@ -141,6 +141,7 @@ def get_cases(self) -> List[Zaak]:
def process_cases(self, cases: List[Zaak]) -> List[dict]:
# Prepare data for frontend
config = OpenZaakConfig.get_solo()
status_translate = StatusTranslation.objects.get_lookup()

updated_cases = []
for case in cases:
Expand All @@ -150,7 +151,7 @@ def process_cases(self, cases: List[Zaak]) -> List[dict]:
"start_date": case.startdatum,
"end_date": getattr(case, "einddatum", None),
"description": case.zaaktype.omschrijving,
"current_status": glom(
"current_status": status_translate.from_glom(
case, "status.statustype.omschrijving", default=""
),
}
Expand Down
22 changes: 19 additions & 3 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
create_klant,
fetch_klant_for_bsn,
)
from open_inwoner.openzaak.api_models import Zaak
from open_inwoner.openzaak.api_models import Status, Zaak
from open_inwoner.openzaak.cases import (
connect_case_with_document,
fetch_case_information_objects,
Expand All @@ -41,6 +41,7 @@
)
from open_inwoner.openzaak.models import (
OpenZaakConfig,
StatusTranslation,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
)
Expand All @@ -49,6 +50,7 @@
get_role_name_display,
is_info_object_visible,
)
from open_inwoner.utils.translate import TranslationLookup
from open_inwoner.utils.views import CommonPageMixin, LogMixin

from ..forms import CaseContactForm, CaseUploadForm
Expand Down Expand Up @@ -110,6 +112,7 @@ def get_context_data(self, **kwargs):
if self.case:
self.log_case_access(self.case.identificatie)
config = OpenZaakConfig.get_solo()
status_translate = StatusTranslation.objects.get_lookup()

documents = self.get_case_document_files(self.case)

Expand Down Expand Up @@ -147,12 +150,12 @@ def get_context_data(self, **kwargs):
self.case, "uiterlijke_einddatum_afdoening", None
),
"description": self.case.zaaktype.omschrijving,
"current_status": glom(
"current_status": status_translate.from_glom(
self.case,
"status.statustype.omschrijving",
default=_("No data available"),
),
"statuses": statuses,
"statuses": self.get_statuses_data(statuses, status_translate),
"documents": documents,
"allowed_file_extensions": sorted(config.allowed_file_extensions),
}
Expand Down Expand Up @@ -221,6 +224,19 @@ def get_initiator_display(self, case: Zaak) -> str:
return ""
return ", ".join([get_role_name_display(r) for r in roles])

def get_statuses_data(
self, statuses: List[Status], lookup: TranslationLookup
) -> List[dict]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the built-in type list for the annotation since we don't need to support Python < 3.9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should, but let's do it in one operation and sweep for all main PEP 585 containers: I created Taiga issue 1718 for it.

return [
{
"date": s.datum_status_gezet,
"label": lookup.from_glom(
s, "statustype.omschrijving", default=_("No data available")
),
}
for s in statuses
]

def get_case_document_files(self, case: Zaak) -> List[SimpleFile]:
case_info_objects = fetch_case_information_objects(case.url)

Expand Down

This file was deleted.

29 changes: 0 additions & 29 deletions src/open_inwoner/components/templatetags/status_tags.py

This file was deleted.

32 changes: 31 additions & 1 deletion src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
from django.contrib import admin, messages
from django.core.exceptions import ValidationError
from django.db.models import BooleanField, Count, Exists, ExpressionWrapper, Q
from django.db.models import BooleanField, Count, ExpressionWrapper, Q
from django.forms.models import BaseInlineFormSet
from django.utils.translation import gettext_lazy as _, ngettext

from import_export.admin import ImportExportMixin
from import_export.formats import base_formats
from solo.admin import SingletonModelAdmin

from .models import (
CatalogusConfig,
OpenZaakConfig,
StatusTranslation,
UserCaseInfoObjectNotification,
UserCaseStatusNotification,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
)
from .resources.import_resource import StatusTranslationImportResource


@admin.register(OpenZaakConfig)
Expand Down Expand Up @@ -324,3 +328,29 @@ class UserCaseInfoObjectNotificationAdmin(admin.ModelAdmin):

def has_change_permission(self, request, obj=None):
return False


@admin.register(StatusTranslation)
class StatusTranslationAdmin(ImportExportMixin, admin.ModelAdmin):
fields = [
"status",
"translation",
]
search_fields = [
"status",
"translation",
]
list_display = [
"id",
"status",
"translation",
]
list_editable = [
"status",
"translation",
]
ordering = ("status",)

# import-export
resource_class = StatusTranslationImportResource
formats = [base_formats.XLSX, base_formats.CSV]
8 changes: 7 additions & 1 deletion src/open_inwoner/openzaak/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from django.utils import timezone

from open_inwoner.accounts.models import User
from open_inwoner.openzaak.api_models import Zaak, ZaakType
from open_inwoner.openzaak.api_models import ZaakType
from open_inwoner.utils.translate import TranslationLookup

if TYPE_CHECKING:
from open_inwoner.openzaak.models import (
Expand Down Expand Up @@ -162,3 +163,8 @@ def filter_questions_enabled_for_case_type(self, case_type: ZaakType):
return self.none()

return self.filter_case_type(case_type).filter(questions_enabled=True)


class StatusTranslationQuerySet(models.QuerySet):
def get_lookup(self):
return TranslationLookup(self.values_list("status", "translation"))
44 changes: 44 additions & 0 deletions src/open_inwoner/openzaak/migrations/0021_statustranslation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 3.2.20 on 2023-08-25 08:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"openzaak",
"0020_rename_contact_moments_enabled_zaaktypeconfig_contact_form_enabled",
),
]

operations = [
migrations.CreateModel(
name="StatusTranslation",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"status",
models.CharField(
max_length=255, unique=True, verbose_name="Status tekst"
),
),
(
"translation",
models.CharField(max_length=255, verbose_name="Vertaling"),
),
],
options={
"verbose_name": "Status vertaling",
"verbose_name_plural": "Status vertalingen",
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.20 on 2023-09-04 10:33

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0021_statustranslation"),
("openzaak", "0022_mark_as_is_sent"),
]

operations = []
19 changes: 19 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from zgw_consumers.constants import APITypes

from open_inwoner.openzaak.managers import (
StatusTranslationQuerySet,
UserCaseInfoObjectNotificationManager,
UserCaseStatusNotificationManager,
ZaakTypeConfigQueryset,
Expand Down Expand Up @@ -361,3 +362,21 @@ def has_received_similar_notes_within(self, period: timedelta) -> bool:
) or UserCaseStatusNotification.objects.has_received_similar_notes_within(
self.user, self.case_uuid, period
)


class StatusTranslation(models.Model):
status = models.CharField(
verbose_name=_("Status tekst"),
max_length=255,
unique=True,
)
translation = models.CharField(
verbose_name=_("Vertaling"),
max_length=255,
)

objects = StatusTranslationQuerySet.as_manager()

class Meta:
verbose_name = _("Status vertaling")
verbose_name_plural = _("Status vertalingen")
Empty file.
33 changes: 33 additions & 0 deletions src/open_inwoner/openzaak/resources/import_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.utils.translation import ugettext_lazy as _

from import_export import fields, resources
from import_export.exceptions import ImportExportError

from open_inwoner.openzaak.models import StatusTranslation


class StatusTranslationImportResource(resources.ModelResource):
def before_import(self, dataset, using_transactions, dry_run, **kwargs):
# Validate that file contains all the headers
missing_headers = set(self.get_diff_headers()) - set(dataset.headers)
if missing_headers:
missing_headers = ",\n".join(missing_headers)
raise ImportExportError(_(f"Missing required headers: {missing_headers}"))

return super().before_import(dataset, using_transactions, dry_run, **kwargs)

def get_or_init_instance(self, instance_loader, row):
# Replace newlines from excel
for key, value in row.items():
if isinstance(value, str):
row[key] = value.replace("_x000D_", "\n")

return super().get_or_init_instance(instance_loader, row)

status = fields.Field(column_name="status", attribute="status")
translation = fields.Field(column_name="translation", attribute="translation")

class Meta:
model = StatusTranslation
import_id_fields = ("status",)
fields = ("status", "translation")
9 changes: 9 additions & 0 deletions src/open_inwoner/openzaak/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from open_inwoner.openzaak.api_models import Notification, Rol, ZaakType
from open_inwoner.openzaak.models import (
CatalogusConfig,
StatusTranslation,
UserCaseInfoObjectNotification,
UserCaseStatusNotification,
ZaakTypeConfig,
Expand Down Expand Up @@ -141,6 +142,14 @@ class Meta:
model = Notification


class StatusTranslationFactory(factory.django.DjangoModelFactory):
status = factory.Faker("pystr", max_chars=50)
translation = factory.Faker("pystr", max_chars=80)

class Meta:
model = StatusTranslation


def generate_rol(
type_: str,
identification: dict,
Expand Down
Loading
Loading