0035_remove_googleapisettings_site_and_more.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Generated by Django 4.0.7 on 2022-08-10 20:37
  2. from django.db import migrations, models
  3. def copy_settings(apps, schema_editor):
  4. LayoutSettings = apps.get_model("coderedcms", "LayoutSettings")
  5. GeneralSettings = apps.get_model("coderedcms", "GeneralSettings")
  6. GoogleApiSettings = apps.get_model("coderedcms", "GoogleApiSettings")
  7. MailchimpApiSettings = apps.get_model("coderedcms", "MailchimpApiSettings")
  8. for s in LayoutSettings.objects.all():
  9. gen = GeneralSettings.objects.filter(site=s.site).first()
  10. goog = GoogleApiSettings.objects.filter(site=s.site).first()
  11. mc = MailchimpApiSettings.objects.filter(site=s.site).first()
  12. if gen:
  13. s.external_new_tab = gen.external_new_tab
  14. s.from_email_address = gen.from_email_address
  15. s.search_num_results = gen.search_num_results
  16. if goog:
  17. s.google_maps_api_key = goog.google_maps_api_key
  18. if mc:
  19. s.mailchimp_api_key = mc.mailchimp_api_key
  20. s.save()
  21. class Migration(migrations.Migration):
  22. dependencies = [
  23. ('coderedcms', '0034_delete_adasettings'),
  24. ]
  25. operations = [
  26. migrations.AlterModelOptions(
  27. name='layoutsettings',
  28. options={'verbose_name': 'CRX Settings'},
  29. ),
  30. migrations.AddField(
  31. model_name='layoutsettings',
  32. name='external_new_tab',
  33. field=models.BooleanField(default=False, verbose_name='Open all external links in new tab'),
  34. ),
  35. migrations.AddField(
  36. model_name='layoutsettings',
  37. name='from_email_address',
  38. field=models.CharField(blank=True, help_text='The default email address this site appears to send from. For example: "sender@example.com" or "Sender Name <sender@example.com>" (without quotes)', max_length=255, verbose_name='From email address'),
  39. ),
  40. migrations.AddField(
  41. model_name='layoutsettings',
  42. name='google_maps_api_key',
  43. field=models.CharField(blank=True, help_text='The API Key used for Google Maps.', max_length=255, verbose_name='Google Maps API Key'),
  44. ),
  45. migrations.AddField(
  46. model_name='layoutsettings',
  47. name='mailchimp_api_key',
  48. field=models.CharField(blank=True, help_text='The API Key used for Mailchimp.', max_length=255, verbose_name='Mailchimp API Key'),
  49. ),
  50. migrations.AddField(
  51. model_name='layoutsettings',
  52. name='search_num_results',
  53. field=models.PositiveIntegerField(default=10, verbose_name='Number of results per page'),
  54. ),
  55. # Copy the settings over.
  56. migrations.RunPython(copy_settings),
  57. # Delete the old fields and models.
  58. migrations.RemoveField(
  59. model_name='generalsettings',
  60. name='site',
  61. ),
  62. migrations.RemoveField(
  63. model_name='googleapisettings',
  64. name='site',
  65. ),
  66. migrations.RemoveField(
  67. model_name='mailchimpapisettings',
  68. name='site',
  69. ),
  70. migrations.DeleteModel(
  71. name='GeneralSettings',
  72. ),
  73. migrations.DeleteModel(
  74. name='GoogleApiSettings',
  75. ),
  76. migrations.DeleteModel(
  77. name='MailchimpApiSettings',
  78. ),
  79. ]