apps.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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><tbody><tr><td><h2>&nbsp;gemeinschaffen.com </h2></td></tr><tr><td><h3>name</h3><p>{{product_name}}</p><h3>claim</h3><p>{{product_claim}}</p><h3>beschreibung</h3><p>{{product_beschreibung}}</p><h3>learning</h3><p>{{product_learning}}</p><h3>status</h3><p>{{product_status}}</p><h3>adresse</h3><p>{{product_adresse}}</p><h3>plz</h3><p>{{product_plz}}</p><h3>adresse_zusatz</h3><p>{{product_adresse_zusatz}}</p><h3>ort</h3><p>{{product_ort}}</p><h3>website</h3><p>{{product_website}}</p><h3>email</h3><p>{{product_email}}</p></td></tr><tr><td>&nbsp;<a href="https://gemeinschaffen.com/mab/products/">gemeinschaffen.com</a></td></tr></tbody></table><p>&nbsp;</p>
  39. """
  40. content_txt = strip_tags(content_html)
  41. def create_emails(sender=None, **kwargs):
  42. from post_office.models import EmailTemplate
  43. EmailTemplate.objects.update_or_create(
  44. name='generic',
  45. defaults={
  46. 'subject' : 'Neue Nachricht von gemeinschaffen.com',
  47. 'description' : 'Generic template',
  48. 'html_content' : content_html,
  49. 'content' : content_txt}
  50. )
  51. pass
  52. class PostOfficeBase(PostOfficeConfig):
  53. def ready(self):
  54. super().ready()
  55. post_migrate.connect(create_emails, sender=self)