0003_create_agreements_from_settings.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Generated by Django 1.11.15 on 2018-08-16 14:22
  2. from django.db import migrations
  3. from misago.conf.migrationutils import migrate_settings_group
  4. from misago.legal.models import Agreement as MisagoAgreement
  5. _ = lambda s: s
  6. LEGAL_SETTINGS = [
  7. "terms_of_service_title",
  8. "terms_of_service_link",
  9. "terms_of_service",
  10. "privacy_policy_title",
  11. "privacy_policy_link",
  12. "privacy_policy",
  13. ]
  14. def create_legal_settings_group(apps, schema_editor):
  15. Agreement = apps.get_model("misago_legal", "Agreement")
  16. Setting = apps.get_model("misago_conf", "Setting")
  17. legal_conf = {}
  18. for setting in Setting.objects.filter(setting__in=LEGAL_SETTINGS):
  19. legal_conf[setting.setting] = setting.dry_value
  20. if legal_conf["terms_of_service"] or legal_conf["terms_of_service_link"]:
  21. Agreement.objects.create(
  22. type=MisagoAgreement.TYPE_TOS,
  23. title=legal_conf["terms_of_service_title"],
  24. link=legal_conf["terms_of_service_link"],
  25. text=legal_conf["terms_of_service"],
  26. is_active=True,
  27. )
  28. if legal_conf["privacy_policy"] or legal_conf["privacy_policy_link"]:
  29. Agreement.objects.create(
  30. type=MisagoAgreement.TYPE_PRIVACY,
  31. title=legal_conf["privacy_policy_title"],
  32. link=legal_conf["privacy_policy_link"],
  33. text=legal_conf["privacy_policy"],
  34. is_active=True,
  35. )
  36. MisagoAgreement.objects.invalidate_cache()
  37. def delete_deprecated_settings(apps, schema_editor):
  38. migrate_settings_group(
  39. apps,
  40. {
  41. "key": "legal",
  42. "name": _("Legal information"),
  43. "description": _(
  44. "Those settings allow you to set additional legal information for your forum."
  45. ),
  46. "settings": [
  47. {
  48. "setting": "forum_footnote",
  49. "name": _("Footnote"),
  50. "description": _("Short message displayed in forum footer."),
  51. "legend": _("Forum footer"),
  52. "field_extra": {"max_length": 300},
  53. "is_public": True,
  54. }
  55. ],
  56. },
  57. )
  58. class Migration(migrations.Migration):
  59. dependencies = [("misago_legal", "0002_agreement_useragreement")]
  60. operations = [
  61. migrations.RunPython(create_legal_settings_group),
  62. migrations.RunPython(delete_deprecated_settings),
  63. ]