diff --git a/TODO b/TODO index 349542c..5d8ef6a 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ * remove dot before "Nextcloud" at login page. -* better error handling with mail sending. - * test for complete run with all forms diff --git a/evapp/tests.py b/evapp/tests.py index f897265..d827ed3 100644 --- a/evapp/tests.py +++ b/evapp/tests.py @@ -1,6 +1,7 @@ from django.test import TestCase from django.test import Client from django.contrib.auth.models import User +from django.conf import settings from .forms import ITForm @@ -16,6 +17,7 @@ class LoginTestCase(TestCase): def testDebugWarning(self): with self.settings(DEBUG=True): + self.response = self.client.get('/') self.assertContains(self.response, "WARNUNG! Test-MODUS aktiviert. Es werden keine Mails verschickt!", status_code=200) diff --git a/evapp/views.py b/evapp/views.py index 6c8b902..615e831 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -83,10 +83,10 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView): #print('GETCONTEXT') context = super().get_context_data(form=form, **kwargs) - #testmode = settings.DEBUG or settings.MAILTEST + testmode = settings.DEBUG or settings.MAILTEST context.update({'choice': self.choice, 'choice_string': TYPE_CHOICES[self.choice], - 'TESTMODE': settings.DEBUG or settings.MAILTEST}) + 'TESTMODE': testmode}) # deliver context for forms if we are in the last step if (self.steps.step1 == 5 or (self.choice != 'IN' and self.steps.step1 == 3)): @@ -95,7 +95,7 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView): return context def get_form_instance(self,step): - ''' this method makes shure, that we use the same model instance for all steps''' + ''' this method assures, that we use the same model instance for all steps''' if self.instance == None: self.instance = Employee() @@ -114,12 +114,15 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView): # send data to departments for dep in MAILS: - self.send_mail_to_department(dep) + response = self.send_mail_to_department(dep) if not settings.DEBUG: self.instance.delete() - return HttpResponseRedirect('success') + if response: + return response + else: + return HttpResponseRedirect('success') def send_mail_to_department(self, department): @@ -152,12 +155,19 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView): EVA_MAIL, [MAILS[department]['MAIL'], contact], fail_silently=False) - except BadHeaderError: + except BadHeaderError as error: + print(error) self.instance.delete() - return HttpResponse('Invalid header found. Data not saved!') - except SMTPException: + return HttpResponse(f'{error}
Invalid header found. Data not saved!') + except SMTPException as error: + print(error) self.instance.delete() - return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!') + return HttpResponse(f'{error}
Error in sending mails (propably wrong adress?). Data not saved!') + except Exception as error: + print(error) + # self.instance.delete() + return HttpResponse(f'{error}
Error in sending mails. Data not saved! Please contact ' + EVA_MAIL) + return False def beautify_data(self, data): ''' # use long form for contextdata instead of short form if available