0004_create_settings.py 3.3 KB

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