feat: Add general field-based status and migrate data
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# Generated by Django 5.2.1 on 2025-08-30 21:51
|
||||
import logging
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def map_status(adoption_notice_status):
|
||||
minor = adoption_notice_status.minor_status
|
||||
|
||||
if minor == "searching":
|
||||
return "active_searching"
|
||||
if minor == "interested":
|
||||
return "active_interested"
|
||||
|
||||
if minor == "waiting_for_review":
|
||||
return "awaiting_action_waiting_for_review"
|
||||
if minor == "needs_additional_info":
|
||||
return "awaiting_action_needs_additional_info"
|
||||
|
||||
if minor == "successful_with_notfellchen":
|
||||
return "closed_successful_with_notfellchen"
|
||||
if minor == "successful_without_notfellchen":
|
||||
return "closed_successful_without_notfellchen"
|
||||
if minor == "animal_died":
|
||||
return "closed_animal_died"
|
||||
if minor == "closed_for_other_adoption_notice":
|
||||
return "closed_for_other_adoption_notice"
|
||||
if minor == "not_open_for_adoption_anymore":
|
||||
return "closed_not_open_for_adoption_anymore"
|
||||
if minor == "other":
|
||||
return "closed_other"
|
||||
|
||||
if minor == "against_the_rules":
|
||||
return "disabled_against_the_rules"
|
||||
if minor == "unchecked":
|
||||
return "disabled_unchecked"
|
||||
if minor in ["missing_information", "technical_error"]:
|
||||
return "disabled_other"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def migrate_status(apps, schema_editor):
|
||||
# We can't import the model directly as it may be a newer
|
||||
# version than this migration expects. We use the historical version.
|
||||
AdoptionNoticeStatus = apps.get_model("fellchensammlung", "AdoptionNoticeStatus")
|
||||
AdoptionNotice = apps.get_model("fellchensammlung", "AdoptionNotice")
|
||||
for ans in AdoptionNoticeStatus.objects.all():
|
||||
adoption_notice = AdoptionNotice.objects.get(id=ans.adoption_notice.id)
|
||||
new_status = map_status(ans)
|
||||
logging.debug(f"{ans.minor_status} -> {new_status}")
|
||||
adoption_notice.adoption_notice_status = map_status(ans)
|
||||
adoption_notice.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('fellchensammlung', '0060_alter_adoptionnotice_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_status),
|
||||
]
|
||||
Reference in New Issue
Block a user