Skip to content

Commit

Permalink
apps/plans: remove published_projects from PlanSerializer use Project…
Browse files Browse the repository at this point in the history
…Serializer directly in PlanDetailView
  • Loading branch information
goapunk committed Jan 9, 2025
1 parent 86c275f commit 6e4827b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 5 additions & 3 deletions meinberlin/apps/plans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from django.views import generic
Expand All @@ -26,7 +27,7 @@
from meinberlin.apps.plans import models
from meinberlin.apps.plans.forms import PlanForm
from meinberlin.apps.plans.models import Plan
from meinberlin.apps.plans.serializers import PlanSerializer
from meinberlin.apps.projects.serializers import ProjectSerializer


class FreeTextFilterWidget(filter_widgets.FreeTextFilterWidget):
Expand All @@ -50,9 +51,10 @@ class PlanDetailView(rules_mixins.PermissionRequiredMixin, CanonicalURLDetailVie

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
serializer = PlanSerializer(self.object)
context["published_projects"] = json.dumps(
serializer.data.get("published_projects")
ProjectSerializer(
self.object.published_projects, many=True, now=timezone.now()
).data
)
context["polygon"] = settings.BERLIN_POLYGON
return context
Expand Down
15 changes: 6 additions & 9 deletions tests/plans/test_views_integration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest
from dateutil.parser import parse
from django.core.cache import cache
Expand Down Expand Up @@ -286,16 +288,11 @@ def test_plan_view_with_published_projects_and_topics(
organisation = plan.organisation
initiator = organisation.initiators.first()
client.login(username=initiator.email, password="password")
url = reverse("plans-list")
response = client.get(url)
items = response.data
assert response.status_code == 200
assert items[0]["published_projects"] is not None
assert items[0]["published_projects"][0]["title"] in [
assert response.context_data["published_projects"] is not None
published_projects = json.loads(response.context_data["published_projects"])
assert published_projects[0]["title"] in [
project1.name,
project2.name,
project3.name,
]
published_projects_count = len(items[0]["published_projects"])
assert items[0]["published_projects_count"] == published_projects_count
assert len(items[0]["topics"]) == plan.topics.count()
assert len(published_projects) == 3

0 comments on commit 6e4827b

Please sign in to comment.