Coverage for gui/email.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2023-03-14 06:24 +0000

1from django.conf import settings 

2from django.core.mail import send_mail 

3from django.contrib.auth import get_user_model 

4from django.contrib.sites.models import Site 

5 

6 

7class Email: 

8 def __init__(self, subject, message, to): 

9 self.subject = subject.strip() 

10 self.message = message 

11 self.to = to 

12 

13 def send(self): 

14 subject = "{} {}".format('[X.Org membership]', self.subject) 

15 

16 from_email = settings.DEFAULT_FROM_EMAIL 

17 if from_email is None: 

18 from_email = "{}@{}".format(settings.EMAIL_HOST_USER, settings.EMAIL_HOST) 

19 

20 send_mail(subject, self.message, from_email, self.to) 

21 

22 

23class AdminEmail(Email): 

24 def __init__(self, subject, message): 

25 to = [u.email for u in get_user_model().objects.filter(is_superuser=True)] 

26 super().__init__(subject, message, to) 

27 

28 

29def email_context(**kwargs): 

30 kwargs['current_site'] = Site.objects.get_current() 

31 return kwargs