0003_create_agreements_from_settings.py 2.5 KB

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