Skip to content

Commit

Permalink
Remove contact data fields from poi
Browse files Browse the repository at this point in the history
Remove contact box from poi form and refactor migration
  • Loading branch information
lunars97 committed Dec 18, 2024
1 parent f394887 commit fed7ff1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 112 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
9 changes: 0 additions & 9 deletions integreat_cms/cms/fixtures/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,6 @@
"location_on_map": false,
"icon": null,
"archived": false,
"website": "",
"email": "",
"phone_number": "",
"category": 2,
"temporarily_closed": false,
"appointment_url": "",
Expand Down Expand Up @@ -921,9 +918,6 @@
"location_on_map": false,
"icon": null,
"archived": false,
"website": "",
"email": "",
"phone_number": "",
"category": 1,
"temporarily_closed": false,
"appointment_url": "",
Expand Down Expand Up @@ -955,9 +949,6 @@
"location_on_map": false,
"icon": null,
"archived": false,
"website": "",
"email": "",
"phone_number": "",
"category": 2,
"temporarily_closed": false,
"appointment_url": "",
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,59 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django.db import migrations

if TYPE_CHECKING:
from django.apps.registry import Apps
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


# pylint: disable=unused-argument
def create_primary_contact(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""
Create primary contact for each POI and remove E-mail, phone number and website fields from POI model
:param apps: The configuration of installed applications
:param schema_editor: The database abstraction layer that creates actual SQL code
"""
POI = apps.get_model("cms", "POI")
Contact = apps.get_model("cms", "Contact")
for poi in POI.objects.all():
if not Contact.objects.filter(location=poi, point_of_contact_for="").exists():
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.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,5 +1,6 @@
from __future__ import annotations

import importlib
import logging
from typing import TYPE_CHECKING

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 @@ -24,36 +24,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>
1 change: 0 additions & 1 deletion integreat_cms/cms/templates/pois/poi_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ <h3 class="font-bold text-black heading">
</div>
<div id="right-sidebar-column"
class="flex flex-col flex-wrap 3xl:col-end-3 4xl:col-end-auto md:w-full">
{% include "./poi_form_sidebar/contact_box.html" with box_id="poi-contact" %}
{% if poi_form.instance.id and perms.cms.view_contact %}
{% include "./poi_form_sidebar/related_contacts_box.html" with box_id="poi-related-contacts" %}
{% endif %}
Expand Down
31 changes: 0 additions & 31 deletions integreat_cms/cms/templates/pois/poi_form_sidebar/contact_box.html

This file was deleted.

43 changes: 18 additions & 25 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2770,16 +2770,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 @@ -4915,27 +4914,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 @@ -11151,6 +11129,21 @@ msgstr ""
"Diese Seite konnte nicht importiert werden, da sie zu einer anderen Region "
"gehört ({})."

#~ msgid "Contact details"
#~ msgstr "Kontaktdaten"

#~ 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 links"
#~ msgstr "Ungültige Links"

Expand Down

0 comments on commit fed7ff1

Please sign in to comment.