mirror of
https://github.com/kjanat/livegraphs-django.git
synced 2026-02-14 04:15:43 +01:00
feat: add ty type checking support and fix type issues
- Add ty.toml configuration with Django project root - Add py.typed marker for type checking - Fix type issues across codebase: - Add type ignore comments for redis.exceptions imports - Fix django.db.models.functions imports in utils - Fix getattr usage in accounts/forms - Remove unnecessary type annotations in dashboard/forms - Configure ty to exclude migrations and respect ignore files - All ty checks now pass (29 diagnostics -> 0)
This commit is contained in:
@@ -49,7 +49,9 @@ class DataSourceAdmin(admin.ModelAdmin):
|
||||
@admin.display(description="External Data Status")
|
||||
def get_external_data_status(self, obj):
|
||||
if obj.external_source:
|
||||
return f"Last synced: {obj.external_source.last_synced or 'Never'} | Status: {obj.external_source.get_status()}"
|
||||
last_sync = obj.external_source.last_synced or "Never"
|
||||
status = obj.external_source.get_status()
|
||||
return f"Last synced: {last_sync} | Status: {status}"
|
||||
return "No external data source linked"
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
# dashboard/forms.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django import forms
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
from .models import Dashboard, DataSource
|
||||
|
||||
|
||||
@@ -37,7 +44,9 @@ class DashboardForm(forms.ModelForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if self.company:
|
||||
self.fields["data_sources"].queryset = DataSource.objects.filter(company=self.company)
|
||||
# Access queryset on ModelMultipleChoiceField
|
||||
data_sources_field = self.fields["data_sources"] # type: ignore[assignment]
|
||||
data_sources_field.queryset = DataSource.objects.filter(company=self.company) # type: ignore[attr-defined]
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super().save(commit=False)
|
||||
|
||||
@@ -83,7 +83,7 @@ class Command(BaseCommand):
|
||||
ChatSession.objects.all().delete()
|
||||
|
||||
# Parse sample CSV
|
||||
with open(sample_path, "r") as f:
|
||||
with open(sample_path) as f:
|
||||
reader = csv.reader(f)
|
||||
header = next(reader) # Skip header
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
# dashboard/utils.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from django.db import models
|
||||
from django.db.models import functions
|
||||
from django.utils.timezone import make_aware
|
||||
|
||||
from .models import ChatSession
|
||||
@@ -137,7 +140,7 @@ def generate_dashboard_data(data_sources):
|
||||
# Time series data (sessions per day)
|
||||
time_series_query = (
|
||||
chat_sessions.filter(start_time__isnull=False)
|
||||
.annotate(date=models.functions.TruncDate("start_time"))
|
||||
.annotate(date=functions.TruncDate("start_time")) # type: ignore[attr-defined]
|
||||
.values("date")
|
||||
.annotate(count=models.Count("id"))
|
||||
.order_by("date")
|
||||
|
||||
@@ -58,7 +58,7 @@ def dashboard_view(request):
|
||||
if selected_dashboard_id:
|
||||
selected_dashboard = get_object_or_404(Dashboard, id=selected_dashboard_id, company=company)
|
||||
else:
|
||||
selected_dashboard = dashboards.first()
|
||||
selected_dashboard = dashboards.first() # type: ignore[assignment]
|
||||
|
||||
# Generate dashboard data
|
||||
dashboard_data = generate_dashboard_data(selected_dashboard.data_sources.all())
|
||||
|
||||
Reference in New Issue
Block a user