Skip to content

Commit

Permalink
Remove contact data fields from poi
Browse files Browse the repository at this point in the history
  • Loading branch information
lunars97 committed Nov 30, 2024
1 parent 8490250 commit 543cc34
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 71 deletions.
7 changes: 4 additions & 3 deletions integreat_cms/api/v3/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def transform_poi_translation(poi_translation: POITranslation) -> dict[str, Any]
"""

poi = poi_translation.poi
contact = poi.get_primary_contact()
# 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 @@ -87,9 +88,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": poi.website or None,
"email": poi.email or None,
"phone_number": poi.phone_number or None,
"website": contact.website or None,
"email": contact.email or None,
"phone_number": contact.phone_number or None,
"category": transform_location_category(
poi.category, poi_translation.language.slug
),
Expand Down
3 changes: 0 additions & 3 deletions integreat_cms/cms/forms/pois/poi_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class Meta:
"longitude",
"location_on_map",
"icon",
"website",
"email",
"phone_number",
"category",
"opening_hours",
"temporarily_closed",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django.db import migrations

if TYPE_CHECKING:
from django.apps.registry import Apps


def create_primary_contact(apps: Apps) -> None:
"""
Create primary contact from the poi contact data
:param apps: The configuration of installed applications
"""
POI = apps.get_model("cms", "POI")
Contact = apps.get_model("cms", "Contact")
for poi in POI.objects.all():
if poi.email or poi.phone_number or poi.website:
primary_contact = Contact.objects.create(
email=poi.email,
phone_number=poi.phone_number,
website=poi.website,
point_of_contact_for="",
name="",
location=poi,
)
primary_contact.save()


class Migration(migrations.Migration):
"""
Migrate contact data from poi to Contact model
"""

dependencies = [
("cms", "0111_alter_language_language_color"),
]

operations = [
migrations.RunPython(create_primary_contact, migrations.RunPython.noop),
migrations.RemoveField(
model_name="poi",
name="email",
),
migrations.RemoveField(
model_name="poi",
name="phone_number",
),
migrations.RemoveField(
model_name="poi",
name="website",
),
]
23 changes: 15 additions & 8 deletions integreat_cms/cms/models/pois/poi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import importlib
from typing import TYPE_CHECKING

from django.core.validators import MaxValueValidator, MinValueValidator
Expand Down Expand Up @@ -80,14 +81,6 @@ class POI(AbstractContentModel):
verbose_name=_("archived"),
help_text=_("Whether or not the location is read-only and hidden in the API."),
)
website = models.URLField(max_length=250, blank=True, verbose_name=_("website"))
email = models.EmailField(
blank=True,
verbose_name=_("email address"),
)
phone_number = models.CharField(
max_length=250, blank=True, verbose_name=_("phone number")
)
category = models.ForeignKey(
POICategory,
on_delete=models.PROTECT,
Expand Down Expand Up @@ -148,6 +141,20 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,4 @@
rel="noopener noreferrer">
{% translate "Open on Google Maps" %}
</a>
<label class="secondary">
{% translate "Contact details" %}
</label>
<div>
<p>
{% translate "E-mail address: " %}
<span>
{% if poi.email %}
{{ poi.email }}
{% endif %}
</span>
<span class="{% if poi.email %}hidden{% endif %}">{% translate "Not provided" %}</span>
</p>
<p>
{% translate "Phone number: " %}
<span>
{% if poi.phone_number %}
{{ poi.phone_number }}
{% endif %}
</span>
<span class="{% if poi.phone_number %}hidden{% endif %}">{% translate "Not provided" %}</span>
</p>
<p>
{% translate "Website: " %}
<span>
{% if poi.website %}
{{ poi.website }}
{% endif %}
</span>
<span class="{% if poi.website %}hidden{% endif %}">{% translate "Not provided" %}</span>
</p>
</div>
</div>
44 changes: 19 additions & 25 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2769,16 +2769,15 @@ msgstr "Name"
msgid "location"
msgstr "Ort"

#: cms/models/contact/contact.py cms/models/pois/poi.py
#: cms/models/contact/contact.py
msgid "email address"
msgstr "E-Mail-Adresse"

#: cms/models/contact/contact.py cms/models/pois/poi.py
#: cms/models/contact/contact.py
msgid "phone number"
msgstr "Telefonnummer"

#: cms/models/contact/contact.py cms/models/pois/poi.py
#: cms/models/users/organization.py
#: cms/models/contact/contact.py cms/models/users/organization.py
msgid "website"
msgstr "Webseite"

Expand Down Expand Up @@ -4910,27 +4909,6 @@ msgstr "Adresse"
msgid "Open on Google Maps"
msgstr "Auf Google Maps öffnen"

#: cms/templates/ajax_poi_form/_poi_address_container.html
#: cms/templates/pois/poi_form_sidebar/contact_box.html
msgid "Contact details"
msgstr "Kontaktdaten"

#: cms/templates/ajax_poi_form/_poi_address_container.html
msgid "E-mail address: "
msgstr "E-Mail-Adresse: "

#: cms/templates/ajax_poi_form/_poi_address_container.html
msgid "Not provided"
msgstr "Keine Angabe"

#: cms/templates/ajax_poi_form/_poi_address_container.html
msgid "Phone number: "
msgstr "Telefonnummer: "

#: cms/templates/ajax_poi_form/_poi_address_container.html
msgid "Website: "
msgstr "Website: "

#: cms/templates/ajax_poi_form/_poi_form_widget.html
#: cms/templates/events/event_form.html cms/templates/imprint/imprint_form.html
#: cms/templates/imprint/imprint_sbs.html cms/templates/pages/page_form.html
Expand Down Expand Up @@ -7716,6 +7694,10 @@ msgstr[1] "Löschen Sie zuerst diese Kontakte, um den Ort zu löschen:"
msgid "Delete this location"
msgstr "Diesen Ort löschen"

#: cms/templates/pois/poi_form_sidebar/contact_box.html
msgid "Contact details"
msgstr "Kontaktdaten"

#: cms/templates/pois/poi_form_sidebar/position_box.html
msgid "Position"
msgstr "Position"
Expand Down Expand Up @@ -11121,6 +11103,18 @@ msgstr ""
"Diese Seite konnte nicht importiert werden, da sie zu einer anderen Region "
"gehört ({})."

#~ msgid "E-mail address: "
#~ msgstr "E-Mail-Adresse: "

#~ msgid "Not provided"
#~ msgstr "Keine Angabe"

#~ msgid "Phone number: "
#~ msgstr "Telefonnummer: "

#~ msgid "Website: "
#~ msgstr "Website: "

#~ msgid "Invalid"
#~ msgstr "Ungültig"

Expand Down

0 comments on commit 543cc34

Please sign in to comment.