From ab6a7c0bcccdd8ca3ade9e38ff336cb269e0a56c Mon Sep 17 00:00:00 2001 From: RunLit <41996199+RunLit@users.noreply.github.com> Date: Sun, 22 Feb 2026 21:32:58 +1100 Subject: [PATCH] support bammbu run as external django app (#2) --- .../bambu_run/filament_color_list.html | 4 ++++ .../templates/bambu_run/filament_detail.html | 20 +++++++++++++++++++ .../templates/bambu_run/filament_form.html | 2 +- .../templates/bambu_run/filament_list.html | 4 ++++ .../bambu_run/filament_type_list.html | 4 ++++ .../bambu_run/printer_dashboard.html | 17 ++++++++++++++++ bambu_run/views.py | 16 +++++++++++---- 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/bambu_run/templates/bambu_run/filament_color_list.html b/bambu_run/templates/bambu_run/filament_color_list.html index b4061b9..c777595 100644 --- a/bambu_run/templates/bambu_run/filament_color_list.html +++ b/bambu_run/templates/bambu_run/filament_color_list.html @@ -9,9 +9,11 @@

Manage filament colors for auto-matching

+ {% if not is_basic_user %} Add New Color + {% endif %} Back to Inventory @@ -70,8 +72,10 @@ {{ color.brand }} + {% if not is_basic_user %} Edit Delete + {% endif %} {% empty %} diff --git a/bambu_run/templates/bambu_run/filament_detail.html b/bambu_run/templates/bambu_run/filament_detail.html index 0adf548..c9c1d53 100644 --- a/bambu_run/templates/bambu_run/filament_detail.html +++ b/bambu_run/templates/bambu_run/filament_detail.html @@ -13,7 +13,9 @@

Filament Spool Details

+ {% if not is_basic_user %} Edit + {% endif %} Back to List
@@ -78,6 +80,7 @@
+ {% if not is_basic_user %}
@@ -118,6 +121,7 @@
+ {% endif %}
@@ -199,6 +203,7 @@ {% block extra_js %} +{% if not is_basic_user %} +{% else %} + +{% endif %} {% endblock %} diff --git a/bambu_run/templates/bambu_run/filament_form.html b/bambu_run/templates/bambu_run/filament_form.html index 98d18a7..6a03453 100644 --- a/bambu_run/templates/bambu_run/filament_form.html +++ b/bambu_run/templates/bambu_run/filament_form.html @@ -145,7 +145,7 @@ Cancel
- {% if form.instance.pk %} + {% if form.instance.pk and not is_basic_user %} diff --git a/bambu_run/templates/bambu_run/filament_list.html b/bambu_run/templates/bambu_run/filament_list.html index 92366eb..e83052a 100644 --- a/bambu_run/templates/bambu_run/filament_list.html +++ b/bambu_run/templates/bambu_run/filament_list.html @@ -12,6 +12,7 @@

Filament Inventory

Manage your 3D printer filament spools

+ {% if not is_basic_user %}
Manage Types @@ -23,6 +24,7 @@ Add Filament
+ {% endif %}
@@ -158,7 +160,9 @@ {{ filament.last_used|date:"Y-m-d H:i"|default:"Never" }} View + {% if not is_basic_user %} Edit + {% endif %} {% empty %} diff --git a/bambu_run/templates/bambu_run/filament_type_list.html b/bambu_run/templates/bambu_run/filament_type_list.html index aa36884..b112cbc 100644 --- a/bambu_run/templates/bambu_run/filament_type_list.html +++ b/bambu_run/templates/bambu_run/filament_type_list.html @@ -9,9 +9,11 @@

Manage filament types (material, sub-type, brand)

+ {% if not is_basic_user %} Add New Type + {% endif %} Back to Inventory @@ -60,8 +62,10 @@ {{ ft.brand }} + {% if not is_basic_user %} Edit Delete + {% endif %} {% empty %} diff --git a/bambu_run/templates/bambu_run/printer_dashboard.html b/bambu_run/templates/bambu_run/printer_dashboard.html index 614de65..df5496c 100644 --- a/bambu_run/templates/bambu_run/printer_dashboard.html +++ b/bambu_run/templates/bambu_run/printer_dashboard.html @@ -203,6 +203,7 @@
+ {% if not is_basic_user %}
@@ -247,6 +248,7 @@
+ {% endif %}
@@ -372,6 +374,7 @@ +{% if not is_basic_user %} +{% else %} + +{% endif %} {% endblock %} diff --git a/bambu_run/views.py b/bambu_run/views.py index e15e1ca..54d1fa9 100644 --- a/bambu_run/views.py +++ b/bambu_run/views.py @@ -17,6 +17,11 @@ from .forms import FilamentForm, FilamentColorForm, FilamentTypeForm class PrinterDashboardView(LoginRequiredMixin, TemplateView): template_name = "bambu_run/printer_dashboard.html" + def _get_date_range(self, request): + """Return (start_dt, end_dt) for the dashboard query. Override for custom date logic.""" + time_24h_ago = timezone.now() - timedelta(hours=24) + return time_24h_ago, None # None means "now" + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['bambu_run_base_template'] = app_settings.BASE_TEMPLATE @@ -34,11 +39,14 @@ class PrinterDashboardView(LoginRequiredMixin, TemplateView): tz = zoneinfo.ZoneInfo(app_settings.TIMEZONE) - # Last 24 hours of live data - time_24h_ago = timezone.now() - timedelta(hours=24) + # Get date range (overridable by subclasses) + start_dt, end_dt = self._get_date_range(self.request) metrics = PrinterMetrics.objects.filter( - device=printer_device, timestamp__gte=time_24h_ago - ).prefetch_related('filament_snapshots').order_by("timestamp") + device=printer_device, timestamp__gte=start_dt + ) + if end_dt: + metrics = metrics.filter(timestamp__lte=end_dt) + metrics = metrics.prefetch_related('filament_snapshots').order_by("timestamp") latest_metric = metrics.last()