apps.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from django.apps import AppConfig
  2. from constance.apps import ConstanceConfig
  3. from post_office.apps import PostOfficeConfig
  4. from django.template.loader import render_to_string, get_template
  5. from django.utils.html import strip_tags
  6. class ConstanceBase(ConstanceConfig):
  7. verbose_name = "Configuration"
  8. class project_base(AppConfig):
  9. name = 'project_base'
  10. def ready(self):
  11. from django.contrib.auth.models import User
  12. print("ready")
  13. user = User.objects.update_or_create(username='admin',
  14. defaults={
  15. 'email':'admin@server.com',
  16. 'password':'admin_pass',
  17. 'is_superuser': 'True',
  18. 'is_staff': 'True' }
  19. )
  20. u = User.objects.get(username='admin')
  21. u.set_password('admin_pass')
  22. u.save()
  23. class PostOfficeBase(PostOfficeConfig):
  24. def ready(self):
  25. from post_office.models import EmailTemplate
  26. EmailTemplate.objects.update_or_create(
  27. name='generic',
  28. defaults={
  29. 'subject' : 'Neue Nachricht von gemeinschaffen.at',
  30. 'description' : 'Generic template',
  31. 'html_content' : "content html",
  32. 'content' : "content"}
  33. )
  34. super().ready()
  35. #
  36. #
  37. # def db_table_exists(table_name):
  38. # return table_name in connection.introspection.table_names()
  39. #
  40. # if db_table_exists( 'post_office_emailtemplate' ):
  41. #
  42. #
  43. # tFile = get_template('streets/email/generic.html')
  44. # with open( str(tFile.template.origin), 'r') as file:
  45. # tContentHTML = file.read()
  46. # tContent = strip_tags(tContentHTML)
  47. #
  48. # EmailTemplate.objects.update_or_create(
  49. # name='generic',
  50. # defaults={
  51. # 'subject' : _('Message from pop-up.wien'),
  52. # 'description' : 'Generic template',
  53. # 'html_content' : tContentHTML,
  54. # 'content' : tContent}
  55. # )