apps.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. if ( User.objects.filter(username='admin').exists() ):
  15. pass
  16. else:
  17. user = User.objects.create_superuser('admin', email='admin@server.com', password='admin_pass')
  18. user.save()
  19. Group.objects.update_or_create(name='submission')
  20. Group.objects.update_or_create(name='jury')
  21. class project_base(AppConfig):
  22. name = 'project_base'
  23. def ready(self):
  24. # print("base ready")
  25. super().ready()
  26. post_migrate.connect(create_admin, sender=self)
  27. class AuthConfigBase(AuthConfig):
  28. def ready(self):
  29. # print("base ready")
  30. super().ready()
  31. post_migrate.connect(create_admin, sender=self)
  32. content_html = """
  33. <table>
  34. <tbody>
  35. <tr>
  36. <td>
  37. <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>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td>
  42. <h3>{{ product.name }}</h3>
  43. <p>Freie Plätze!</p>
  44. {% if product.beschreibung %}
  45. <h3>Beschreibung</h3>
  46. <p>{{ product.beschreibung }}</p>
  47. {% endif %} {% if product.claim %}
  48. <h3>Claim</h3>
  49. <p>{{ product.claim }}</p>
  50. {% endif %} {% if product.learning %}
  51. <h3>Learning</h3>
  52. <p>{{ product.learning }}</p>
  53. {% endif %} {% if product.status %}
  54. <h3>Status</h3>
  55. <p>{{ product.status }}</p>
  56. {% endif %} {% if product.adresse %}
  57. <h3>Adresse</h3>
  58. <p>{{product.adresse}}</p>
  59. {% endif %} {% if product.adresse_zusatz %}
  60. <p>{{ product.adresse_zusatz }}</p>
  61. {% endif %} {% if product.plz %}
  62. <h3>plz</h3>
  63. <p>{{ product.plz }}</p>
  64. {% endif %} {% if product.get_ort_display %}
  65. <h3>ort</h3>
  66. <p>{{ product.ort }}</p>
  67. {% endif %}
  68. {% if product.website %}
  69. <h3>website</h3>
  70. <p><a href="{{product.website}}" target="_blank" rel="noopener">{{product.website}}</a></p>
  71. {% endif %}
  72. {% if product.email %}
  73. <h3>email</h3>
  74. <p><a href="mailto:{{product.email}}">{{product.email}}</a></p>
  75. {% endif %}
  76. </td>
  77. </tr>
  78. <tr>
  79. <td><a href="{{ product.current_uri }}">{{ product.current_uri }}</a>
  80. <p><a href="{{ agent.delete_url }}">Agent Löschen</a>: {{ agent.delete_url }}</p>
  81. </td>
  82. </tr>
  83. </tbody>
  84. </table>
  85. """
  86. content_txt = strip_tags(content_html)
  87. def create_emails(sender=None, **kwargs):
  88. from post_office.models import EmailTemplate
  89. EmailTemplate.objects.update_or_create(
  90. name='generic',
  91. defaults={
  92. 'subject' : 'Neue Nachricht von gemeinschaffen.com',
  93. 'description' : 'Generic template',
  94. 'html_content' : content_html,
  95. 'content' : content_txt}
  96. )
  97. pass
  98. class PostOfficeBase(PostOfficeConfig):
  99. def ready(self):
  100. super().ready()
  101. post_migrate.connect(create_emails, sender=self)