Home Information - Your home, your data, organized.
Python
Added beginning of location views.
Anthony Cassandra3061431e05b8
diff --git a/src/hi/apps/common/templatetags/common_template_helpers.py b/src/hi/apps/common/templatetags/common_template_helpers.pyindex 79f0489b..53e4dd09 100644--- a/src/hi/apps/common/templatetags/common_template_helpers.py+++ b/src/hi/apps/common/templatetags/common_template_helpers.py@@ -1,7 +1,9 @@+import osimport urllibfrom django import templatefrom django.conf import settings+from django.template import enginesfrom django.urls import reverseregister = template.Library()@@ -59,3 +61,24 @@ def digit_count( value ):@register.simple_tagdef settings_value(name):return getattr(settings, name, "")++[email protected]_tag( takes_context = True )+def include_media_template( context, file_path ):+ """+ Load a file from MEDIA_ROOT, treat it as a Django template,+ and render it with the current context.+ """+ full_path = os.path.join( settings.MEDIA_ROOT, file_path )++ if not os.path.exists(full_path):+ return f'Template file not found: {full_path}'++ with open(full_path, 'r') as file:+ file_content = file.read()++ template_engine = engines['django']+ template_obj = template_engine.from_string(file_content)++ context_dict = context.flatten()+ return template_obj.render(context_dict)diff --git a/src/hi/apps/location/__init__.py b/src/hi/apps/location/__init__.pynew file mode 100644index 00000000..e69de29bdiff --git a/src/hi/apps/location/admin.py b/src/hi/apps/location/admin.pynew file mode 100644index 00000000..8705fda1--- /dev/null+++ b/src/hi/apps/location/admin.py@@ -0,0 +1,50 @@+from django.contrib import admin++from . import models+++class LocationViewInLine(admin.TabularInline):+ model = models.LocationView+ extra = 0+ show_change_link = True++[email protected](models.Location)+class LocationAdmin(admin.ModelAdmin):+ show_full_result_count = False++ list_display = (+ 'name',+ 'svg_filename',+ 'svg_viewbox',+ 'latitude',+ 'longitude',+ 'elevation_feet',+ 'order_id',+ 'created_datetime',+ 'updated_datetime',+ )++ search_fields = ['name']+ ordering = ( 'order_id', )++ inlines = [ LocationViewInLine, ]++[email protected](models.LocationView)+class LocationViewAdmin(admin.ModelAdmin):+ show_full_result_count = False++ list_display = (+ 'name',+ 'location',+ 'svg_viewbox',+ 'svg_rotation',+ 'order_id',+ 'created_datetime',+ 'updated_datetime',+ )+ list_select_related = ( 'location', )++ search_fields = ['name']+ ordering = ( 'order_id', )diff --git a/src/hi/apps/location/apps.py b/src/hi/apps/location/apps.pynew file mode 100644index 00000000..db3714bc--- /dev/null+++ b/src/hi/apps/location/apps.py@@ -0,0 +1,6 @@+from django.apps import AppConfig+++class LocationConfig(AppConfig):+ default_auto_field = "django.db.models.BigAutoField"+ name = "hi.apps.location"diff --git a/src/hi/apps/location/migrations/0001_initial.py b/src/hi/apps/location/migrations/0001_initial.pynew file mode 100644index 00000000..eedb97a0--- /dev/null+++ b/src/hi/apps/location/migrations/0001_initial.py@@ -0,0 +1,115 @@+# Generated by Django 4.2.15 on 2024-08-14 19:15++from django.db import migrations, models+import django.db.models.deletion+++class Migration(migrations.Migration):++ initial = True++ dependencies = []++ operations = [+ migrations.CreateModel(+ name="Location",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True,+ primary_key=True,+ serialize=False,+ verbose_name="ID",+ ),+ ),+ ("name", models.CharField(max_length=64, verbose_name="Name")),+ (+ "svg_filename",+ models.CharField(max_length=256, verbose_name="SVG File"),+ ),+ (+ "svg_viewbox",+ models.CharField(max_length=64, verbose_name="Viewbox"),+ ),+ (+ "latitude",+ models.DecimalField(+ decimal_places=6, max_digits=9, verbose_name="Latitude"+ ),+ ),+ (+ "longitude",+ models.DecimalField(+ decimal_places=6, max_digits=9, verbose_name="Longitude"+ ),+ ),+ (+ "elevation_feet",+ models.DecimalField(+ decimal_places=3, max_digits=9, verbose_name="Elevation (ft)"+ ),+ ),+ ("order_id", models.IntegerField(default=0, verbose_name="Order Id")),+ (+ "created_datetime",+ models.DateTimeField(auto_now_add=True, verbose_name="Created"),+ ),+ (+ "updated_datetime",+ models.DateTimeField(auto_now=True, verbose_name="Updated"),+ ),+ ],+ options={+ "verbose_name": "Location",+ "verbose_name_plural": "Locations",+ },+ ),+ migrations.CreateModel(+ name="LocationView",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True,+ primary_key=True,+ serialize=False,+ verbose_name="ID",+ ),+ ),+ ("name", models.CharField(max_length=64, verbose_name="Name")),+ (+ "svg_viewbox",+ models.CharField(max_length=64, verbose_name="Viewbox"),+ ),+ (+ "svg_rotation",+ models.DecimalField(+ decimal_places=6, max_digits=9, verbose_name="Rotation"+ ),+ ),+ ("order_id", models.IntegerField(default=0, verbose_name="Order Id")),+ (+ "created_datetime",+ models.DateTimeField(auto_now_add=True, verbose_name="Created"),+ ),+ (+ "updated_datetime",+ models.DateTimeField(auto_now=True, verbose_name="Updated"),+ ),+ (+ "location",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="views",+ to="location.location",+ verbose_name="View",+ ),+ ),+ ],+ options={+ "verbose_name": "View",+ "verbose_name_plural": "Views",+ },+ ),+ ]diff --git a/src/hi/apps/location/migrations/0002_alter_location_latitude_alter_location_longitude.py b/src/hi/apps/location/migrations/0002_alter_location_latitude_alter_location_longitude.pynew file mode 100644index 00000000..8ce15868--- /dev/null+++ b/src/hi/apps/location/migrations/0002_alter_location_latitude_alter_location_longitude.py@@ -0,0 +1,27 @@+# Generated by Django 4.2.15 on 2024-08-14 19:20++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ("location", "0001_initial"),+ ]++ operations = [+ migrations.AlterField(+ model_name="location",+ name="latitude",+ field=models.DecimalField(+ decimal_places=8, max_digits=11, verbose_name="Latitude"+ ),+ ),+ migrations.AlterField(+ model_name="location",+ name="longitude",+ field=models.DecimalField(+ decimal_places=8, max_digits=11, verbose_name="Longitude"+ ),+ ),+ ]diff --git a/src/hi/apps/location/migrations/__init__.py b/src/hi/apps/location/migrations/__init__.pynew file mode 100644index 00000000..e69de29bdiff --git a/src/hi/apps/location/models.py b/src/hi/apps/location/models.pynew file mode 100644index 00000000..3e0fd784--- /dev/null+++ b/src/hi/apps/location/models.py@@ -0,0 +1,110 @@+from django.db import models+++class Location(models.Model):++ name = models.CharField(+ 'Name',+ max_length = 64,+ null = False, blank = False,+ )+ svg_filename = models.CharField(+ 'SVG File',+ max_length = 256,+ null = False, blank = False,+ )+ svg_viewbox = models.CharField(+ 'Viewbox',+ max_length = 64,+ null = False, blank = False,+ )++ latitude = models.DecimalField(+ 'Latitude',+ max_digits = 11,+ decimal_places = 8,+ )+ longitude = models.DecimalField(+ 'Longitude',+ max_digits = 11,+ decimal_places = 8,+ )+ elevation_feet = models.DecimalField(+ 'Elevation (ft)',+ max_digits = 9,+ decimal_places = 3,+ )+ order_id = models.IntegerField(+ 'Order Id',+ default = 0,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )+ updated_datetime = models.DateTimeField(+ 'Updated',+ auto_now=True,+ blank = True,+ )++ class Meta:+ verbose_name = 'Location'+ verbose_name_plural = 'Locations'++ def __str__(self):+ return f'{self.name} ({self.id})'++ def __repr__(self):+ return self.__str__()+++class LocationView(models.Model):++ location = models.ForeignKey(+ Location,+ related_name = 'views',+ verbose_name = 'View',+ on_delete = models.CASCADE,+ null = False, blank = False,+ )+ name = models.CharField(+ 'Name',+ max_length = 64,+ null = False, blank = False,+ )+ svg_viewbox = models.CharField(+ 'Viewbox',+ max_length = 64,+ null = False, blank = False,+ )++ svg_rotation = models.DecimalField(+ 'Rotation',+ max_digits = 9,+ decimal_places = 6,+ )+ order_id = models.IntegerField(+ 'Order Id',+ default = 0,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )+ updated_datetime = models.DateTimeField(+ 'Updated',+ auto_now=True,+ blank = True,+ )++ class Meta:+ verbose_name = 'View'+ verbose_name_plural = 'Views'++ def __str__(self):+ return f'{self.name} ({self.id})'++ def __repr__(self):+ return self.__str__()+diff --git a/src/hi/apps/location/templates/location/location_view.html b/src/hi/apps/location/templates/location/location_view.htmlnew file mode 100644index 00000000..53fad3d5--- /dev/null+++ b/src/hi/apps/location/templates/location/location_view.html@@ -0,0 +1,8 @@+{% load common_template_helpers %}+<div class="hi-location-view">+ {% with current_location_view.svg_viewbox as svg_viewbox %}+ {% with current_location_view.svg_rotation as svg_rotation %}+ {% include_media_template current_location_view.location.svg_filename %}+ {% endwith %}+ {% endwith %}+</div>diff --git a/src/hi/apps/location/templates/location/location_view_buttons.html b/src/hi/apps/location/templates/location/location_view_buttons.htmlnew file mode 100644index 00000000..21d9a600--- /dev/null+++ b/src/hi/apps/location/templates/location/location_view_buttons.html@@ -0,0 +1,9 @@+{% for location_view in location_view_list %}+<div class="col-1">+ <a href="{% url 'location_view' id=location_view.id %}"+ class="btn btn-primary btn-control" role="button"+ data-async="#hi-main-content" >+ {{ location_view.name }}+ </a>+</div>+{% endfor %}diff --git a/src/hi/apps/location/urls.py b/src/hi/apps/location/urls.pynew file mode 100644index 00000000..d2c0b759--- /dev/null+++ b/src/hi/apps/location/urls.py@@ -0,0 +1,12 @@+from django.urls import re_path++from . import views+++urlpatterns = [++ re_path( r'^view/(?P<id>\d+)$',+ views.LocationViewView.as_view(),+ name='location_view'),++]diff --git a/src/hi/apps/location/views.py b/src/hi/apps/location/views.pynew file mode 100644index 00000000..9212fa96--- /dev/null+++ b/src/hi/apps/location/views.py@@ -0,0 +1,16 @@+from django.shortcuts import render+from django.views.generic import View++from .models import LocationView+++class LocationViewView( View ):++ def get(self, request, *args, **kwargs):++ location_view_id = kwargs.get('id')+ current_location_view = LocationView.objects.select_related( 'location' ).get( id = location_view_id )+ context = {+ 'current_location_view': current_location_view,+ }+ return render( request, 'location/location_view.html', context )diff --git a/src/hi/settings/base.py b/src/hi/settings/base.pyindex 6fb7a885..ec0bb063 100644--- a/src/hi/settings/base.py+++ b/src/hi/settings/base.py@@ -136,6 +136,7 @@ INSTALLED_APPS = ['django.contrib.humanize','constance','hi.apps.common',+ 'hi.apps.location',]MIDDLEWARE = [@@ -228,6 +229,9 @@ STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)+MEDIA_ROOT = get_env_variable('HI_MEDIA_PATH')+MEDIA_URL = '/media/'+PIPELINE = {'DISABLE_WRAPPER': True, # Important since some scripts assume global scope@@ -279,3 +283,4 @@ CONSTANCE_DATABASE_PREFIX = 'constance:hi:'CONSTANCE_CONFIG = {'DOWN_FOR_MAINTENANCE': ( False, 'Should we force the down for maintenance page to show?' ),}+diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.cssindex e9eb7353..1cb5d6eb 100644--- a/src/hi/static/css/main.css+++ b/src/hi/static/css/main.css@@ -24,6 +24,9 @@--muted-color: #7e7e81;--on-muted-color: #ffffff;--line-color: #cccccc;++ --top-buttons-height: 2.5rem;+ --bottom-buttons-height: 2.5rem;}html, body {@@ -125,23 +128,30 @@ a.underline:visited {background-color: var(--muted-color) !important;}-+.hi-top-buttons {+ height: var(--top-buttons-height);+ border-bottom: 1px solid var(--line-color);+}+.hi-bottom-buttons {+ height: var(--bottom-buttons-height);+ border-top: 1px solid var(--line-color);+}.hi-screen {max-height: 100vh;}.scrollable-column {overflow-y: auto;max-height: 100vh;- padding-top: 2.5rem;- padding-bottom: 2.5rem;+ padding-top: var(--top-buttons-height);+ padding-bottom: var(--bottom-buttons-height);}.fixed-column {overflow-y: auto;flex-shrink: 0;height: 100vh;max-height: 100vh;- padding-top: 2.5rem;- padding-bottom: 2.5rem;+ padding-top: var(--top-buttons-height);+ padding-bottom: var(--bottom-buttons-height);border-left: 1px solid var(--line-color);}@@ -151,3 +161,16 @@ a.underline:visited {font-size: 0.75rem;font-weight: bold;}++.hi-location-view {+ display: flex;+ justify-content: center;+ align-items: center;+ height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );+}+.hi-location-view svg {+ max-height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );+ width: auto;+ height: auto;+ display: block;+}diff --git a/src/hi/static/img/antinode-loading.gif b/src/hi/static/img/antinode-loading.gifnew file mode 100644index 00000000..4106259dBinary files /dev/null and b/src/hi/static/img/antinode-loading.gif differdiff --git a/src/hi/static/img/hi-icon-16x16.png b/src/hi/static/img/hi-icon-16x16.pngnew file mode 100644index 00000000..345afb4fBinary files /dev/null and b/src/hi/static/img/hi-icon-16x16.png differdiff --git a/src/hi/static/img/hi-icon-196x196.png b/src/hi/static/img/hi-icon-196x196.pngnew file mode 100644index 00000000..98610977Binary files /dev/null and b/src/hi/static/img/hi-icon-196x196.png differdiff --git a/src/hi/templates/pages/home.html b/src/hi/templates/pages/home.htmlindex 0526e073..a6e9ec4a 100644--- a/src/hi/templates/pages/home.html+++ b/src/hi/templates/pages/home.html@@ -13,13 +13,15 @@<div class="container-fluid hi-screen"><div class="row"><div class="col-9 scrollable-column ">- SCREEN-+ <div id="hi-main-content">+ {% include "location/location_view.html" %}+ </div></div><div class="col-3 fixed-column">- {% include "panes/side_panel.html" %}+ <div id="hi-side-content">+ {% include "panes/side_panel.html" %}+ </div></div></div>-</div>{% endblock %}diff --git a/src/hi/templates/panes/bottom_buttons.html b/src/hi/templates/panes/bottom_buttons.htmlindex 90bbbba4..ebe5b7c8 100644--- a/src/hi/templates/panes/bottom_buttons.html+++ b/src/hi/templates/panes/bottom_buttons.html@@ -1,4 +1,4 @@-<div class="row bg-white p-1">+<div class="hi-bottom-buttons row bg-white p-1"><div class="col-1"><div class="btn btn-secondary btn-control" role="button">BUTTON 1diff --git a/src/hi/templates/panes/top_buttons.html b/src/hi/templates/panes/top_buttons.htmlindex efd93d2d..1873876f 100644--- a/src/hi/templates/panes/top_buttons.html+++ b/src/hi/templates/panes/top_buttons.html@@ -1,62 +1,3 @@-<div class="row bg-white p-1">- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 1- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 2- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 3- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 4- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 5- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 6- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 7- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 8- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 9- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 10- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 11- </div>- </div>- <div class="col-1">- <div class="btn btn-primary btn-control" role="button">- BUTTON 12- </div>- </div>+<div class="hi-top-buttons row bg-white p-1">+ {% include "location/location_view_buttons.html" %}</div>diff --git a/src/hi/templates/service-worker.js b/src/hi/templates/service-worker.jsnew file mode 100644index 00000000..b9893174--- /dev/null+++ b/src/hi/templates/service-worker.js@@ -0,0 +1,4 @@+{% load static %}++var CACHE_VERSION = 1;+var OFFLINE_CACHE_NAME = 'offline-cache-' + CACHE_VERSION;diff --git a/src/hi/urls.py b/src/hi/urls.pyindex b3d8bff9..ef913be6 100644--- a/src/hi/urls.py+++ b/src/hi/urls.py@@ -1,3 +1,5 @@+from django.conf import settings+from django.conf.urls.static import staticfrom django.contrib import adminfrom django.contrib.staticfiles.storage import staticfiles_storagefrom django.urls import include, path, re_path@@ -15,8 +17,17 @@ urlpatterns = [name="favicon"),+ re_path(r'^(?P<filename>(service-worker.js))$',+ views.home_javascript_files, name='home-javascript-files'),++path('admin/', admin.site.urls),re_path( r'^$', views.HomeView.as_view(), name='home' ),re_path( r'^index.html$', views.HomeView.as_view(), name='home_index' ),++ re_path( r'^location/', include('hi.apps.location.urls' )),+]++urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)diff --git a/src/hi/views.py b/src/hi/views.pyindex c846ce67..b642b323 100644--- a/src/hi/views.py+++ b/src/hi/views.py@@ -1,11 +1,26 @@+import os++from django.conf import settingsfrom django.shortcuts import renderfrom django.views.generic import View+from hi.apps.location.models import Location+++def home_javascript_files( request, filename ):+ return render(request, filename, {}, content_type = "text/javascript")+class HomeView( View ):def get(self, request, *args, **kwargs):++ location = Location.objects.order_by( 'order_id' ).first()+ location_view_list = list( location.views.order_by( 'order_id' ))+ current_location_view = location_view_list[0]+context = {+ 'current_location_view': current_location_view,+ 'location_view_list': location_view_list,}return render( request, 'pages/home.html', context )-