0003_create_agreements_from_settings.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. 'key': 'legal',
  41. 'name': _("Legal information"),
  42. 'description': _("Those settings allow you to set additional legal information for your forum."),
  43. 'settings': [
  44. {
  45. 'setting': 'forum_footnote',
  46. 'name': _("Footnote"),
  47. 'description': _("Short message displayed in forum footer."),
  48. 'legend': _("Forum footer"),
  49. 'field_extra': {
  50. 'max_length': 300,
  51. },
  52. 'is_public': True,
  53. },
  54. ],
  55. }
  56. )
  57. class Migration(migrations.Migration):
  58. dependencies = [
  59. ('misago_legal', '0002_agreement_useragreement'),
  60. ]
  61. operations = [
  62. migrations.RunPython(create_legal_settings_group),
  63. migrations.RunPython(delete_deprecated_settings),
  64. ]