0004_create_settings.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. {"setting": "forum_footnote", "is_public": True},
  18. {"setting": "forum_index_meta_description"},
  19. {"setting": "forum_index_title", "is_public": True},
  20. {"setting": "forum_name", "dry_value": "Misago", "is_public": True},
  21. {"setting": "logo", "python_type": "image", "is_public": True},
  22. {"setting": "logo_small", "python_type": "image", "is_public": True},
  23. {"setting": "logo_text", "dry_value": "Misago", "is_public": True},
  24. {
  25. "setting": "post_length_max",
  26. "python_type": "int",
  27. "dry_value": 60000,
  28. "is_public": True,
  29. },
  30. {
  31. "setting": "post_length_min",
  32. "python_type": "int",
  33. "dry_value": 5,
  34. "is_public": True,
  35. },
  36. {"setting": "qa_answers"},
  37. {"setting": "qa_help_text"},
  38. {"setting": "qa_question"},
  39. {"setting": "recaptcha_secret_key"},
  40. {"setting": "recaptcha_site_key", "is_public": True},
  41. {
  42. "setting": "signature_length_max",
  43. "python_type": "int",
  44. "dry_value": 256,
  45. "is_public": True,
  46. },
  47. {"setting": "subscribe_reply", "dry_value": "watch_email"},
  48. {"setting": "subscribe_start", "dry_value": "watch_email"},
  49. {
  50. "setting": "thread_title_length_max",
  51. "python_type": "int",
  52. "dry_value": 90,
  53. "is_public": True,
  54. },
  55. {
  56. "setting": "thread_title_length_min",
  57. "python_type": "int",
  58. "dry_value": 5,
  59. "is_public": True,
  60. },
  61. {"setting": "username_length_min", "python_type": "int", "dry_value": 3},
  62. {"setting": "username_length_max", "python_type": "int", "dry_value": 14},
  63. ]
  64. removed_settings = ["forum_branding_display", "forum_branding_text"]
  65. def create_settings(apps, _):
  66. # This migration builds list of existing settings, and then
  67. # creates settings not already in the database
  68. Setting = apps.get_model("misago_conf", "Setting")
  69. # Update existing settings and add new ones
  70. existing_settings = list(Setting.objects.values_list("setting", flat=True))
  71. for setting in default_settings:
  72. if setting["setting"] in existing_settings:
  73. continue # skip already existing setting (migration on existing forum)
  74. data = setting.copy()
  75. if "python_type" in data and "dry_value" in data:
  76. data["dry_value"] = dehydrate_value(data["python_type"], data["dry_value"])
  77. Setting.objects.create(**setting)
  78. # Delete deprecated settings
  79. Setting.objects.filter(setting__in=removed_settings).delete()
  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)]