0004_create_settings.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Generated by Django 2.2.1 on 2019-05-19 00:16
  2. from django.conf import settings
  3. from django.db import migrations
  4. from ..hydrators import dehydrate_value
  5. default_settings = [
  6. {"setting": "account_activation", "dry_value": "none", "is_public": True},
  7. {"setting": "allow_custom_avatars", "python_type": "bool", "dry_value": True},
  8. {
  9. "setting": "avatar_upload_limit",
  10. "python_type": "int",
  11. "dry_value": 1536,
  12. "is_public": True,
  13. },
  14. {"setting": "blank_avatar", "python_type": "image"},
  15. {"setting": "captcha_type", "dry_value": "no", "is_public": True},
  16. {"setting": "default_avatar", "dry_value": "gravatar"},
  17. {"setting": "default_gravatar_fallback", "dry_value": "dynamic"},
  18. {"setting": "email_footer"},
  19. {
  20. "setting": "forum_address",
  21. "dry_value": getattr(settings, "MISAGO_ADDRESS", None),
  22. "is_public": True,
  23. },
  24. {"setting": "forum_footnote", "is_public": True},
  25. {"setting": "forum_name", "dry_value": "Misago", "is_public": True},
  26. {"setting": "google_tracking_id"},
  27. {"setting": "google_site_verification"},
  28. {"setting": "index_header", "is_public": True},
  29. {"setting": "index_meta_description", "is_public": True},
  30. {"setting": "index_title", "is_public": True},
  31. {"setting": "logo", "python_type": "image", "is_public": True},
  32. {"setting": "logo_small", "python_type": "image", "is_public": True},
  33. {"setting": "logo_text", "dry_value": "Misago", "is_public": True},
  34. {
  35. "setting": "post_length_max",
  36. "python_type": "int",
  37. "dry_value": 60000,
  38. "is_public": True,
  39. },
  40. {
  41. "setting": "post_length_min",
  42. "python_type": "int",
  43. "dry_value": 5,
  44. "is_public": True,
  45. },
  46. {"setting": "og_image", "python_type": "image"},
  47. {
  48. "setting": "og_image_avatar_on_profile",
  49. "python_type": "bool",
  50. "dry_value": False,
  51. },
  52. {"setting": "og_image_avatar_on_thread", "python_type": "bool", "dry_value": False},
  53. {"setting": "qa_answers"},
  54. {"setting": "qa_help_text"},
  55. {"setting": "qa_question"},
  56. {"setting": "recaptcha_secret_key"},
  57. {"setting": "recaptcha_site_key", "is_public": True},
  58. {
  59. "setting": "signature_length_max",
  60. "python_type": "int",
  61. "dry_value": 256,
  62. "is_public": True,
  63. },
  64. {"setting": "subscribe_reply", "dry_value": "watch_email"},
  65. {"setting": "subscribe_start", "dry_value": "watch_email"},
  66. {
  67. "setting": "thread_title_length_max",
  68. "python_type": "int",
  69. "dry_value": 90,
  70. "is_public": True,
  71. },
  72. {
  73. "setting": "thread_title_length_min",
  74. "python_type": "int",
  75. "dry_value": 5,
  76. "is_public": True,
  77. },
  78. {"setting": "username_length_min", "python_type": "int", "dry_value": 3},
  79. {"setting": "username_length_max", "python_type": "int", "dry_value": 14},
  80. ]
  81. removed_settings = ["forum_branding_display", "forum_branding_text"]
  82. def create_settings(apps, _):
  83. # This migration builds list of existing settings, and then
  84. # creates settings not already in the database
  85. Setting = apps.get_model("misago_conf", "Setting")
  86. # Update existing settings and add new ones
  87. existing_settings = list(Setting.objects.values_list("setting", flat=True))
  88. for setting in default_settings:
  89. if setting["setting"] in existing_settings:
  90. continue # skip already existing setting (migration on existing forum)
  91. data = setting.copy()
  92. if "python_type" in data and "dry_value" in data:
  93. data["dry_value"] = dehydrate_value(data["python_type"], data["dry_value"])
  94. Setting.objects.create(**setting)
  95. # Delete deprecated settings
  96. Setting.objects.filter(setting__in=removed_settings).delete()
  97. class Migration(migrations.Migration):
  98. dependencies = [
  99. ("misago_conf", "0003_simplify_models"),
  100. ("misago_core", "0003_delete_cacheversion"),
  101. ("misago_threads", "0012_set_dj_partial_indexes"),
  102. ("misago_users", "0020_set_dj_partial_indexes"),
  103. ]
  104. operations = [migrations.RunPython(create_settings)]