Skip to content

Commit 72be286

Browse files
committed
project-search: add identifer to search field
1 parent 1484c4f commit 72be286

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

meinberlin/apps/kiezradar/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ def get_search_profiles_for_project(project: Project) -> QuerySet[SearchProfile]
197197
)
198198
if project.administrative_district:
199199
search_term += " " + project.administrative_district.name
200+
if hasattr(project, "externalproject"):
201+
if hasattr(project.externalproject, "bplan"):
202+
search_term += " " + project.externalproject.bplan.identifier
200203
for topic in project.topic_names:
201204
search_term += " " + topic
202205
if connection.vendor == "postgresql":

meinberlin/apps/projects/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def get_public_projects() -> QuerySet[Project]:
2929
is_archived=False,
3030
)
3131
.order_by("created")
32-
.select_related("administrative_district", "organisation")
32+
.select_related(
33+
"administrative_district", "organisation", "externalproject__bplan"
34+
)
3335
.prefetch_related(
3436
"moderators",
3537
"plans",

meinberlin/apps/projects/serializers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ProjectSerializer(
6565
type = serializers.SerializerMethodField()
6666
url = serializers.SerializerMethodField()
6767
topics = serializers.SerializerMethodField()
68+
identifier = serializers.SerializerMethodField()
6869

6970
def __init__(self, *args, **kwargs):
7071
self.now = kwargs.pop("now")
@@ -84,6 +85,7 @@ class Meta:
8485
"description",
8586
"district",
8687
"future_phase",
88+
"identifier",
8789
"organisation",
8890
"participation",
8991
"participation_active",
@@ -248,6 +250,11 @@ def get_point_label(self, instance):
248250
def get_cost(self, instance):
249251
return ""
250252

253+
def get_identifier(self, instance):
254+
if hasattr(instance, "externalproject"):
255+
if hasattr(instance.externalproject, "bplan"):
256+
return instance.externalproject.bplan.identifier
257+
251258

252259
class ActiveProjectSerializer(ProjectSerializer):
253260
def seconds_in_units(self, seconds):

meinberlin/react/projects/filter-projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const statusNames = ['active', 'future', 'past']
2121

2222
export const filterProjects = (items, appliedFilters, kiezradars, topics, projectState) => {
2323
const { search, topics: activeTopics, districts, organisation, participations, plansOnly, kiezradars: activeKiezradars } = appliedFilters
24-
2524
return items.filter((item) => {
2625
const isWithinAnyRadius =
2726
item.point && kiezradars.some(kiezradar =>
@@ -37,6 +36,7 @@ export const filterProjects = (items, appliedFilters, kiezradars, topics, projec
3736
isInTitle(item.district, search) ||
3837
isInTitle(item.organisation, search) ||
3938
isInTitle(item.description, search) ||
39+
isInTitle(item.identifier, search) ||
4040
isInTopic(topics, item.topics, search)) &&
4141
(projectState.includes(statusNames[item.status])) &&
4242
(!plansOnly || item.type === 'plan') &&

tests/kiezradar/test_search_profile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ def test_searchprofile_filter_query(
315315
assert list(result) == expected_profiles
316316

317317

318+
@pytest.mark.django_db
319+
def test_searchprofile_filter_query_bplan(
320+
search_profile_factory,
321+
kiezradar_query_factory,
322+
bplan_factory,
323+
):
324+
bplan = bplan_factory(identifier="B30-1 A30-bplan 2024")
325+
bplan_profile = search_profile_factory(
326+
query=kiezradar_query_factory(text="A30-bplan")
327+
)
328+
329+
result = get_search_profiles_for_project(bplan).order_by("pk")
330+
assert list(result) == [bplan_profile]
331+
332+
318333
@pytest.mark.django_db
319334
def test_searchprofile_filter_kiezradar(
320335
user, phase_factory, search_profile_factory, kiez_radar_factory

tests/projects/test_serializer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_project_serializer(
3535
tile_image_alt_text="img_alt",
3636
)
3737
external_project_factory()
38-
bplan_factory()
38+
bplan_factory(identifier="bplan 2013-01-01")
3939

4040
now = parse("2013-01-01 18:00:00+01:00")
4141
yesterday = now - timezone.timedelta(days=1)
@@ -165,3 +165,5 @@ def test_project_serializer(
165165
assert not project_data[5]["tile_image_alt_text"]
166166

167167
assert project_data[0]["point"] == geojson_point
168+
169+
assert project_data[5]["identifier"] == "bplan 2013-01-01"

0 commit comments

Comments
 (0)