0004_create_settings.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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": "attachment_403_image", "python_type": "image"},
  15. {"setting": "attachment_404_image", "python_type": "image"},
  16. {"setting": "blank_avatar", "python_type": "image"},
  17. {"setting": "captcha_type", "dry_value": "no", "is_public": True},
  18. {"setting": "default_avatar", "dry_value": "gravatar"},
  19. {"setting": "default_gravatar_fallback", "dry_value": "dynamic"},
  20. {"setting": "unused_attachments_lifetime", "python_type": "int", "dry_value": 24},
  21. {"setting": "email_footer"},
  22. {
  23. "setting": "forum_address",
  24. "dry_value": getattr(settings, "MISAGO_ADDRESS", None),
  25. "is_public": True,
  26. },
  27. {"setting": "forum_footnote", "is_public": True},
  28. {"setting": "forum_name", "dry_value": "Misago", "is_public": True},
  29. {"setting": "google_tracking_id"},
  30. {"setting": "google_site_verification"},
  31. {"setting": "index_header", "is_public": True},
  32. {"setting": "index_meta_description", "is_public": True},
  33. {"setting": "index_title", "is_public": True},
  34. {"setting": "logo", "python_type": "image", "is_public": True},
  35. {"setting": "logo_small", "python_type": "image", "is_public": True},
  36. {"setting": "logo_text", "dry_value": "Misago", "is_public": True},
  37. {"setting": "daily_post_limit", "python_type": "int", "dry_value": 600},
  38. {"setting": "hourly_post_limit", "python_type": "int", "dry_value": 100},
  39. {"setting": "post_attachments_limit", "python_type": "int", "dry_value": 16},
  40. {
  41. "setting": "post_length_max",
  42. "python_type": "int",
  43. "dry_value": 60000,
  44. "is_public": True,
  45. },
  46. {
  47. "setting": "post_length_min",
  48. "python_type": "int",
  49. "dry_value": 5,
  50. "is_public": True,
  51. },
  52. {"setting": "readtracker_cutoff", "python_type": "int", "dry_value": 40},
  53. {"setting": "threads_per_page", "python_type": "int", "dry_value": 26},
  54. {"setting": "posts_per_page", "python_type": "int", "dry_value": 18},
  55. {"setting": "posts_per_page_orphans", "python_type": "int", "dry_value": 6},
  56. {"setting": "events_per_page", "python_type": "int", "dry_value": 20},
  57. {"setting": "og_image", "python_type": "image"},
  58. {
  59. "setting": "og_image_avatar_on_profile",
  60. "python_type": "bool",
  61. "dry_value": False,
  62. },
  63. {"setting": "og_image_avatar_on_thread", "python_type": "bool", "dry_value": False},
  64. {"setting": "qa_answers"},
  65. {"setting": "qa_help_text"},
  66. {"setting": "qa_question"},
  67. {"setting": "recaptcha_secret_key"},
  68. {"setting": "recaptcha_site_key", "is_public": True},
  69. {
  70. "setting": "signature_length_max",
  71. "python_type": "int",
  72. "dry_value": 256,
  73. "is_public": True,
  74. },
  75. {"setting": "subscribe_reply", "dry_value": "watch_email"},
  76. {"setting": "subscribe_start", "dry_value": "watch_email"},
  77. {
  78. "setting": "thread_title_length_max",
  79. "python_type": "int",
  80. "dry_value": 90,
  81. "is_public": True,
  82. },
  83. {
  84. "setting": "thread_title_length_min",
  85. "python_type": "int",
  86. "dry_value": 5,
  87. "is_public": True,
  88. },
  89. {"setting": "username_length_min", "python_type": "int", "dry_value": 3},
  90. {"setting": "username_length_max", "python_type": "int", "dry_value": 14},
  91. {"setting": "anonymous_username", "dry_value": "Deleted"},
  92. {"setting": "enable_stop_forum_spam", "python_type": "bool", "dry_value": False},
  93. {"setting": "stop_forum_spam_confidence", "python_type": "int", "dry_value": 80},
  94. {"setting": "users_per_page", "python_type": "int", "dry_value": 12},
  95. {"setting": "users_per_page_orphans", "python_type": "int", "dry_value": 4},
  96. {"setting": "allow_data_downloads", "python_type": "bool", "dry_value": True},
  97. {"setting": "data_downloads_expiration", "python_type": "int", "dry_value": 48},
  98. {"setting": "allow_delete_own_account", "python_type": "bool", "dry_value": False},
  99. {"setting": "top_posters_ranking_length", "python_type": "int", "dry_value": 30},
  100. {"setting": "top_posters_ranking_size", "python_type": "int", "dry_value": 50},
  101. {"setting": "new_inactive_accounts_delete", "python_type": "int", "dry_value": 0},
  102. {"setting": "ip_storage_time", "python_type": "int", "dry_value": 90},
  103. ]
  104. removed_settings = ["forum_branding_display", "forum_branding_text"]
  105. def create_settings(apps, _):
  106. # This migration builds list of existing settings, and then
  107. # creates settings not already in the database
  108. Setting = apps.get_model("misago_conf", "Setting")
  109. # Update existing settings and add new ones
  110. existing_settings = list(Setting.objects.values_list("setting", flat=True))
  111. for setting in default_settings:
  112. if setting["setting"] in existing_settings:
  113. continue # skip already existing setting (migration on existing forum)
  114. data = setting.copy()
  115. if "python_type" in data and "dry_value" in data:
  116. data["dry_value"] = dehydrate_value(data["python_type"], data["dry_value"])
  117. Setting.objects.create(**setting)
  118. # Delete deprecated settings
  119. Setting.objects.filter(setting__in=removed_settings).delete()
  120. class Migration(migrations.Migration):
  121. dependencies = [
  122. ("misago_conf", "0003_simplify_models"),
  123. ("misago_core", "0003_delete_cacheversion"),
  124. ("misago_threads", "0012_set_dj_partial_indexes"),
  125. ("misago_users", "0020_set_dj_partial_indexes"),
  126. ]
  127. operations = [migrations.RunPython(create_settings)]