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

✨ Filter on latest record workaround #1187

Merged
merged 1 commit into from
Feb 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ChecklistSerializer(APIModelSerializer):
answers = ChecklistAnswerSerializer(
many=True,
)
# meta = serializers.HiddenField(default=True)
locked_by = UserSlugRelatedField(
help_text=_("Checklist is locked by this user."),
slug_field="username",
Expand Down
1 change: 0 additions & 1 deletion backend/src/zac/contrib/objects/kownsl/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ class Meta:
"isBeingReconfigured",
"locked",
"lockReason",
"meta",
"metadata",
"numReviewsGivenBeforeChange",
"requester",
Expand Down
13 changes: 10 additions & 3 deletions backend/src/zac/contrib/objects/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _search_meta_objects(
data_attrs: List = [],
paginated: bool = False,
query_params: Optional[Dict] = None,
extra_kwargs: Optional[Dict] = None,
page_size: int = 100,
) -> Union[List[dict], Tuple[Dict, Dict]]:

Expand All @@ -59,6 +60,9 @@ def _search_meta_objects(
return []

object_filters = {"type": ot_url, "data_attrs": []}
if extra_kwargs:
object_filters.update(extra_kwargs)

if zaaktype:
catalogus = fetch_catalogus(zaaktype.catalogus)
object_filters["data_attrs"] += [
Expand Down Expand Up @@ -116,10 +120,7 @@ def create_meta_object_and_relate_to_zaak(

# Get latest version of objecttype
latest_version = fetch_objecttype(max(objecttype["versions"]))

# Set meta to always True
data = camelize(data, **camelize_settings)
data["meta"] = True

result = create_object(
{
Expand Down Expand Up @@ -522,6 +523,7 @@ def get_review_requests_paginated(
zaak: Optional[Zaak] = None,
requester: Optional[User] = None,
not_locked: Optional[bool] = False,
latest_version: Optional[bool] = True,
page_size: int = 100,
) -> Tuple[List[Dict], Dict]:

Expand All @@ -533,10 +535,15 @@ def get_review_requests_paginated(
data_attrs += [f"requester__username__exact__{requester.username}"]
if not_locked:
data_attrs += [f"locked__icontains__false"]
if latest_version:
future_date = datetime.date.today() + datetime.timedelta(
days=100 * 365
) # 100 years lawl

response, query_params = _search_meta_objects(
"review_request_objecttype",
data_attrs=data_attrs,
extra_kwargs={"date": future_date.isoformat()} if latest_version else None,
paginated=True,
page_size=page_size,
query_params=query_params,
Expand Down
14 changes: 0 additions & 14 deletions backend/src/zac/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,13 +1498,6 @@ class ObjecttypeVersionProxySerializer(ProxySerializer):
PROXY_SCHEMA_BASE = settings.EXTERNAL_API_SCHEMAS["OBJECTTYPES_API_SCHEMA"]
PROXY_SCHEMA_PATH = ["components", "schemas", "ObjectVersion"]

def to_representation(self, *args, **kwargs):
data = super().to_representation(*args, **kwargs)
if "meta" in data.get("jsonSchema", {}).get("properties", {}):
del data["jsonSchema"]["properties"]["meta"]

return data


class ObjectProxySerializer(ProxySerializer):
"""
Expand All @@ -1523,13 +1516,6 @@ class ObjectProxySerializer(ProxySerializer):
),
)

def to_representation(self, *args, **kwargs):
data = super().to_representation(*args, **kwargs)
if "meta" in data.get("record", {}).get("data", {}):
del data["record"]["data"]["meta"]

return data


class PaginatedObjectProxySerializer(ProxySerializer):
PROXY_SCHEMA_BASE = settings.EXTERNAL_API_SCHEMAS["OBJECTS_API_SCHEMA"]
Expand Down
1 change: 1 addition & 0 deletions backend/src/zac/werkvoorraad/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def get(self, request, *args, **kwargs):
query_params=self.get_query_params(),
requester=request.user,
not_locked=True,
latest_version=True,
)
review_requests = self.resolve_zaken(results["results"])
review_requests = self.resolve_reviews(results["results"])
Expand Down
Loading