Skip to content

Home Information - Your home, your data, organized.

Python

Added initial modal feature for modals in sync contexts.

Anthony Cassandra152785e4a602
diff --git a/src/hi/apps/console/views.py b/src/hi/apps/console/views.py
index 371fef7a..6b12cff8 100644
--- a/src/hi/apps/console/views.py
+++ b/src/hi/apps/console/views.py
@@ -22,7 +22,7 @@ class ConsoleUnlockView( ConsoleLockView ):
def get( self, request, *args, **kwargs ):
context = {
}
- return self.modal_response( request, context )
+ return self.modal_response( request, context )
def post(self, request, *args, **kwargs):
diff --git a/src/hi/hi_async_view.py b/src/hi/hi_async_view.py
index b850ae58..92bbec5c 100644
--- a/src/hi/hi_async_view.py
+++ b/src/hi/hi_async_view.py
@@ -2,10 +2,13 @@ import logging
from typing import Dict
import urllib.parse
+from django.shortcuts import render
from django.template.loader import get_template
+from django.utils.safestring import mark_safe
from django.views.generic import View
import hi.apps.common.antinode as antinode
+from hi.apps.common.utils import is_ajax
from hi.constants import DIVID
@@ -101,16 +104,26 @@ class HiSideView( HiAsyncView ):
class HiModalView( View ):
+ DEFAULT_PAGE_TEMPLATE_NAME = 'pages/main_default.html'
+
def get_template_name( self ) -> str:
raise NotImplementedError('Subclasses must override this method.')
- def modal_response( self, request, context ):
- template_name = self.get_template_name()
- return antinode.modal_from_template(
+ def modal_response( self, request, context, status = 200 ):
+ modal_response = antinode.modal_from_template(
request = request,
- template_name = template_name,
+ template_name = self.get_template_name(),
context = context,
)
+ if is_ajax( request ):
+ return modal_response
+
+ context['initial_modal_template_name'] = self.get_template_name()
+ template_name = self.DEFAULT_PAGE_TEMPLATE_NAME
+ return render( request,
+ template_name,
+ context,
+ status = status )
def redirect_response( self, request, redirect_url ):
return antinode.redirect_response( redirect_url )
diff --git a/src/hi/simulator/management/commands/runsim.py b/src/hi/simulator/management/commands/runsim.py
index 61c1705b..bc5ecb21 100644
--- a/src/hi/simulator/management/commands/runsim.py
+++ b/src/hi/simulator/management/commands/runsim.py
@@ -5,7 +5,7 @@ from django.core.management.commands.runserver import Command as RunserverComman
class Command(RunserverCommand):
- help = "Runs the simulator server (separate port)."
+ help = "Runs the simulator server (separate port, custom settings)."
def add_arguments(self, parser):
super().add_arguments( parser )
diff --git a/src/hi/templates/pages/base.html b/src/hi/templates/pages/base.html
index e89dce9c..67f01b18 100644
--- a/src/hi/templates/pages/base.html
+++ b/src/hi/templates/pages/base.html
@@ -38,6 +38,12 @@
{% block footer_pre_javascript %}{% endblock %}
{% javascript 'js_after_content' %}
{% block footer_post_javascript %}{% endblock %}
+
+ {% if initial_modal_template_name %}
+ <div id="antinode-initial-modal">
+ {% include initial_modal_template_name %}
+ </div>
+ {% endif %}
</body>
</html>
diff --git a/src/hi/templates/pages/main_default.html b/src/hi/templates/pages/main_default.html
index 4521ba10..4491868b 100644
--- a/src/hi/templates/pages/main_default.html
+++ b/src/hi/templates/pages/main_default.html
@@ -1 +1,8 @@
-<h5>Home Information</h5>
+{% extends "pages/base.html" %}
+{% load pipeline %}
+
+{% block content %}
+<h1>Home Information</h1>
+
+
+{% endblock %}