Skip to content

Commit

Permalink
Fix Contact module not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
lunars97 committed Dec 20, 2024
1 parent 400225f commit bd43e82
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 24 deletions.
13 changes: 9 additions & 4 deletions integreat_cms/api/v3/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from ...cms.constants import status
from ...cms.models import POICategoryTranslation
from ...cms.models import Contact
from ...cms.models.pois.poi import get_default_opening_hours
from ...core.utils.strtobool import strtobool
from ..decorators import json_response
Expand Down Expand Up @@ -70,7 +71,11 @@ def transform_poi_translation(poi_translation: POITranslation) -> dict[str, Any]
"""

poi = poi_translation.poi
contact = poi.get_primary_contact()

primary_contact = Contact.objects.filter(
location=poi, point_of_contact_for="", name=""
).first()

# Only return opening hours if they differ from the default value and the location is not temporarily closed
opening_hours = None
if not poi.temporarily_closed and poi.opening_hours != get_default_opening_hours():
Expand All @@ -88,9 +93,9 @@ def transform_poi_translation(poi_translation: POITranslation) -> dict[str, Any]
"available_languages": poi_translation.available_languages_dict,
"icon": poi.icon.url if poi.icon else None,
"thumbnail": poi.icon.thumbnail_url if poi.icon else None,
"website": contact.website or None,
"email": contact.email or None,
"phone_number": contact.phone_number or None,
"website": primary_contact.website if primary_contact else None,
"email": primary_contact.email if primary_contact else None,
"phone_number": primary_contact.phone_number if primary_contact else None,
"category": transform_location_category(
poi.category, poi_translation.language.slug
),
Expand Down
15 changes: 0 additions & 15 deletions integreat_cms/cms/models/pois/poi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import importlib
import logging
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -141,20 +140,6 @@ def get_translation_model() -> ModelBase:
"""
return POITranslation

@property
def get_primary_contact(self) -> None:
"""
Returns the primary contact from Contact
"""
contact_module = importlib.import_module("Contact")

primary_contact = contact_module.objects.filter(
location=self,
point_of_contact_for="",
name="",
).first()
return primary_contact

def delete(self, *args: list, **kwargs: dict) -> bool:
r"""
Deletes the poi
Expand Down
10 changes: 5 additions & 5 deletions tests/api/api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@
"/augsburg/de/wp-json/extensions/v3/locations/",
"tests/api/expected-outputs/augsburg_de_locations.json",
200,
5,
6,
),
(
"/api/v3/augsburg/en/locations/",
"/augsburg/en/wp-json/extensions/v3/locations/",
"tests/api/expected-outputs/augsburg_en_locations.json",
200,
5,
6,
),
(
"/api/v3/augsburg/ar/locations/",
"/augsburg/ar/wp-json/extensions/v3/locations/",
"tests/api/expected-outputs/augsburg_ar_locations.json",
200,
5,
6,
),
(
"/api/v3/augsburg/non-existing/locations/",
Expand Down Expand Up @@ -233,14 +233,14 @@
"/nurnberg/de/wp-json/extensions/v3/locations/",
"tests/api/expected-outputs/nurnberg_de_locations.json",
200,
5,
6,
),
(
"/api/v3/nurnberg/en/locations/",
"/nurnberg/en/wp-json/extensions/v3/locations/",
"tests/api/expected-outputs/nurnberg_en_locations.json",
200,
5,
6,
),
(
"/api/v3/nurnberg/ar/locations/",
Expand Down
3 changes: 3 additions & 0 deletions tests/api/expected-outputs/augsburg_ar_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"icon": null,
"thumbnail": null,
"website": null,
"email": null,
"phone_number": null,
"category": {
"id": 2,
"name": "Beh\u00f6rde/Amt",
Expand Down
3 changes: 3 additions & 0 deletions tests/api/expected-outputs/augsburg_de_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"icon": null,
"thumbnail": null,
"website": null,
"email": null,
"phone_number": null,
"category": {
"id": 2,
"name": "Beh\u00f6rde/Amt",
Expand Down
3 changes: 3 additions & 0 deletions tests/api/expected-outputs/augsburg_en_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"icon": null,
"thumbnail": null,
"website": null,
"email": null,
"phone_number": null,
"category": {
"id": 2,
"name": "Authority/Office",
Expand Down
3 changes: 3 additions & 0 deletions tests/api/expected-outputs/nurnberg_de_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"icon": null,
"thumbnail": null,
"website": null,
"email": null,
"phone_number": null,
"category": {
"id": 1,
"name": "Beratungsstelle",
Expand Down
3 changes: 3 additions & 0 deletions tests/api/expected-outputs/nurnberg_en_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"icon": null,
"thumbnail": null,
"website": null,
"email": null,
"phone_number": null,
"category": {
"id": 1,
"name": "Advice Center",
Expand Down

0 comments on commit bd43e82

Please sign in to comment.