PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/common/djangoapps/django_comment_common/migrations/0003_enable_forums.py

https://gitlab.com/unofficial-mirrors/edx-platform
Python | 30 lines | 17 code | 9 blank | 4 comment | 1 complexity | c6a895faaf87f32c59b7676637661d91 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.db import migrations, models
  4. def add_default_enable(apps, schema_editor):
  5. ForumsConfig = apps.get_model("django_comment_common", "ForumsConfig")
  6. settings_count = ForumsConfig.objects.count()
  7. if settings_count is 0:
  8. # By default we want the comment client enabled, but this is *not* enabling
  9. # discussions themselves by default, as in showing the Disucussions tab, or
  10. # inline discussions, etc. It just allows the underlying service client to work.
  11. settings = ForumsConfig(enabled=True)
  12. settings.save()
  13. def reverse_noop(apps, schema_editor):
  14. return
  15. class Migration(migrations.Migration):
  16. dependencies = [
  17. ('django_comment_common', '0002_forumsconfig'),
  18. ]
  19. operations = [
  20. migrations.RunPython(add_default_enable, reverse_code=reverse_noop),
  21. ]