-
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
6 changed files
with
93 additions
and
71 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
55 changes: 55 additions & 0 deletions
55
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,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", | ||
), | ||
] |
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