apps.py 2.8 KB

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