0003_create_agreements_from_settings.py 2.5 KB

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