0004_create_settings.py 3.5 KB

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