0004_create_settings.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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": "captcha_type", "dry_value": "no", "is_public": True},
  15. {"setting": "default_avatar", "dry_value": "gravatar"},
  16. {"setting": "default_gravatar_fallback", "dry_value": "dynamic"},
  17. {"setting": "email_footer"},
  18. {
  19. "setting": "forum_address",
  20. "dry_value": getattr(settings, "MISAGO_ADDRESS", None),
  21. "is_public": True,
  22. },
  23. {"setting": "forum_footnote", "is_public": True},
  24. {"setting": "forum_name", "dry_value": "Misago", "is_public": True},
  25. {"setting": "index_header", "is_public": True},
  26. {"setting": "index_meta_description", "is_public": True},
  27. {"setting": "index_title", "is_public": True},
  28. {"setting": "logo", "python_type": "image", "is_public": True},
  29. {"setting": "logo_small", "python_type": "image", "is_public": True},
  30. {"setting": "logo_text", "dry_value": "Misago", "is_public": True},
  31. {
  32. "setting": "post_length_max",
  33. "python_type": "int",
  34. "dry_value": 60000,
  35. "is_public": True,
  36. },
  37. {
  38. "setting": "post_length_min",
  39. "python_type": "int",
  40. "dry_value": 5,
  41. "is_public": True,
  42. },
  43. {"setting": "qa_answers"},
  44. {"setting": "qa_help_text"},
  45. {"setting": "qa_question"},
  46. {"setting": "recaptcha_secret_key"},
  47. {"setting": "recaptcha_site_key", "is_public": True},
  48. {
  49. "setting": "signature_length_max",
  50. "python_type": "int",
  51. "dry_value": 256,
  52. "is_public": True,
  53. },
  54. {"setting": "subscribe_reply", "dry_value": "watch_email"},
  55. {"setting": "subscribe_start", "dry_value": "watch_email"},
  56. {
  57. "setting": "thread_title_length_max",
  58. "python_type": "int",
  59. "dry_value": 90,
  60. "is_public": True,
  61. },
  62. {
  63. "setting": "thread_title_length_min",
  64. "python_type": "int",
  65. "dry_value": 5,
  66. "is_public": True,
  67. },
  68. {"setting": "username_length_min", "python_type": "int", "dry_value": 3},
  69. {"setting": "username_length_max", "python_type": "int", "dry_value": 14},
  70. ]
  71. removed_settings = ["forum_branding_display", "forum_branding_text"]
  72. def create_settings(apps, _):
  73. # This migration builds list of existing settings, and then
  74. # creates settings not already in the database
  75. Setting = apps.get_model("misago_conf", "Setting")
  76. # Update existing settings and add new ones
  77. existing_settings = list(Setting.objects.values_list("setting", flat=True))
  78. for setting in default_settings:
  79. if setting["setting"] in existing_settings:
  80. continue # skip already existing setting (migration on existing forum)
  81. data = setting.copy()
  82. if "python_type" in data and "dry_value" in data:
  83. data["dry_value"] = dehydrate_value(data["python_type"], data["dry_value"])
  84. Setting.objects.create(**setting)
  85. # Delete deprecated settings
  86. Setting.objects.filter(setting__in=removed_settings).delete()
  87. class Migration(migrations.Migration):
  88. dependencies = [
  89. ("misago_conf", "0003_simplify_models"),
  90. ("misago_core", "0003_delete_cacheversion"),
  91. ("misago_threads", "0012_set_dj_partial_indexes"),
  92. ("misago_users", "0020_set_dj_partial_indexes"),
  93. ]
  94. operations = [migrations.RunPython(create_settings)]