apps.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from django.apps import AppConfig
  2. from constance.apps import ConstanceConfig
  3. from post_office.apps import PostOfficeConfig
  4. from django.db import connection
  5. from django.db.models.signals import post_migrate
  6. from django.template.loader import render_to_string, get_template
  7. from django.utils.html import strip_tags
  8. class ConstanceBase(ConstanceConfig):
  9. verbose_name = "Configuration"
  10. def create_admin(sender=None, **kwargs):
  11. from django.contrib.auth.models import User
  12. user = User.objects.update_or_create(username='admin',
  13. defaults={
  14. 'email':'admin@server.com',
  15. 'password':'admin_pass',
  16. 'is_superuser': 'True',
  17. 'is_staff': 'True' }
  18. )
  19. u = User.objects.get(username='admin')
  20. u.set_password('admin_pass')
  21. u.save()
  22. class project_base(AppConfig):
  23. name = 'project_base'
  24. def ready(self):
  25. super().ready()
  26. post_migrate.connect(create_admin, sender=self)
  27. def create_emails(sender=None, **kwargs):
  28. # Your specific logic here
  29. print("post post migrations")
  30. from post_office.models import EmailTemplate
  31. EmailTemplate.objects.update_or_create(
  32. name='generic',
  33. defaults={
  34. 'subject' : 'Neue Nachricht von gemeinschaffen.at',
  35. 'description' : 'Generic template',
  36. 'html_content' : "content html",
  37. 'content' : "content"}
  38. )
  39. pass
  40. class PostOfficeBase(PostOfficeConfig):
  41. def ready(self):
  42. # def db_table_exists(table_name):
  43. # return table_name in connection.introspection.table_names()
  44. #
  45. # if db_table_exists( 'post_office_emailtemplate' ):
  46. #
  47. # from post_office.models import EmailTemplate
  48. # EmailTemplate.objects.update_or_create(
  49. # name='generic',
  50. # defaults={
  51. # 'subject' : 'Neue Nachricht von gemeinschaffen.at',
  52. # 'description' : 'Generic template',
  53. # 'html_content' : "content html",
  54. # 'content' : "content"}
  55. # )
  56. super().ready()
  57. post_migrate.connect(create_emails, sender=self)
  58. #
  59. #
  60. # def db_table_exists(table_name):
  61. # return table_name in connection.introspection.table_names()
  62. #
  63. # if db_table_exists( 'post_office_emailtemplate' ):
  64. #
  65. #
  66. # tFile = get_template('streets/email/generic.html')
  67. # with open( str(tFile.template.origin), 'r') as file:
  68. # tContentHTML = file.read()
  69. # tContent = strip_tags(tContentHTML)
  70. #
  71. # EmailTemplate.objects.update_or_create(
  72. # name='generic',
  73. # defaults={
  74. # 'subject' : _('Message from pop-up.wien'),
  75. # 'description' : 'Generic template',
  76. # 'html_content' : tContentHTML,
  77. # 'content' : tContent}
  78. # )