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 28, 2024
1 parent 1e6dde2 commit b22737a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 73 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,57 @@
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


def create_primary_contact(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""
Create primary contact from the poi contact data
: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 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", "0108_rename_contact_title_to_point_of_contact_for"),
]

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
Expand Up @@ -80,14 +80,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 +140,21 @@ def get_translation_model() -> ModelBase:
"""
return POITranslation

@property
def get_primary_contact(self) -> None:
"""
Returns the primary contact from Contact
"""

from cms.models import Contact

primary_contact = Contact.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
33 changes: 0 additions & 33 deletions integreat_cms/cms/templates/ajax_poi_form/poi_box.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,6 @@
rel="noopener noreferrer">
{% translate "Open on Google Maps" %}
</a>
<label class="secondary">
{% translate "Contact details" %}
</label>
<div id="poi-contact-information">
<p>
{% translate "E-mail address: " %}
<span id="email">
{% if poi.email %}
{{ poi.email }}
{% endif %}
</span>
<span id="no-email" class="{% if poi.email %}hidden{% endif %}">{% translate "Not provided" %}</span>
</p>
<p>
{% translate "Phone number: " %}
<span id="phone_number">
{% if poi.phone_number %}
{{ poi.phone_number }}
{% endif %}
</span>
<span id="no-phone_number"
class="{% if poi.phone_number %}hidden{% endif %}">{% translate "Not provided" %}</span>
</p>
<p>
{% translate "Website: " %}
<span id="website">
{% if poi.website %}
{{ poi.website }}
{% endif %}
</span>
<span id="no-website" class="{% if poi.website %}hidden{% endif %}">{% translate "Not provided" %}</span>
</p>
</div>
</div>
<div id="poi-ajax-success-message"
class="bg-green-100 border-l-4 border-green-500 text-green-800 px-4 py-3 hidden">
Expand Down
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" %}
{% include "./poi_form_sidebar/opening_hours_box.html" with box_id="poi-opening-hours" no_padding=True %}
{% include "./poi_form_sidebar/category_box.html" with box_id="poi-category" %}
{% include "./poi_form_sidebar/icon_box.html" with box_id="poi-icon" %}
Expand Down
28 changes: 3 additions & 25 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2733,16 +2733,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 @@ -4872,27 +4871,6 @@ msgstr "Adresse"
msgid "Open on Google Maps"
msgstr "Auf Google Maps öffnen"

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

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

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

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

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

#: cms/templates/ajax_poi_form/poi_box.html
msgid "The new location was successfully created."
msgstr "Ein neuer Ort wurde erfolgreich erstellt."
Expand Down

0 comments on commit b22737a

Please sign in to comment.