-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove contact box from poi form and refactor migration
- Loading branch information
Showing
9 changed files
with
96 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
integreat_cms/cms/migrations/0112_remove_poi_email_remove_poi_phone_number_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
integreat_cms/cms/templates/pois/poi_form_sidebar/contact_box.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters