apps.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. from django.apps import AppConfig
  2. from constance.apps import ConstanceConfig
  3. from post_office.apps import PostOfficeConfig
  4. from django.contrib.auth.apps import AuthConfig
  5. from django.db import connection
  6. from django.db.models.signals import post_migrate
  7. from django.template.loader import render_to_string, get_template
  8. from django.utils.html import strip_tags
  9. class ConstanceBase(ConstanceConfig):
  10. verbose_name = "Configuration"
  11. def create_admin(sender=None, **kwargs):
  12. from django.contrib.auth.models import User
  13. from django.contrib.auth.models import Group
  14. user = User.objects.update_or_create(username='admin',
  15. defaults={
  16. 'email':'admin@server.com',
  17. 'password':'admin_pass',
  18. 'is_superuser': 'True',
  19. 'is_staff': 'True' }
  20. )
  21. u = User.objects.get(username='admin')
  22. u.set_password('admin_pass')
  23. u.save()
  24. Group.objects.update_or_create(name='submission')
  25. Group.objects.update_or_create(name='jury')
  26. class project_base(AppConfig):
  27. name = 'project_base'
  28. def ready(self):
  29. # print("base ready")
  30. super().ready()
  31. post_migrate.connect(create_admin, sender=self)
  32. class AuthConfigBase(AuthConfig):
  33. def ready(self):
  34. # print("base ready")
  35. super().ready()
  36. post_migrate.connect(create_admin, sender=self)
  37. content_html = """
  38. <table>
  39. <tbody>
  40. <tr>
  41. <td>
  42. <h2><a href="{{product.current_uri}}" target="_blank" rel="noopener"><span style="text-decoration: none;"><span style="color: #000000; text-decoration: underline;">{{product.current_uri}}</span></span></a></h2>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td>
  47. <h3>{{ product.name }}</h3>
  48. <p>Freie Plätze!</p>
  49. {% if product.beschreibung %}
  50. <h3>Beschreibung</h3>
  51. <p>{{ product.beschreibung }}</p>
  52. {% endif %} {% if product.claim %}
  53. <h3>Claim</h3>
  54. <p>{{ product.claim }}</p>
  55. {% endif %} {% if product.learning %}
  56. <h3>Learning</h3>
  57. <p>{{ product.learning }}</p>
  58. {% endif %} {% if product.status %}
  59. <h3>Status</h3>
  60. <p>{{ product.status }}</p>
  61. {% endif %} {% if product.adresse %}
  62. <h3>Adresse</h3>
  63. <p>{{product.adresse}}</p>
  64. {% endif %} {% if product.adresse_zusatz %}
  65. <p>{{ product.adresse_zusatz }}</p>
  66. {% endif %} {% if product.plz %}
  67. <h3>plz</h3>
  68. <p>{{ product.plz }}</p>
  69. {% endif %} {% if product.get_ort_display %}
  70. <h3>ort</h3>
  71. <p>{{ product.ort }}</p>
  72. {% endif %}
  73. {% if product.website %}
  74. <h3>website</h3>
  75. <p><a href="{{product.website}}" target="_blank" rel="noopener">{{product.website}}</a></p>
  76. {% endif %}
  77. {% if product.email %}
  78. <h3>email</h3>
  79. <p><a href="mailto:{{product.email}}">{{product.email}}</a></p>
  80. {% endif %}
  81. </td>
  82. </tr>
  83. <tr>
  84. <td><a href="{{ product.current_uri }}">{{ product.current_uri }}</a>
  85. <p><a href="{{ agent.delete_url }}">Agent Löschen</a>: {{ agent.delete_url }}</p>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. """
  91. content_txt = strip_tags(content_html)
  92. def create_emails(sender=None, **kwargs):
  93. from post_office.models import EmailTemplate
  94. EmailTemplate.objects.update_or_create(
  95. name='generic',
  96. defaults={
  97. 'subject' : 'Neue Nachricht von gemeinschaffen.com',
  98. 'description' : 'Generic template',
  99. 'html_content' : content_html,
  100. 'content' : content_txt}
  101. )
  102. pass
  103. class PostOfficeBase(PostOfficeConfig):
  104. def ready(self):
  105. super().ready()
  106. post_migrate.connect(create_emails, sender=self)