Skip to content

Home Information - Your home, your data, organized.

Python

Added more help with messaging around email configuration status.

Anthony Cassandra245e5c27bb58
diff --git a/src/hi/apps/notify/email_sender.py b/src/hi/apps/notify/email_sender.py
index 7621fcef..e56bfb34 100644
--- a/src/hi/apps/notify/email_sender.py
+++ b/src/hi/apps/notify/email_sender.py
@@ -79,7 +79,7 @@ class EmailSender:
return
def _send_helper(self):
- self._ensure_email_configured()
+ self._assert_email_configured()
context = self._data.template_context
self._add_base_url( context = context )
@@ -142,7 +142,23 @@ class EmailSender:
raise UnsubscribedEmailError( f'Email address is unsubscribed for {email_address}' )
return
- def _ensure_email_configured( self ):
+ def _assert_email_configured( self ):
+ missing_names = self.get_missing_email_setting_names()
+ if missing_names:
+ raise ImproperlyConfigured( 'Email is not configured. Missing: %s.'
+ % ', '.join( missing_names ))
+ return
+
+ @classmethod
+ def is_email_configured( cls ) -> bool:
+ missing_names = cls.get_missing_email_setting_names()
+ if missing_names:
+ return False
+ return True
+
+ @classmethod
+ def get_missing_email_setting_names( cls ) -> List[ str ]:
+ missing_names = list()
for setting_name in [ 'EMAIL_BACKEND',
'EMAIL_HOST',
'EMAIL_PORT',
@@ -151,6 +167,6 @@ class EmailSender:
'SERVER_EMAIL' ]:
email_setting = getattr( settings, setting_name )
if not email_setting:
- raise ImproperlyConfigured( f'Email is not configured. Missing "{setting_name}".' )
+ missing_names.append( setting_name )
continue
- return
+ return missing_names
diff --git a/src/hi/apps/user/templates/user/pages/signin.html b/src/hi/apps/user/templates/user/pages/signin.html
index 459ca51a..1debf3e7 100644
--- a/src/hi/apps/user/templates/user/pages/signin.html
+++ b/src/hi/apps/user/templates/user/pages/signin.html
@@ -2,6 +2,17 @@
{% block interstitial_content %}
<div>
+ {% if email_not_configured %}
+ <div class="alert alert-danger">
+ <div class="h4" >Email Not Configured</div>
+ <p>
+ The email settings are is not properly configured. The Sign In feature requires emails to work.
+ </p>
+ <p class="font-weight-bold">
+ You will not be able to sign in unless you disable the Sign In feature or properly configure the email settings.
+ </p>
+ </div>
+ {% endif %}
<form class="sigin form" method="post"
action="{% url 'user_signin' %}"
data-synchronous="true">
diff --git a/src/hi/apps/user/views.py b/src/hi/apps/user/views.py
index 464e79db..70217c27 100644
--- a/src/hi/apps/user/views.py
+++ b/src/hi/apps/user/views.py
@@ -10,6 +10,8 @@ from django.shortcuts import render
from django.urls import reverse
from django.views.generic import View
+from hi.apps.notify.email_sender import EmailSender
+
from . import forms
from .magic_code_generator import MagicCodeStatus, MagicCodeGenerator
from .signin_manager import SigninManager
@@ -21,7 +23,10 @@ logger = logging.getLogger(__name__)
class UserSigninView( View ):
def get(self, request, *args, **kwargs):
- return render( request, 'user/pages/signin.html' )
+ context = {
+ 'email_not_configured': not EmailSender.is_email_configured(),
+ }
+ return render( request, 'user/pages/signin.html', context )
def post(self, request, *args, **kwargs):
if request.user.is_authenticated:
diff --git a/src/hi/hi_grid_view.py b/src/hi/hi_grid_view.py
index e25a734b..0e1e787a 100644
--- a/src/hi/hi_grid_view.py
+++ b/src/hi/hi_grid_view.py
@@ -47,6 +47,7 @@ class HiGridView(View):
TOP_TEMPLATE_NAME = 'panes/top_buttons.html'
BOTTOM_TEMPLATE_NAME = 'panes/bottom_buttons.html'
SIDE_FALLBACK_TEMPLATE_NAME = 'panes/side_fallback.html'
+ TOP_FALLBACK_TEMPLATE_NAME = 'panes/top_fallback.html'
def get_main_template_name( self ) -> str:
raise NotImplementedError('Subclasses must override this method.')
@@ -60,9 +61,10 @@ class HiGridView(View):
raise NotImplementedError('Subclasses must override this method.')
def get_top_template_name_and_context( self, request, *args, **kwargs ):
- """ Subclasses can override this i sneeded. """
+ """ Subclasses can override this if sneeded. """
if not request.view_parameters.location:
- return dict()
+ return ( self.TOP_FALLBACK_TEMPLATE_NAME, dict() )
+
location_list = list( Location.objects.all() )
location_view_list = list( request.view_parameters.location.views.order_by( 'order_id' ))
context = {
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index 30c52f18..a06cad9d 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -355,7 +355,11 @@ FROM_EMAIL_NAME = "Home Information"
# Normal Settings
EMAIL_HOST = get_env_variable('HI_EMAIL_HOST')
-EMAIL_PORT = int(get_env_variable('HI_EMAIL_PORT'))
+try:
+ EMAIL_PORT = int(get_env_variable('HI_EMAIL_PORT'))
+except (TypeError, ValueError):
+ EMAIL_PORT = 587
+
EMAIL_HOST_USER = get_env_variable('HI_EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = get_env_variable('HI_EMAIL_HOST_PASSWORD')
EMAIL_TIMEOUT = 10 # In seconds
diff --git a/src/hi/templates/panes/top_fallback.html b/src/hi/templates/panes/top_fallback.html
new file mode 100644
index 00000000..ce13177a
--- /dev/null
+++ b/src/hi/templates/panes/top_fallback.html
@@ -0,0 +1,11 @@
+<div class="d-flex justify-content-between p-1" >
+ <div class=""><em>No locations defined.</em></div>
+ <div>
+ <a href="{% url 'start' %}" title="Start Page"
+ class="btn btn-primary btn-control">
+ START
+ </a>
+ </div>
+</div>
+
+
diff --git a/src/hi/views.py b/src/hi/views.py
index 20219510..2b95c3bb 100644
--- a/src/hi/views.py
+++ b/src/hi/views.py
@@ -177,7 +177,6 @@ class StartView( View ):
# First actions need edit ability.
request.view_parameters.view_mode = ViewMode.EDIT
request.view_parameters.to_session( request )
-
- context = {
+ context = {
}
return render( request, 'pages/start.html', context )