-
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.
- Loading branch information
Showing
7 changed files
with
79 additions
and
73 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
57 changes: 57 additions & 0 deletions
57
integreat_cms/cms/migrations/0109_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,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", | ||
), | ||
] |
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
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